My agentic slop goes here. Not intended for anyone else!

more

-93
yaml/ocaml-yamle/tests/categorize_failures.ml
···
-
(* Categorize test failures *)
-
open Yamle
-
module TL = Test_suite_lib.Test_suite_loader
-
module TF = Test_suite_lib.Tree_format
-
-
let test_suite_path = "../yaml-test-suite"
-
-
let normalize_tree s =
-
let lines = String.split_on_char '\n' s in
-
let lines = List.filter (fun l -> String.trim l <> "") lines in
-
String.concat "\n" lines
-
-
type failure =
-
| Error_not_detected of string
-
| Parse_error of string
-
| Tree_mismatch of string * string
-
-
let run_test (test : TL.test_case) =
-
if test.fail then begin
-
try
-
let parser = Parser.of_string test.yaml in
-
let _events = Parser.to_list parser in
-
Some (Error_not_detected test.name)
-
with _ -> None
-
end
-
else begin
-
match test.tree with
-
| None -> None
-
| Some expected ->
-
try
-
let parser = Parser.of_string test.yaml in
-
let events = Parser.to_list parser in
-
let actual = TF.of_spanned_events events in
-
let expected_norm = normalize_tree expected in
-
let actual_norm = normalize_tree actual in
-
if expected_norm = actual_norm then None
-
else Some (Tree_mismatch (expected_norm, actual_norm))
-
with e ->
-
let msg = Printexc.to_string e in
-
Some (Parse_error msg)
-
end
-
-
let diff_lines expected actual =
-
let exp_lines = String.split_on_char '\n' expected in
-
let act_lines = String.split_on_char '\n' actual in
-
let rec find_diff i es as_ =
-
match es, as_ with
-
| [], [] -> None
-
| [], _ -> Some (Printf.sprintf "Line count: expected %d, got %d" (List.length exp_lines) (List.length act_lines))
-
| _, [] -> Some (Printf.sprintf "Line count: expected %d, got %d" (List.length exp_lines) (List.length act_lines))
-
| e :: es', a :: as_' ->
-
if e = a then find_diff (i + 1) es' as_'
-
else Some (Printf.sprintf "Line %d differs:\n exp: %s\n got: %s" i e a)
-
in
-
find_diff 1 exp_lines act_lines
-
-
let () =
-
let src_path = Filename.concat test_suite_path "src" in
-
let all_tests = TL.load_directory src_path in
-
-
let error_not_detected = ref [] in
-
let parse_errors = ref [] in
-
let tree_mismatches = ref [] in
-
-
List.iter (fun test ->
-
match run_test test with
-
| None -> ()
-
| Some (Error_not_detected name) ->
-
error_not_detected := (test.TL.id, name) :: !error_not_detected
-
| Some (Parse_error msg) ->
-
parse_errors := (test.TL.id, test.TL.name, msg) :: !parse_errors
-
| Some (Tree_mismatch (exp, act)) ->
-
tree_mismatches := (test.TL.id, test.TL.name, exp, act) :: !tree_mismatches
-
) all_tests;
-
-
Printf.printf "=== ERROR TESTS NOT DETECTED (%d) ===\n" (List.length !error_not_detected);
-
List.iter (fun (id, name) ->
-
Printf.printf " %s: %s\n" id name
-
) (List.rev !error_not_detected);
-
-
Printf.printf "\n=== PARSE ERRORS (%d) ===\n" (List.length !parse_errors);
-
List.iter (fun (id, name, msg) ->
-
Printf.printf " %s: %s\n %s\n" id name msg
-
) (List.rev !parse_errors);
-
-
Printf.printf "\n=== TREE MISMATCHES (%d) ===\n" (List.length !tree_mismatches);
-
List.iter (fun (id, name, exp, act) ->
-
let diff = diff_lines exp act in
-
Printf.printf " %s: %s\n" id name;
-
match diff with
-
| Some d -> Printf.printf " %s\n" d
-
| None -> ()
-
) (List.rev !tree_mismatches)
-12
yaml/ocaml-yamle/tests/count_tests.ml
···
-
module TL = Test_suite_lib.Test_suite_loader
-
-
let () =
-
let tests = TL.load_directory "../yaml-test-suite/src" in
-
let error_without_tree = List.filter (fun t -> t.TL.fail && t.TL.tree = None) tests in
-
let non_error_without_tree = List.filter (fun t -> (not t.TL.fail) && t.TL.tree = None) tests in
-
Printf.printf "Error tests without tree: %d\n" (List.length error_without_tree);
-
Printf.printf "Non-error tests without tree (will be skipped): %d\n" (List.length non_error_without_tree);
-
Printf.printf "\nError tests without tree:\n";
-
List.iter (fun t -> Printf.printf " %s\n" t.TL.id) error_without_tree;
-
Printf.printf "\nNon-error tests without tree:\n";
-
List.iter (fun t -> Printf.printf " %s\n" t.TL.id) non_error_without_tree
-71
yaml/ocaml-yamle/tests/debug_5we3_6m2f.ml
···
-
open Yamle
-
-
let show_token tok =
-
Format.asprintf "%a" Token.pp_spanned tok
-
-
let show_event evt =
-
Format.asprintf "%a" Event.pp_spanned evt
-
-
let test_5we3 () =
-
Printf.printf "\n=== Test 5WE3: Explicit Block Mapping Entries ===\n";
-
let yaml = "? explicit key # Empty value\n? |\n block key\n: - one # Explicit compact\n - two # block value" in
-
Printf.printf "Input:\n%s\n\n" yaml;
-
try
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "Tokens:\n";
-
let rec print_tokens () =
-
match Scanner.peek scanner with
-
| None -> Printf.printf "No more tokens\n"
-
| Some tok ->
-
Printf.printf " %s\n" (show_token tok);
-
ignore (Scanner.next scanner);
-
print_tokens ()
-
in
-
print_tokens ();
-
Printf.printf "\nParsing:\n";
-
let scanner = Scanner.of_string yaml in
-
let parser = Parser.create scanner in
-
let rec print_events () =
-
match Parser.next parser with
-
| None -> Printf.printf "No more events\n"
-
| Some event ->
-
Printf.printf " %s\n" (show_event event);
-
print_events ()
-
in
-
print_events ()
-
with e ->
-
Printf.printf "ERROR: %s\n" (Printexc.to_string e)
-
-
let test_6m2f () =
-
Printf.printf "\n=== Test 6M2F: Aliases in Explicit Block Mapping ===\n";
-
let yaml = "? &a a\n: &b b\n: *a" in
-
Printf.printf "Input:\n%s\n\n" yaml;
-
try
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "Tokens:\n";
-
let rec print_tokens () =
-
match Scanner.peek scanner with
-
| None -> Printf.printf "No more tokens\n"
-
| Some tok ->
-
Printf.printf " %s\n" (show_token tok);
-
ignore (Scanner.next scanner);
-
print_tokens ()
-
in
-
print_tokens ();
-
Printf.printf "\nParsing:\n";
-
let scanner = Scanner.of_string yaml in
-
let parser = Parser.create scanner in
-
let rec print_events () =
-
match Parser.next parser with
-
| None -> Printf.printf "No more events\n"
-
| Some event ->
-
Printf.printf " %s\n" (show_event event);
-
print_events ()
-
in
-
print_events ()
-
with e ->
-
Printf.printf "ERROR: %s\n" (Printexc.to_string e)
-
-
let () =
-
test_5we3 ();
-
test_6m2f ()
-62
yaml/ocaml-yamle/tests/debug_block_issues.ml
···
-
open Yamle
-
open Test_suite_lib
-
-
let test_case name yaml expected_tree =
-
Printf.printf "\n=== Testing %s ===\n" name;
-
Printf.printf "YAML:\n%s\n" yaml;
-
Printf.printf "\nExpected tree:\n%s\n" expected_tree;
-
-
try
-
let input = Input.of_string yaml in
-
let scanner = Scanner.create input in
-
let parser = Parser.create scanner in
-
-
(* Skip token output for now *)
-
();
-
-
Printf.printf "\nParsing...\n";
-
let rec collect_events acc =
-
match Parser.next parser with
-
| None -> List.rev acc
-
| Some evt -> collect_events (evt :: acc)
-
in
-
let events = collect_events [] in
-
-
let tree = Tree_format.of_spanned_events events in
-
Printf.printf "\nFormatted tree:\n%s\n" tree;
-
-
if tree = expected_tree then
-
Printf.printf "✓ PASS\n"
-
else
-
Printf.printf "✗ FAIL - Tree mismatch\n"
-
with
-
| Error.Yamle_error err ->
-
Printf.printf "ERROR: %s\n" (Error.to_string err)
-
| e ->
-
Printf.printf "ERROR: %s\n" (Printexc.to_string e)
-
-
let () =
-
(* JEF9 - Extra newlines at end *)
-
test_case "JEF9"
-
"- |+\n\n"
-
"+STR\n +DOC\n +SEQ\n =VAL |\\n\\n\n -SEQ\n -DOC\n-STR";
-
-
(* K858 - Empty scalar chomping - block scalar consuming too much *)
-
test_case "K858"
-
"strip: >-\n\nclip: >\n\nkeep: |+\n\n"
-
"+STR\n +DOC\n +MAP\n =VAL :strip\n =VAL >\n =VAL :clip\n =VAL >\n =VAL :keep\n =VAL |\\n\n -MAP\n -DOC\n-STR";
-
-
(* L24T - Trailing whitespace-only line *)
-
test_case "L24T"
-
"foo: |\n x\n \n"
-
"+STR\n +DOC\n +MAP\n =VAL :foo\n =VAL |x\\n \\n\n -MAP\n -DOC\n-STR";
-
-
(* MJS9 - Folded block newline handling *)
-
test_case "MJS9"
-
">\n foo \n \n \t bar\n\n baz\n"
-
"+STR\n +DOC\n =VAL >foo \\n\\n\\t bar\\n\\nbaz\\n\n -DOC\n-STR";
-
-
(* R4YG - Tab handling in folded block - just the problematic 4th test *)
-
test_case "R4YG-4"
-
"- >\n \t\n detected\n"
-
"+STR\n +DOC\n +SEQ\n =VAL >\\t\\ndetected\\n\n -SEQ\n -DOC\n-STR"
-47
yaml/ocaml-yamle/tests/debug_block_scalars.ml
···
-
(* Debug block scalar behavior *)
-
open Yamle
-
-
let test_simple name yaml expected =
-
Printf.printf "\n=== %s ===\n" name;
-
Printf.printf "Input: %S\n" yaml;
-
Printf.printf "Expected: %S\n" expected;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
List.iter (fun ev ->
-
match ev.Event.event with
-
| Event.Scalar { value; style; _ } ->
-
let style_str = match style with
-
| Scalar_style.Literal -> "Literal"
-
| Scalar_style.Folded -> "Folded"
-
| _ -> "Other"
-
in
-
Printf.printf "Scalar (%s): %S (len=%d)\n" style_str value (String.length value);
-
Printf.printf " Escaped: %s\n" (String.escaped value);
-
if value = expected then
-
Printf.printf " PASS\n"
-
else
-
Printf.printf " FAIL: Expected %S\n" expected
-
| _ -> ()
-
) events
-
with e ->
-
Printf.printf "ERROR: %s\n" (Printexc.to_string e);
-
Printexc.print_backtrace stdout
-
-
let () =
-
(* JEF9 - Keep chomping with empty content *)
-
test_simple "JEF9" "- |+\n\n\n" "\n\n";
-
-
(* K858 - Empty scalar chomping *)
-
test_simple "K858-strip" "strip: >-\n\n" "";
-
test_simple "K858-clip" "clip: >\n\n" "";
-
test_simple "K858-keep" "keep: |+\n\n" "\n";
-
-
(* L24T - Trailing spaces *)
-
test_simple "L24T" "foo: |\n x\n \n" "x\n \n";
-
-
(* MJS9 - Folded newlines *)
-
test_simple "MJS9" ">\n foo \n \n\t bar\n\n baz\n" "foo \n\n\t bar\n\nbaz\n";
-
-
(* R4YG - Tab preservation *)
-
test_simple "R4YG" "- >\n \t\n detected\n" "\t\ndetected\n"
-13
yaml/ocaml-yamle/tests/debug_dk95_01.ml
···
-
open Yamle
-
let () =
-
(* DK95/01: foo: "bar<nl><4 tabs>baz" - 4 tabs at column 1 puts us at column 5, but quote started at 6 *)
-
let yaml = "foo: \"bar\n\t\t\t\tbaz\"" in
-
Format.printf "YAML: %S@.@." yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Format.printf "Events: %d (ERROR: should have failed)@." (List.length events);
-
List.iter (fun e -> Format.printf " %a@." Event.pp_spanned e) events
-
with
-
| Yamle_error e ->
-
Format.printf "Error (expected): %a@." Error.pp e
-71
yaml/ocaml-yamle/tests/debug_empty_key.ml
···
-
open Yamle
-
-
let show_token tok =
-
Format.asprintf "%a" Token.pp_spanned tok
-
-
let show_event evt =
-
Format.asprintf "%a" Event.pp_spanned evt
-
-
let test_2jqs () =
-
Printf.printf "\n=== Test 2JQS: Block Mapping with Missing Keys ===\n";
-
let yaml = ": a\n: b" in
-
Printf.printf "Input:\n%s\n\n" yaml;
-
try
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "Tokens:\n";
-
let rec print_tokens () =
-
match Scanner.peek scanner with
-
| None -> Printf.printf "No more tokens\n"
-
| Some tok ->
-
Printf.printf " %s\n" (show_token tok);
-
ignore (Scanner.next scanner);
-
print_tokens ()
-
in
-
print_tokens ();
-
Printf.printf "\nParsing:\n";
-
let scanner = Scanner.of_string yaml in
-
let parser = Parser.create scanner in
-
let rec print_events () =
-
match Parser.next parser with
-
| None -> Printf.printf "No more events\n"
-
| Some event ->
-
Printf.printf " %s\n" (show_event event);
-
print_events ()
-
in
-
print_events ()
-
with e ->
-
Printf.printf "ERROR: %s\n" (Printexc.to_string e)
-
-
let test_5nyz () =
-
Printf.printf "\n=== Test 5NYZ: Separated Comment ===\n";
-
let yaml = "key: # Comment\n value" in
-
Printf.printf "Input:\n%s\n\n" yaml;
-
try
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "Tokens:\n";
-
let rec print_tokens () =
-
match Scanner.peek scanner with
-
| None -> Printf.printf "No more tokens\n"
-
| Some tok ->
-
Printf.printf " %s\n" (show_token tok);
-
ignore (Scanner.next scanner);
-
print_tokens ()
-
in
-
print_tokens ();
-
Printf.printf "\nParsing:\n";
-
let scanner = Scanner.of_string yaml in
-
let parser = Parser.create scanner in
-
let rec print_events () =
-
match Parser.next parser with
-
| None -> Printf.printf "No more events\n"
-
| Some event ->
-
Printf.printf " %s\n" (show_event event);
-
print_events ()
-
in
-
print_events ()
-
with e ->
-
Printf.printf "ERROR: %s\n" (Printexc.to_string e)
-
-
let () =
-
test_2jqs ();
-
test_5nyz ()
-73
yaml/ocaml-yamle/tests/debug_flow.ml
···
-
(* Debug flow context issues *)
-
open Yamle
-
-
let show_error_kind = function
-
| Error.Unexpected_character c -> Printf.sprintf "Unexpected_character(%c)" c
-
| Error.Unexpected_eof -> "Unexpected_eof"
-
| Error.Invalid_escape_sequence s -> Printf.sprintf "Invalid_escape_sequence(%s)" s
-
| Error.Invalid_unicode_escape s -> Printf.sprintf "Invalid_unicode_escape(%s)" s
-
| Error.Invalid_hex_escape s -> Printf.sprintf "Invalid_hex_escape(%s)" s
-
| Error.Invalid_tag s -> Printf.sprintf "Invalid_tag(%s)" s
-
| Error.Invalid_anchor s -> Printf.sprintf "Invalid_anchor(%s)" s
-
| Error.Invalid_alias s -> Printf.sprintf "Invalid_alias(%s)" s
-
| Error.Invalid_comment -> "Invalid_comment"
-
| Error.Unclosed_single_quote -> "Unclosed_single_quote"
-
| Error.Unclosed_double_quote -> "Unclosed_double_quote"
-
| Error.Unclosed_flow_sequence -> "Unclosed_flow_sequence"
-
| Error.Unclosed_flow_mapping -> "Unclosed_flow_mapping"
-
| Error.Invalid_indentation (exp, got) -> Printf.sprintf "Invalid_indentation(expected %d, got %d)" exp got
-
| Error.Invalid_flow_indentation -> "Invalid_flow_indentation"
-
| Error.Tab_in_indentation -> "Tab_in_indentation"
-
| Error.Invalid_block_scalar_header s -> Printf.sprintf "Invalid_block_scalar_header(%s)" s
-
| Error.Invalid_directive s -> Printf.sprintf "Invalid_directive(%s)" s
-
| Error.Invalid_yaml_version s -> Printf.sprintf "Invalid_yaml_version(%s)" s
-
| Error.Invalid_tag_directive s -> Printf.sprintf "Invalid_tag_directive(%s)" s
-
| Error.Reserved_directive s -> Printf.sprintf "Reserved_directive(%s)" s
-
| Error.Unexpected_token s -> Printf.sprintf "Unexpected_token(%s)" s
-
| Error.Expected_document_start -> "Expected_document_start"
-
| Error.Expected_document_end -> "Expected_document_end"
-
| Error.Expected_block_entry -> "Expected_block_entry"
-
| Error.Expected_key -> "Expected_key"
-
| Error.Expected_value -> "Expected_value"
-
| Error.Expected_node -> "Expected_node"
-
| Error.Expected_scalar -> "Expected_scalar"
-
| Error.Expected_sequence_end -> "Expected_sequence_end"
-
| Error.Expected_mapping_end -> "Expected_mapping_end"
-
| Error.Duplicate_anchor s -> Printf.sprintf "Duplicate_anchor(%s)" s
-
| Error.Undefined_alias s -> Printf.sprintf "Undefined_alias(%s)" s
-
| Error.Alias_cycle s -> Printf.sprintf "Alias_cycle(%s)" s
-
| Error.Multiple_documents -> "Multiple_documents"
-
| Error.Mapping_key_too_long -> "Mapping_key_too_long"
-
| Error.Custom s -> Printf.sprintf "Custom(%s)" s
-
| _ -> "Unknown error"
-
-
let test_case id yaml =
-
Printf.printf "\n=== Test %s ===\n%!" id;
-
Printf.printf "YAML: %S\n%!" yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Printf.printf "SUCCESS - got %d events\n%!" (List.length events)
-
with Error.Yamle_error err ->
-
let pos_str = match err.Error.span with
-
| Some span -> Printf.sprintf " at line %d col %d" span.Span.start.Position.line span.Span.start.Position.column
-
| None -> ""
-
in
-
Printf.printf "ERROR%s: %s\n%!" pos_str (show_error_kind err.Error.kind)
-
-
let () =
-
(* Test 87E4: Single Quoted Implicit Keys *)
-
test_case "87E4" {|'implicit block key' : [
-
'implicit flow key' : value,
-
]|};
-
-
(* Test CFD4: Empty implicit key *)
-
test_case "CFD4" {|- [ : empty key ]|};
-
-
(* Test L9U5: Plain Implicit Keys *)
-
test_case "L9U5" {|implicit block key : [
-
implicit flow key : value,
-
]|};
-
-
(* Test 9MMW: Single Pair Implicit Entries *)
-
test_case "9MMW" {|- [ YAML : separate ]|};
-61
yaml/ocaml-yamle/tests/debug_flow2.ml
···
-
(* Debug tokenization *)
-
open Yamle
-
-
let show_token = function
-
| Token.Stream_start enc -> Printf.sprintf "Stream_start(%s)" (match enc with Utf8 -> "UTF8" | _ -> "?")
-
| Token.Stream_end -> "Stream_end"
-
| Token.Document_start -> "Document_start"
-
| Token.Document_end -> "Document_end"
-
| Token.Block_mapping_start -> "Block_mapping_start"
-
| Token.Block_sequence_start -> "Block_sequence_start"
-
| Token.Block_end -> "Block_end"
-
| Token.Flow_sequence_start -> "Flow_sequence_start"
-
| Token.Flow_sequence_end -> "Flow_sequence_end"
-
| Token.Flow_mapping_start -> "Flow_mapping_start"
-
| Token.Flow_mapping_end -> "Flow_mapping_end"
-
| Token.Block_entry -> "Block_entry"
-
| Token.Flow_entry -> "Flow_entry"
-
| Token.Key -> "Key"
-
| Token.Value -> "Value"
-
| Token.Alias s -> Printf.sprintf "Alias(%s)" s
-
| Token.Anchor s -> Printf.sprintf "Anchor(%s)" s
-
| Token.Tag {handle; suffix} -> Printf.sprintf "Tag(%s, %s)" handle suffix
-
| Token.Scalar {value; style; _} ->
-
let style_str = match style with
-
| Plain -> "Plain" | Single_quoted -> "Single" | Double_quoted -> "Double"
-
| Literal -> "Literal" | Folded -> "Folded" | _ -> "Other"
-
in
-
Printf.sprintf "Scalar(%S, %s)" value style_str
-
| _ -> "Other"
-
-
let test_case id yaml =
-
Printf.printf "\n=== Test %s ===\n%!" id;
-
Printf.printf "YAML: %S\n%!" yaml;
-
Printf.printf "Tokens:\n%!";
-
try
-
let scanner = Scanner.of_string yaml in
-
let rec print_tokens () =
-
match Scanner.next scanner with
-
| Some tok ->
-
Printf.printf " %s at line %d col %d\n%!"
-
(show_token tok.token)
-
tok.span.start.line
-
tok.span.start.column;
-
print_tokens ()
-
| None -> ()
-
in
-
print_tokens ();
-
Printf.printf "SUCCESS\n%!"
-
with Error.Yamle_error err ->
-
let pos_str = match err.Error.span with
-
| Some span -> Printf.sprintf " at line %d col %d" span.Span.start.Position.line span.Span.start.Position.column
-
| None -> ""
-
in
-
Printf.printf "ERROR%s\n%!" pos_str
-
-
let () =
-
(* Test CFD4: Empty implicit key *)
-
test_case "CFD4" {|- [ : empty key ]|};
-
-
(* Test 9MMW: Single Pair Implicit Entries *)
-
test_case "9MMW" {|- [ YAML : separate ]|};
-27
yaml/ocaml-yamle/tests/debug_flow3.ml
···
-
open Yamle
-
-
let show_error_kind = function
-
| Error.Expected_sequence_end -> "Expected_sequence_end"
-
| Error.Expected_mapping_end -> "Expected_mapping_end"
-
| Error.Unexpected_token s -> Printf.sprintf "Unexpected_token(%s)" s
-
| Error.Expected_key -> "Expected_key"
-
| Error.Expected_value -> "Expected_value"
-
| Error.Expected_node -> "Expected_node"
-
| _ -> "Other"
-
-
let test yaml =
-
Printf.printf "YAML: %S\n%!" yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Printf.printf "SUCCESS - %d events\n%!" (List.length events)
-
with Error.Yamle_error err ->
-
let pos_str = match err.Error.span with
-
| Some span -> Printf.sprintf " at line %d col %d" span.Span.start.Position.line span.Span.start.Position.column
-
| None -> ""
-
in
-
Printf.printf "ERROR%s: %s\n%!" pos_str (show_error_kind err.Error.kind)
-
-
let () =
-
test {|- [ : empty key ]|};
-
test {|- [ YAML : separate ]|};
-36
yaml/ocaml-yamle/tests/debug_flow4.ml
···
-
open Yamle
-
-
let test yaml =
-
Printf.printf "\n=== YAML: %S ===\n%!" yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let rec print_events n =
-
match Parser.next parser with
-
| None -> Printf.printf "Total events: %d\n%!" n
-
| Some ev ->
-
Printf.printf "Event %d: " n;
-
(match ev.Event.event with
-
| Event.Stream_start _ -> Printf.printf "Stream_start\n"
-
| Event.Stream_end -> Printf.printf "Stream_end\n"
-
| Event.Document_start _ -> Printf.printf "Document_start\n"
-
| Event.Document_end _ -> Printf.printf "Document_end\n"
-
| Event.Sequence_start _ -> Printf.printf "Sequence_start\n"
-
| Event.Sequence_end -> Printf.printf "Sequence_end\n"
-
| Event.Mapping_start _ -> Printf.printf "Mapping_start\n"
-
| Event.Mapping_end -> Printf.printf "Mapping_end\n"
-
| Event.Scalar {value; _} -> Printf.printf "Scalar(%S)\n" value
-
| Event.Alias {anchor} -> Printf.printf "Alias(%s)\n" anchor);
-
print_events (n + 1)
-
in
-
print_events 0;
-
Printf.printf "SUCCESS\n%!"
-
with Error.Yamle_error err ->
-
let pos_str = match err.Error.span with
-
| Some span -> Printf.sprintf " at line %d col %d" span.Span.start.Position.line span.Span.start.Position.column
-
| None -> ""
-
in
-
Printf.printf "ERROR%s\n%!" pos_str
-
-
let () =
-
test {|- [ : empty key ]|};
-
test {|- [ YAML : separate ]|};
-29
yaml/ocaml-yamle/tests/debug_flow5.ml
···
-
open Yamle
-
-
let () =
-
Printf.printf "Test: - [ : empty key ]\n%!";
-
try
-
let scanner = Scanner.of_string {|- [ : empty key ]|} in
-
Printf.printf "Tokens:\n%!";
-
let rec print_all n =
-
match Scanner.next scanner with
-
| None -> ()
-
| Some tok ->
-
Printf.printf " %d. " n;
-
(match tok.Token.token with
-
| Token.Stream_start _ -> Printf.printf "Stream_start"
-
| Token.Stream_end -> Printf.printf "Stream_end"
-
| Token.Block_sequence_start -> Printf.printf "Block_sequence_start"
-
| Token.Block_entry -> Printf.printf "Block_entry"
-
| Token.Block_end -> Printf.printf "Block_end"
-
| Token.Flow_sequence_start -> Printf.printf "Flow_sequence_start"
-
| Token.Flow_sequence_end -> Printf.printf "Flow_sequence_end"
-
| Token.Value -> Printf.printf "Value"
-
| Token.Scalar {value; _} -> Printf.printf "Scalar(%S)" value
-
| _ -> Printf.printf "Other");
-
Printf.printf " at %d:%d\n%!" tok.span.start.line tok.span.start.column;
-
print_all (n + 1)
-
in
-
print_all 0
-
with Error.Yamle_error _ ->
-
Printf.printf "Scanner error\n%!"
-19
yaml/ocaml-yamle/tests/debug_flow6.ml
···
-
open Yamle
-
-
let () =
-
Printf.printf "Test: - [ a ]\n%!";
-
let parser = Parser.of_string {|- [ a ]|} in
-
let rec print_events n =
-
match Parser.next parser with
-
| None -> ()
-
| Some ev ->
-
Printf.printf "%d: " n;
-
(match ev.Event.event with
-
| Event.Sequence_start _ -> Printf.printf "Sequence_start"
-
| Event.Sequence_end -> Printf.printf "Sequence_end"
-
| Event.Scalar {value; _} -> Printf.printf "Scalar(%S)" value
-
| _ -> Printf.printf "Other");
-
Printf.printf "\n%!";
-
print_events (n + 1)
-
in
-
print_events 0
-30
yaml/ocaml-yamle/tests/debug_flow7.ml
···
-
open Yamle
-
-
let test yaml =
-
Printf.printf "\nYAML: %S\n%!" yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let rec print_events n =
-
match Parser.next parser with
-
| None -> Printf.printf "Total: %d events\n" n
-
| Some ev ->
-
Printf.printf "%d: " n;
-
(match ev.Event.event with
-
| Event.Sequence_start _ -> Printf.printf "Sequence_start"
-
| Event.Sequence_end -> Printf.printf "Sequence_end"
-
| Event.Mapping_start _ -> Printf.printf "Mapping_start"
-
| Event.Mapping_end -> Printf.printf "Mapping_end"
-
| Event.Scalar {value; _} -> Printf.printf "Scalar(%S)" value
-
| _ -> Printf.printf "Other");
-
Printf.printf "\n%!";
-
print_events (n + 1)
-
in
-
print_events 0;
-
Printf.printf "SUCCESS\n%!"
-
with Error.Yamle_error _ ->
-
Printf.printf "ERROR\n%!"
-
-
let () =
-
test {|[a, b]|}; (* Simple flow sequence *)
-
test {|[{a: b}]|}; (* Flow sequence with mapping *)
-
test {|[a: b]|}; (* Flow sequence with implicit mapping *)
-23
yaml/ocaml-yamle/tests/debug_from.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "---\n- name: Spec Example 2.4. Sequence of Mappings\n from: http://example.com\n" in
-
Printf.printf "YAML: %S\n" yaml;
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "\nTokens:\n";
-
try
-
let rec loop count =
-
if count > 30 then Printf.printf " ... (stopped at 30 tokens)\n"
-
else match Scanner.next scanner with
-
| None -> Printf.printf " (none)\n"
-
| Some tok ->
-
Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
-
(Format.asprintf "%a" Token.pp tok.token);
-
match tok.token with
-
| Token.Stream_end -> ()
-
| _ -> loop (count + 1)
-
in
-
loop 0
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e);
-
Printexc.print_backtrace stdout
-22
yaml/ocaml-yamle/tests/debug_jef9.ml
···
-
module TL = Test_suite_lib.Test_suite_loader
-
module TF = Test_suite_lib.Tree_format
-
open Yamle
-
-
let () =
-
let tests = TL.load_file "../yaml-test-suite/src/JEF9.yaml" in
-
List.iter (fun (test : TL.test_case) ->
-
Printf.printf "=== Test: %s ===\n" test.id;
-
Printf.printf "YAML bytes: ";
-
String.iter (fun c -> Printf.printf "%02x " (Char.code c)) test.yaml;
-
Printf.printf "\n";
-
Printf.printf "YAML len: %d\n" (String.length test.yaml);
-
try
-
let parser = Parser.of_string test.yaml in
-
let events = Parser.to_list parser in
-
Printf.printf "Events: %d\n" (List.length events);
-
let tree = TF.of_spanned_events events in
-
Printf.printf "Expected tree:\n%s\n" (Option.value ~default:"(none)" test.tree);
-
Printf.printf "Actual tree:\n%s\n" tree
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-
) tests
-23
yaml/ocaml-yamle/tests/debug_l24t.ml
···
-
module TL = Test_suite_lib.Test_suite_loader
-
module TF = Test_suite_lib.Tree_format
-
open Yamle
-
-
let () =
-
let tests = TL.load_file "../yaml-test-suite/src/L24T.yaml" in
-
List.iter (fun (test : TL.test_case) ->
-
Printf.printf "=== Test: %s ===\n" test.id;
-
Printf.printf "YAML bytes: ";
-
String.iter (fun c -> Printf.printf "%02x " (Char.code c)) test.yaml;
-
Printf.printf "\n";
-
Printf.printf "YAML repr: %S\n" test.yaml;
-
Printf.printf "YAML len: %d\n" (String.length test.yaml);
-
try
-
let parser = Parser.of_string test.yaml in
-
let events = Parser.to_list parser in
-
Printf.printf "Events: %d\n" (List.length events);
-
let tree = TF.of_spanned_events events in
-
Printf.printf "Expected tree:\n%s\n" (Option.value ~default:"(none)" test.tree);
-
Printf.printf "Actual tree:\n%s\n" tree
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-
) tests
-28
yaml/ocaml-yamle/tests/debug_m2n8.ml
···
-
open Yamle
-
module TF = Test_suite_lib.Tree_format
-
-
let () =
-
let yaml = "- ? : x\n" in
-
Printf.printf "YAML: %S\n" yaml;
-
Printf.printf "\nExpected tree:\n";
-
Printf.printf "+STR
-
+DOC
-
+SEQ
-
+MAP
-
+MAP
-
=VAL :
-
=VAL :x
-
-MAP
-
=VAL :
-
-MAP
-
-SEQ
-
-DOC
-
-STR\n";
-
Printf.printf "\nParsing:\n";
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
let tree = TF.of_spanned_events events in
-
Printf.printf "Actual tree:\n%s\n" tree
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-83
yaml/ocaml-yamle/tests/debug_multiline.ml
···
-
(* Debug specific multiline tests *)
-
open Yamle
-
-
let show_event evt =
-
Format.asprintf "%a" Event.pp_spanned evt
-
-
let test_a984 () =
-
let yaml = "a: b\n c\nd:\n e\n f" in
-
Printf.printf "Testing A984 (Multiline Scalar in Mapping):\n%s\n" yaml;
-
try
-
let scanner = Scanner.of_string yaml in
-
let parser = Parser.create scanner in
-
Printf.printf "Events:\n";
-
let rec print_events () =
-
match Parser.next parser with
-
| None -> ()
-
| Some event ->
-
Printf.printf " %s\n" (show_event event);
-
print_events ()
-
in
-
print_events ()
-
with e ->
-
Printf.printf "ERROR: %s\n" (Printexc.to_string e)
-
-
let test_v9d5 () =
-
let yaml = "- sun: yellow\n- ? earth: blue\n : moon: white" in
-
Printf.printf "\nTesting V9D5 (Compact Block Mappings):\n%s\n" yaml;
-
try
-
let scanner = Scanner.of_string yaml in
-
let parser = Parser.create scanner in
-
Printf.printf "Events:\n";
-
let rec print_events () =
-
match Parser.next parser with
-
| None -> ()
-
| Some event ->
-
Printf.printf " %s\n" (show_event event);
-
print_events ()
-
in
-
print_events ()
-
with e ->
-
Printf.printf "ERROR: %s\n" (Printexc.to_string e)
-
-
let test_q9wf () =
-
let yaml = "{ first: Sammy, last: Sosa }:\n# Statistics:\n hr: # Home runs\n 65\n avg: # Average\n 0.278" in
-
Printf.printf "\nTesting Q9WF (Separation Spaces):\n%s\n" yaml;
-
try
-
let scanner = Scanner.of_string yaml in
-
let parser = Parser.create scanner in
-
Printf.printf "Events:\n";
-
let rec print_events () =
-
match Parser.next parser with
-
| None -> ()
-
| Some event ->
-
Printf.printf " %s\n" (show_event event);
-
print_events ()
-
in
-
print_events ()
-
with e ->
-
Printf.printf "ERROR: %s\n" (Printexc.to_string e)
-
-
let test_m2n8 () =
-
let yaml = "- ? : x" in
-
Printf.printf "\nTesting M2N8 (Question mark edge cases):\n%s\n" yaml;
-
try
-
let scanner = Scanner.of_string yaml in
-
let parser = Parser.create scanner in
-
Printf.printf "Events:\n";
-
let rec print_events () =
-
match Parser.next parser with
-
| None -> ()
-
| Some event ->
-
Printf.printf " %s\n" (show_event event);
-
print_events ()
-
in
-
print_events ()
-
with e ->
-
Printf.printf "ERROR: %s\n" (Printexc.to_string e)
-
-
let () =
-
test_a984 ();
-
test_v9d5 ();
-
test_q9wf ();
-
test_m2n8 ()
-12
yaml/ocaml-yamle/tests/debug_mus6_01.ml
···
-
open Yamle
-
let () =
-
let yaml = "%YAML 1.2\n---\n%YAML 1.2\n---\n" in
-
Format.printf "YAML: %S@.@." yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Format.printf "Events: %d (ERROR: should have failed)@." (List.length events);
-
List.iter (fun e -> Format.printf " %a@." Event.pp_spanned e) events
-
with
-
| Yamle_error e ->
-
Format.printf "Error (expected): %a@." Error.pp e
-7
yaml/ocaml-yamle/tests/debug_mus6_load.ml
···
-
module TL = Test_suite_lib.Test_suite_loader
-
-
let () =
-
let tests = TL.load_file "../yaml-test-suite/src/MUS6.yaml" in
-
List.iter (fun t ->
-
Printf.printf "ID: %s, fail: %b, yaml: %S\n" t.TL.id t.TL.fail t.TL.yaml
-
) tests
-41
yaml/ocaml-yamle/tests/debug_prh3.ml
···
-
(* Debug PRH3 specifically *)
-
open Yamle
-
-
let yaml = "' 1st non-empty\n\n 2nd non-empty \n\t3rd non-empty '"
-
-
let () =
-
Printf.printf "Input YAML:\n";
-
for i = 0 to String.length yaml - 1 do
-
let c = yaml.[i] in
-
match c with
-
| '\n' -> Printf.printf "\\n"
-
| '\t' -> Printf.printf "\\t"
-
| ' ' -> Printf.printf "·"
-
| _ -> Printf.printf "%c" c
-
done;
-
Printf.printf "\n\n";
-
-
Printf.printf "Expected: ' 1st non-empty\\n2nd non-empty 3rd non-empty '\n";
-
Printf.printf "Expected (visual): '·1st·non-empty\\n2nd·non-empty·3rd·non-empty·'\n\n";
-
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
List.iter (fun (e : Event.spanned) ->
-
match e.event with
-
| Event.Scalar { value; _ } ->
-
Printf.printf "Actual scalar value:\n";
-
for i = 0 to String.length value - 1 do
-
let c = value.[i] in
-
match c with
-
| '\n' -> Printf.printf "\\n"
-
| '\t' -> Printf.printf "\\t"
-
| ' ' -> Printf.printf "·"
-
| _ -> Printf.printf "%c" c
-
done;
-
Printf.printf "\n";
-
Printf.printf "Length: %d\n" (String.length value)
-
| _ -> ()
-
) events
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-42
yaml/ocaml-yamle/tests/debug_quoted.ml
···
-
(* Debug quoted string issues *)
-
open Yamle
-
module TL = Test_suite_lib.Test_suite_loader
-
module TF = Test_suite_lib.Tree_format
-
-
let test_suite_path = "../yaml-test-suite"
-
-
let () =
-
let src_path = Filename.concat test_suite_path "src" in
-
let all_tests = TL.load_directory src_path in
-
-
(* Filter for specific tests *)
-
let tests = List.filter (fun t ->
-
t.TL.id = "PRH3" || t.TL.id = "T4YY" || t.TL.id = "NAT4"
-
) all_tests in
-
-
List.iter (fun test ->
-
Printf.printf "\n=== %s: %s ===\n" test.TL.id test.TL.name;
-
Printf.printf "YAML input:\n%s\n" (String.escaped test.TL.yaml);
-
Printf.printf "YAML (raw):\n%s\n---\n" test.TL.yaml;
-
-
match test.TL.tree with
-
| None -> Printf.printf "No expected tree\n"
-
| Some expected ->
-
Printf.printf "Expected tree:\n%s\n" expected;
-
-
(try
-
let parser = Parser.of_string test.TL.yaml in
-
let events = Parser.to_list parser in
-
let actual = TF.of_spanned_events events in
-
Printf.printf "Actual tree:\n%s\n" actual;
-
-
(* Show scalar values *)
-
List.iter (fun (e : Event.spanned) ->
-
match e.event with
-
| Event.Scalar { value; _ } ->
-
Printf.printf "Scalar value: %s (len=%d)\n" (String.escaped value) (String.length value)
-
| _ -> ()
-
) events;
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e))
-
) tests
-23
yaml/ocaml-yamle/tests/debug_r4yg.ml
···
-
module TL = Test_suite_lib.Test_suite_loader
-
module TF = Test_suite_lib.Tree_format
-
open Yamle
-
-
let () =
-
let tests = TL.load_file "../yaml-test-suite/src/R4YG.yaml" in
-
List.iter (fun (test : TL.test_case) ->
-
Printf.printf "=== Test: %s ===\n" test.id;
-
Printf.printf "YAML bytes: ";
-
String.iter (fun c -> Printf.printf "%02x " (Char.code c)) test.yaml;
-
Printf.printf "\n";
-
Printf.printf "YAML repr: %S\n" test.yaml;
-
Printf.printf "YAML len: %d\n" (String.length test.yaml);
-
try
-
let parser = Parser.of_string test.yaml in
-
let events = Parser.to_list parser in
-
Printf.printf "Events: %d\n" (List.length events);
-
let tree = TF.of_spanned_events events in
-
Printf.printf "Expected tree:\n%s\n" (Option.value ~default:"(none)" test.tree);
-
Printf.printf "Actual tree:\n%s\n" tree
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-
) tests
-39
yaml/ocaml-yamle/tests/debug_v9d5.ml
···
-
open Yamle
-
module TL = Test_suite_lib.Test_suite_loader
-
module TF = Test_suite_lib.Tree_format
-
-
let () =
-
let tests = TL.load_file "../yaml-test-suite/src/V9D5.yaml" in
-
List.iter (fun (test : TL.test_case) ->
-
Printf.printf "=== Test: %s ===\n" test.id;
-
Printf.printf "YAML: %S\n" test.yaml;
-
-
(* Print tokens *)
-
Printf.printf "\nTokens:\n";
-
let scanner = Scanner.of_string test.yaml in
-
begin try
-
let rec loop () =
-
match Scanner.next scanner with
-
| None -> Printf.printf " (none)\n"
-
| Some tok ->
-
Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
-
(Format.asprintf "%a" Token.pp tok.token);
-
match tok.token with
-
| Token.Stream_end -> ()
-
| _ -> loop ()
-
in
-
loop ()
-
with e ->
-
Printf.printf "Scanner error: %s\n" (Printexc.to_string e)
-
end;
-
-
Printf.printf "\nExpected tree:\n%s\n" (Option.value ~default:"(none)" test.tree);
-
Printf.printf "\nParsing:\n";
-
try
-
let parser = Parser.of_string test.yaml in
-
let events = Parser.to_list parser in
-
let tree = TF.of_spanned_events events in
-
Printf.printf "Actual tree:\n%s\n" tree
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-
) tests
-13
yaml/ocaml-yamle/tests/debug_y79y_03.ml
···
-
open Yamle
-
let () =
-
(* Y79Y/03: - [<nl><tab>foo,<nl> foo<nl> ] *)
-
let yaml = "- [\n\tfoo,\n foo\n ]" in
-
Format.printf "YAML: %S@.@." yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Format.printf "Events: %d (ERROR: should have failed)@." (List.length events);
-
List.iter (fun e -> Format.printf " %a@." Event.pp_spanned e) events
-
with
-
| Yamle_error e ->
-
Format.printf "Error (expected): %a@." Error.pp e
-13
yaml/ocaml-yamle/tests/debug_y79y_09.ml
···
-
open Yamle
-
let () =
-
(* Y79Y/09: ? key:<nl>:<tab>key: *)
-
let yaml = "? key:\n:\tkey:" in
-
Format.printf "YAML: %S@.@." yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Format.printf "Events: %d (ERROR: should have failed)@." (List.length events);
-
List.iter (fun e -> Format.printf " %a@." Event.pp_spanned e) events
-
with
-
| Yamle_error e ->
-
Format.printf "Error (expected): %a@." Error.pp e
-13
yaml/ocaml-yamle/tests/debug_y79y_first.ml
···
-
open Yamle
-
let () =
-
(* Y79Y first test: block scalar followed by tab-only line *)
-
let yaml = "foo: |\n\t\nbar: 1\n" in
-
Format.printf "YAML: %S@.@." yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Format.printf "Events: %d (ERROR: should have failed)@." (List.length events);
-
List.iter (fun e -> Format.printf " %a@." Event.pp_spanned e) events
-
with
-
| Yamle_error e ->
-
Format.printf "Error (expected): %a@." Error.pp e
-186
yaml/ocaml-yamle/tests/dune
···
(name run_all_tests)
(modules run_all_tests)
(libraries yamle test_suite_lib))
-
-
(executable
-
(name categorize_failures)
-
(modules categorize_failures)
-
(libraries yamle test_suite_lib))
-
-
(executable
-
(name debug_empty_key)
-
(modules debug_empty_key)
-
(libraries yamle))
-
-
(executable
-
(name debug_5we3_6m2f)
-
(modules debug_5we3_6m2f)
-
(libraries yamle))
-
-
(executable
-
(name test_6vjk_only)
-
(modules test_6vjk_only)
-
(libraries yamle))
-
-
(executable
-
(name test_565n_debug)
-
(modules test_565n_debug)
-
(libraries yamle))
-
-
(executable
-
(name debug_flow)
-
(modules debug_flow)
-
(libraries yamle))
-
-
(executable
-
(name debug_flow2)
-
(modules debug_flow2)
-
(libraries yamle))
-
-
(executable
-
(name debug_flow3)
-
(modules debug_flow3)
-
(libraries yamle))
-
-
(executable
-
(name debug_flow4)
-
(modules debug_flow4)
-
(libraries yamle))
-
-
(executable
-
(name debug_flow5)
-
(modules debug_flow5)
-
(libraries yamle))
-
-
(executable
-
(name debug_flow6)
-
(modules debug_flow6)
-
(libraries yamle))
-
-
(executable
-
(name debug_flow7)
-
(modules debug_flow7)
-
(libraries yamle))
-
-
(executable
-
(name test_87e4)
-
(modules test_87e4)
-
(libraries yamle))
-
-
(executable
-
(name test_tokens2)
-
(modules test_tokens2)
-
(libraries yamle))
-
-
(executable
-
(name test_remaining)
-
(modules test_remaining)
-
(libraries yamle))
-
-
(executable
-
(name debug_multiline)
-
(modules debug_multiline)
-
(libraries yamle))
-
-
(executable
-
(name test_anchor_tag_issues)
-
(modules test_anchor_tag_issues)
-
(libraries yamle))
-
-
(executable
-
(name debug_quoted)
-
(modules debug_quoted)
-
(libraries yamle test_suite_lib))
-
-
(executable
-
(name debug_prh3)
-
(modules debug_prh3)
-
(libraries yamle))
-
-
(executable
-
(name test_nat4_a)
-
(modules test_nat4_a)
-
(libraries yamle))
-
-
(executable
-
(name test_simple_single)
-
(modules test_simple_single)
-
(libraries yamle))
-
-
(executable
-
(name test_a984_trace)
-
(modules test_a984_trace)
-
(libraries yamle))
-
-
(executable
-
(name debug_block_scalars)
-
(modules debug_block_scalars)
-
(libraries yamle))
-
-
(executable
-
(name debug_jef9)
-
(modules debug_jef9)
-
(libraries yamle test_suite_lib))
-
-
(executable
-
(name debug_l24t)
-
(modules debug_l24t)
-
(libraries yamle test_suite_lib))
-
-
(executable
-
(name debug_r4yg)
-
(modules debug_r4yg)
-
(libraries yamle test_suite_lib))
-
-
(executable
-
(name test_y79y)
-
(modules test_y79y)
-
(libraries yamle))
-
-
(executable
-
(name test_y79y_simple)
-
(modules test_y79y_simple)
-
(libraries yamle))
-
-
(executable
-
(name test_y79y_trace)
-
(modules test_y79y_trace)
-
(libraries yamle))
-
-
(executable
-
(name test_y79y_all)
-
(modules test_y79y_all)
-
(libraries yamle))
-
-
(executable
-
(name debug_block_issues)
-
(modules debug_block_issues)
-
(libraries yamle test_suite_lib))
-
(executable (name test_simple_key_debug) (modules test_simple_key_debug) (libraries yamle))
-
(executable (name test_trace_a984) (modules test_trace_a984) (libraries yamle))
-
(executable (name test_debug_stale) (modules test_debug_stale) (libraries yamle))
-
(executable (name test_error_type) (modules test_error_type) (libraries yamle))
-
(executable (name test_a984_minimal) (modules test_a984_minimal) (libraries yamle))
-
(executable (name test_indent_debug) (modules test_indent_debug) (libraries yamle))
-
(executable (name test_all_mentioned_cases) (modules test_all_mentioned_cases) (libraries yamle))
-
(executable (name debug_m2n8) (modules debug_m2n8) (libraries yamle test_suite_lib))
-
(executable (name debug_v9d5) (modules debug_v9d5) (libraries yamle test_suite_lib))
-
(executable (name test_lhl4) (modules test_lhl4) (libraries yamle))
-
(executable (name test_dk4h) (modules test_dk4h) (libraries yamle))
-
(executable (name test_sy6v) (modules test_sy6v) (libraries yamle))
-
(executable (name test_3hfz) (modules test_3hfz) (libraries yamle))
-
(executable (name test_5u3a) (modules test_5u3a) (libraries yamle))
-
(executable (name test_2cms) (modules test_2cms) (libraries yamle))
-
(executable (name test_basic_yaml) (modules test_basic_yaml) (libraries yamle))
-
(executable (name test_loader_debug) (modules test_loader_debug) (libraries yamle test_suite_lib))
-
(executable (name test_229q_direct) (modules test_229q_direct) (libraries yamle))
-
(executable (name debug_from) (modules debug_from) (libraries yamle))
-
(executable (name test_2cms_quick) (modules test_2cms_quick) (libraries yamle))
-
(executable (name count_tests) (modules count_tests) (libraries test_suite_lib))
-
(executable (name test_bs4k) (modules test_bs4k) (libraries yamle))
-
(executable (name test_ks4u) (modules test_ks4u) (libraries yamle))
-
(executable (name test_5llu_quick) (modules test_5llu_quick) (libraries yamle))
-
(executable (name test_mus6_debug) (modules test_mus6_debug) (libraries yamle))
-
(executable (name debug_mus6_load) (modules debug_mus6_load) (libraries yamle test_suite_lib))
-
(executable (name debug_mus6_01) (modules debug_mus6_01) (libraries yamle))
-
(executable (name debug_dk95_01) (modules debug_dk95_01) (libraries yamle))
-
(executable (name debug_y79y_first) (modules debug_y79y_first) (libraries yamle))
-
(executable (name debug_y79y_03) (modules debug_y79y_03) (libraries yamle))
-
(executable (name debug_y79y_09) (modules debug_y79y_09) (libraries yamle))
+353 -33
yaml/ocaml-yamle/tests/run_all_tests.ml
···
-
(* Run all yaml-test-suite tests *)
+
(* Run all yaml-test-suite tests with optional HTML output *)
open Yamle
module TL = Test_suite_lib.Test_suite_loader
module TF = Test_suite_lib.Tree_format
+
(* Configuration - single variable for test suite path *)
let test_suite_path = "../yaml-test-suite"
+
(* HTML escape function *)
+
let html_escape s =
+
let buf = Buffer.create (String.length s) in
+
String.iter (function
+
| '<' -> Buffer.add_string buf "&lt;"
+
| '>' -> Buffer.add_string buf "&gt;"
+
| '&' -> Buffer.add_string buf "&amp;"
+
| '"' -> Buffer.add_string buf "&quot;"
+
| c -> Buffer.add_char buf c
+
) s;
+
Buffer.contents buf
+
let normalize_tree s =
let lines = String.split_on_char '\n' s in
let lines = List.filter (fun l -> String.trim l <> "") lines in
String.concat "\n" lines
-
let run_test (test : TL.test_case) =
+
type test_result = {
+
id : string;
+
name : string;
+
yaml : string;
+
expected_tree : string option;
+
is_error_test : bool;
+
status : [`Pass | `Fail of string | `Skip];
+
output : string;
+
}
+
+
let run_test (test : TL.test_case) : test_result =
+
let base = {
+
id = test.id;
+
name = test.name;
+
yaml = test.yaml;
+
expected_tree = test.tree;
+
is_error_test = test.fail;
+
status = `Skip;
+
output = "";
+
} in
if test.fail then begin
try
let parser = Parser.of_string test.yaml in
-
let _events = Parser.to_list parser in
-
`Fail "Expected parsing to fail"
+
let events = Parser.to_list parser in
+
let tree = TF.of_spanned_events events in
+
{ base with
+
status = `Fail "Expected parsing to fail";
+
output = tree;
+
}
with
-
| Yamle_error _ -> `Pass
-
| _ -> `Pass
+
| Yamle_error e ->
+
{ base with
+
status = `Pass;
+
output = Format.asprintf "%a" Error.pp e;
+
}
+
| exn ->
+
{ base with
+
status = `Pass;
+
output = Printexc.to_string exn;
+
}
end
else begin
match test.tree with
-
| None -> `Skip
+
| None ->
+
(* No expected tree - check if json indicates expected success *)
+
(match test.json with
+
| Some _ ->
+
(* Has json output, so should parse successfully *)
+
(try
+
let parser = Parser.of_string test.yaml in
+
let events = Parser.to_list parser in
+
let tree = TF.of_spanned_events events in
+
{ base with status = `Pass; output = tree }
+
with exn ->
+
{ base with
+
status = `Fail (Printf.sprintf "Should parse but got: %s" (Printexc.to_string exn));
+
output = Printexc.to_string exn;
+
})
+
| None ->
+
(* No tree, no json, no fail - ambiguous edge case, skip *)
+
{ base with status = `Skip; output = "(no expected tree or json)" })
| Some expected ->
try
let parser = Parser.of_string test.yaml in
···
let actual = TF.of_spanned_events events in
let expected_norm = normalize_tree expected in
let actual_norm = normalize_tree actual in
-
if expected_norm = actual_norm then `Pass
-
else begin
-
let msg = Printf.sprintf "Tree mismatch:\nExpected:\n%s\nActual:\n%s" expected_norm actual_norm in
-
`Fail msg
-
end
-
with e ->
-
let msg = Printexc.to_string e in
-
`Fail (Printf.sprintf "Exception: %s" msg)
+
if expected_norm = actual_norm then
+
{ base with status = `Pass; output = actual }
+
else
+
{ base with
+
status = `Fail (Printf.sprintf "Tree mismatch");
+
output = Printf.sprintf "Expected:\n%s\n\nActual:\n%s" expected_norm actual_norm;
+
}
+
with exn ->
+
{ base with
+
status = `Fail (Printf.sprintf "Exception: %s" (Printexc.to_string exn));
+
output = Printexc.to_string exn;
+
}
end
+
let status_class = function
+
| `Pass -> "pass"
+
| `Fail _ -> "fail"
+
| `Skip -> "skip"
+
+
let status_text = function
+
| `Pass -> "PASS"
+
| `Fail _ -> "FAIL"
+
| `Skip -> "SKIP"
+
+
let generate_html results output_file =
+
let oc = open_out output_file in
+
let pass_count = List.length (List.filter (fun r -> r.status = `Pass) results) in
+
let fail_count = List.length (List.filter (fun r -> match r.status with `Fail _ -> true | _ -> false) results) in
+
let skip_count = List.length (List.filter (fun r -> r.status = `Skip) results) in
+
let total = List.length results in
+
+
Printf.fprintf oc {|<!DOCTYPE html>
+
<html lang="en">
+
<head>
+
<meta charset="UTF-8">
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
+
<title>Yamle Test Results</title>
+
<style>
+
:root {
+
--pass-color: #22c55e;
+
--fail-color: #ef4444;
+
--skip-color: #f59e0b;
+
--bg-color: #1a1a2e;
+
--card-bg: #16213e;
+
--text-color: #e2e8f0;
+
--border-color: #334155;
+
}
+
* { box-sizing: border-box; margin: 0; padding: 0; }
+
body {
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
+
background: var(--bg-color);
+
color: var(--text-color);
+
line-height: 1.6;
+
padding: 2rem;
+
}
+
.container { max-width: 1400px; margin: 0 auto; }
+
h1 { margin-bottom: 1.5rem; font-size: 2rem; }
+
.summary {
+
display: flex;
+
gap: 1rem;
+
margin-bottom: 2rem;
+
flex-wrap: wrap;
+
}
+
.stat {
+
background: var(--card-bg);
+
padding: 1rem 1.5rem;
+
border-radius: 8px;
+
border-left: 4px solid var(--border-color);
+
}
+
.stat.pass { border-left-color: var(--pass-color); }
+
.stat.fail { border-left-color: var(--fail-color); }
+
.stat.skip { border-left-color: var(--skip-color); }
+
.stat-value { font-size: 2rem; font-weight: bold; }
+
.stat-label { font-size: 0.875rem; opacity: 0.8; }
+
.filters {
+
margin-bottom: 1.5rem;
+
display: flex;
+
gap: 0.5rem;
+
flex-wrap: wrap;
+
}
+
.filter-btn {
+
padding: 0.5rem 1rem;
+
border: 1px solid var(--border-color);
+
background: var(--card-bg);
+
color: var(--text-color);
+
border-radius: 4px;
+
cursor: pointer;
+
transition: all 0.2s;
+
}
+
.filter-btn:hover { border-color: var(--text-color); }
+
.filter-btn.active { background: var(--text-color); color: var(--bg-color); }
+
.search {
+
padding: 0.5rem 1rem;
+
border: 1px solid var(--border-color);
+
background: var(--card-bg);
+
color: var(--text-color);
+
border-radius: 4px;
+
width: 200px;
+
}
+
.tests { display: flex; flex-direction: column; gap: 1rem; }
+
.test {
+
background: var(--card-bg);
+
border-radius: 8px;
+
border: 1px solid var(--border-color);
+
overflow: hidden;
+
}
+
.test-header {
+
padding: 1rem;
+
display: flex;
+
align-items: center;
+
gap: 1rem;
+
cursor: pointer;
+
border-bottom: 1px solid var(--border-color);
+
}
+
.test-header:hover { background: rgba(255,255,255,0.05); }
+
.badge {
+
padding: 0.25rem 0.5rem;
+
border-radius: 4px;
+
font-size: 0.75rem;
+
font-weight: bold;
+
text-transform: uppercase;
+
}
+
.badge.pass { background: var(--pass-color); color: #000; }
+
.badge.fail { background: var(--fail-color); color: #fff; }
+
.badge.skip { background: var(--skip-color); color: #000; }
+
.badge.error-test { background: #8b5cf6; color: #fff; margin-left: auto; }
+
.test-id { font-family: monospace; font-weight: bold; }
+
.test-name { opacity: 0.8; flex: 1; }
+
.test-content { display: none; padding: 1rem; }
+
.test.expanded .test-content { display: block; }
+
.section { margin-bottom: 1rem; }
+
.section-title {
+
font-size: 0.875rem;
+
text-transform: uppercase;
+
opacity: 0.6;
+
margin-bottom: 0.5rem;
+
letter-spacing: 0.05em;
+
}
+
pre {
+
background: #0f172a;
+
padding: 1rem;
+
border-radius: 4px;
+
overflow-x: auto;
+
font-size: 0.875rem;
+
white-space: pre-wrap;
+
word-break: break-all;
+
}
+
.expand-icon { transition: transform 0.2s; }
+
.test.expanded .expand-icon { transform: rotate(90deg); }
+
</style>
+
</head>
+
<body>
+
<div class="container">
+
<h1>Yamle Test Results</h1>
+
<div class="summary">
+
<div class="stat pass">
+
<div class="stat-value">%d</div>
+
<div class="stat-label">Passed</div>
+
</div>
+
<div class="stat fail">
+
<div class="stat-value">%d</div>
+
<div class="stat-label">Failed</div>
+
</div>
+
<div class="stat skip">
+
<div class="stat-value">%d</div>
+
<div class="stat-label">Skipped</div>
+
</div>
+
<div class="stat">
+
<div class="stat-value">%d</div>
+
<div class="stat-label">Total</div>
+
</div>
+
</div>
+
<div class="filters">
+
<button class="filter-btn active" data-filter="all">All</button>
+
<button class="filter-btn" data-filter="pass">Pass</button>
+
<button class="filter-btn" data-filter="fail">Fail</button>
+
<button class="filter-btn" data-filter="skip">Skip</button>
+
<input type="text" class="search" placeholder="Search by ID or name...">
+
</div>
+
<div class="tests">
+
|} pass_count fail_count skip_count total;
+
+
List.iter (fun result ->
+
let error_badge = if result.is_error_test then
+
{|<span class="badge error-test">Error Test</span>|}
+
else "" in
+
Printf.fprintf oc {| <div class="test" data-status="%s" data-id="%s" data-name="%s">
+
<div class="test-header" onclick="this.parentElement.classList.toggle('expanded')">
+
<span class="expand-icon">▶</span>
+
<span class="badge %s">%s</span>
+
<span class="test-id">%s</span>
+
<span class="test-name">%s</span>
+
%s
+
</div>
+
<div class="test-content">
+
<div class="section">
+
<div class="section-title">YAML Input</div>
+
<pre>%s</pre>
+
</div>
+
<div class="section">
+
<div class="section-title">Yamle Output</div>
+
<pre>%s</pre>
+
</div>
+
</div>
+
</div>
+
|}
+
(status_class result.status)
+
(html_escape result.id)
+
(html_escape (String.lowercase_ascii result.name))
+
(status_class result.status)
+
(status_text result.status)
+
(html_escape result.id)
+
(html_escape result.name)
+
error_badge
+
(html_escape result.yaml)
+
(html_escape result.output)
+
) results;
+
+
Printf.fprintf oc {| </div>
+
</div>
+
<script>
+
document.querySelectorAll('.filter-btn').forEach(btn => {
+
btn.addEventListener('click', () => {
+
document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
+
btn.classList.add('active');
+
filterTests();
+
});
+
});
+
document.querySelector('.search').addEventListener('input', filterTests);
+
function filterTests() {
+
const filter = document.querySelector('.filter-btn.active').dataset.filter;
+
const search = document.querySelector('.search').value.toLowerCase();
+
document.querySelectorAll('.test').forEach(test => {
+
const status = test.dataset.status;
+
const id = test.dataset.id.toLowerCase();
+
const name = test.dataset.name;
+
const matchesFilter = filter === 'all' || status === filter;
+
const matchesSearch = !search || id.includes(search) || name.includes(search);
+
test.style.display = matchesFilter && matchesSearch ? '' : 'none';
+
});
+
}
+
</script>
+
</body>
+
</html>
+
|};
+
close_out oc
+
let () =
+
let html_output = ref None in
+
let show_skipped = ref false in
+
let args = [
+
"--html", Arg.String (fun s -> html_output := Some s),
+
"<file> Generate HTML report to file";
+
"--show-skipped", Arg.Set show_skipped,
+
" Show details of skipped tests";
+
] in
+
Arg.parse args (fun _ -> ()) "Usage: run_all_tests [--html <file>] [--show-skipped]";
+
let src_path = Filename.concat test_suite_path "src" in
let all_tests = TL.load_directory src_path in
Printf.printf "Total tests loaded: %d\n%!" (List.length all_tests);
-
let pass = ref 0 in
-
let fail = ref 0 in
-
let skip = ref 0 in
-
let failures = ref [] in
+
let results = List.map run_test all_tests in
-
List.iter (fun test ->
-
match run_test test with
-
| `Pass -> incr pass
-
| `Skip -> incr skip
-
| `Fail msg ->
-
incr fail;
-
failures := (test.TL.id, test.TL.name, msg) :: !failures
-
) all_tests;
+
let pass_count = List.length (List.filter (fun r -> r.status = `Pass) results) in
+
let fail_count = List.length (List.filter (fun r -> match r.status with `Fail _ -> true | _ -> false) results) in
+
let skip_count = List.length (List.filter (fun r -> r.status = `Skip) results) in
Printf.printf "\nResults: %d pass, %d fail, %d skip (total: %d)\n%!"
-
!pass !fail !skip (!pass + !fail + !skip);
+
pass_count fail_count skip_count (pass_count + fail_count + skip_count);
-
if !fail > 0 then begin
+
if fail_count > 0 then begin
Printf.printf "\nFailing tests:\n";
-
List.iter (fun (id, name, _msg) ->
-
Printf.printf " %s: %s\n" id name
-
) (List.rev !failures)
-
end
+
List.iter (fun r ->
+
match r.status with
+
| `Fail msg -> Printf.printf " %s: %s - %s\n" r.id r.name msg
+
| _ -> ()
+
) results
+
end;
+
+
if !show_skipped && skip_count > 0 then begin
+
Printf.printf "\nSkipped tests (no expected tree):\n";
+
List.iter (fun r ->
+
if r.status = `Skip then begin
+
Printf.printf " %s: %s\n" r.id r.name;
+
Printf.printf " YAML (%d chars): %S\n" (String.length r.yaml)
+
(if String.length r.yaml <= 60 then r.yaml
+
else String.sub r.yaml 0 60 ^ "...")
+
end
+
) results
+
end;
+
+
match !html_output with
+
| Some file ->
+
generate_html results file;
+
Printf.printf "\nHTML report generated: %s\n" file
+
| None -> ()
-23
yaml/ocaml-yamle/tests/test_229q_direct.ml
···
-
open Yamle
-
-
let () =
-
let yaml = In_channel.with_open_text "../yaml-test-suite/src/229Q.yaml" In_channel.input_all in
-
Printf.printf "YAML length: %d\n" (String.length yaml);
-
Printf.printf "First 200 chars: %S\n" (String.sub yaml 0 (min 200 (String.length yaml)));
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "\nTokens:\n";
-
try
-
let rec loop count =
-
if count > 30 then Printf.printf " ... (stopped at 30 tokens)\n"
-
else match Scanner.next scanner with
-
| None -> Printf.printf " (none)\n"
-
| Some tok ->
-
Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
-
(Format.asprintf "%a" Token.pp tok.token);
-
match tok.token with
-
| Token.Stream_end -> ()
-
| _ -> loop (count + 1)
-
in
-
loop 0
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-12
yaml/ocaml-yamle/tests/test_2cms.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "this\n is\n invalid: x\n" in
-
Printf.printf "YAML: %S\n" yaml;
-
Printf.printf "\nParsing:\n";
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Printf.printf "Events: %d (should have errored)\n" (List.length events)
-
with e ->
-
Printf.printf "Error (expected): %s\n" (Printexc.to_string e)
-18
yaml/ocaml-yamle/tests/test_2cms_quick.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "this\n is\n invalid: x\n" in
-
Format.printf "YAML: %S@.@." yaml;
-
Format.printf "Parsing:@.";
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Format.printf "Events: %d (ERROR: should have failed)@." (List.length events);
-
List.iter (fun e ->
-
Format.printf " %a@." Event.pp e.Event.event
-
) events
-
with
-
| Yamle_error e ->
-
Format.printf "Error (expected): %a@." Error.pp e
-
| e ->
-
Format.printf "Error: %s@." (Printexc.to_string e)
-25
yaml/ocaml-yamle/tests/test_3hfz.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "---\nkey: value\n... invalid\n" in
-
Printf.printf "YAML: %S\n" yaml;
-
Printf.printf "Byte 18: %C (space=%b, break=%b)\n"
-
yaml.[18]
-
(yaml.[18] = ' ' || yaml.[18] = '\t')
-
(yaml.[18] = '\n' || yaml.[18] = '\r');
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "\nTokens:\n";
-
try
-
let rec loop () =
-
match Scanner.next scanner with
-
| None -> Printf.printf " (none)\n"
-
| Some tok ->
-
Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
-
(Format.asprintf "%a" Token.pp tok.token);
-
match tok.token with
-
| Token.Stream_end -> ()
-
| _ -> loop ()
-
in
-
loop ()
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-29
yaml/ocaml-yamle/tests/test_565n_debug.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "generic: !!binary |
-
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
-
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
-
+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
-
AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=" in
-
-
let scanner = Scanner.of_string yaml in
-
let rec find_binary () =
-
match Scanner.next scanner with
-
| None -> None
-
| Some { token; _ } ->
-
match token with
-
| Token.Scalar { style = Scalar_style.Literal; value; _ } -> Some value
-
| _ -> find_binary ()
-
in
-
match find_binary () with
-
| None -> Printf.printf "No literal scalar found\n"
-
| Some value ->
-
Printf.printf "Got: %S\n" value;
-
Printf.printf "First char: %C (code %d)\n" value.[0] (Char.code value.[0]);
-
if value.[0] = ' ' then
-
Printf.printf "FAIL: starts with space\n"
-
else if value.[0] = 'R' then
-
Printf.printf "PASS: starts with R\n"
-
else
-
Printf.printf "FAIL: starts with unexpected char\n"
-17
yaml/ocaml-yamle/tests/test_5llu_quick.ml
···
-
open Yamle
-
(* Test 5LLU: Block scalar with wrong indented line after spaces only *)
-
let () =
-
(* block scalar: >
-
␣ (1 space, empty line)
-
␣␣ (2 spaces, empty line)
-
␣␣␣ (3 spaces, empty line)
-
invalid (1 space + content - ERROR!) *)
-
let yaml = "block scalar: >\n \n \n \n invalid\n" in
-
Format.printf "YAML: %S@.@." yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Format.printf "Events: %d (ERROR: should have failed)@." (List.length events)
-
with
-
| Yamle_error e ->
-
Format.printf "Error (expected): %a@." Error.pp e
-11
yaml/ocaml-yamle/tests/test_5u3a.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "key: - a\n - b\n" in
-
Printf.printf "YAML: %S\n" yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Printf.printf "Events: %d (should have errored)\n" (List.length events)
-
with e ->
-
Printf.printf "Error (expected): %s\n" (Printexc.to_string e)
-29
yaml/ocaml-yamle/tests/test_6vjk_debug.ml
···
-
open Yamle
-
-
let () =
-
let yaml = ">
-
Sammy Sosa completed another
-
fine season with great stats.
-
-
63 Home Runs
-
0.288 Batting Average
-
-
What a year!" in
-
Printf.printf "Input YAML:\n%s\n\n" yaml;
-
-
(* Create scanner and get scalar token *)
-
let scanner = Scanner.of_string yaml in
-
let rec find_scalar () =
-
match Scanner.next scanner with
-
| None -> failwith "No scalar found"
-
| Some { token; _ } ->
-
match token with
-
| Token.Scalar (style, value) ->
-
Printf.printf "Scalar value: %S\n" value;
-
Printf.printf "Style: %s\n" (match style with
-
| Scalar_style.Literal -> "Literal"
-
| Scalar_style.Folded -> "Folded"
-
| _ -> "Other")
-
| _ -> find_scalar ()
-
in
-
find_scalar ()
-31
yaml/ocaml-yamle/tests/test_6vjk_only.ml
···
-
open Yamle
-
-
let () =
-
let yaml = ">
-
Sammy Sosa completed another
-
fine season with great stats.
-
-
63 Home Runs
-
0.288 Batting Average
-
-
What a year!" in
-
-
let scanner = Scanner.of_string yaml in
-
let rec find_scalar () =
-
match Scanner.next scanner with
-
| None -> None
-
| Some { token; _ } ->
-
match token with
-
| Token.Scalar { style = _; value } -> Some value
-
| _ -> find_scalar ()
-
in
-
match find_scalar () with
-
| None -> Printf.printf "No scalar found\n"
-
| Some value ->
-
Printf.printf "Got: %S\n" value;
-
let expected = "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n" in
-
Printf.printf "Expected: %S\n" expected;
-
if value = expected then
-
Printf.printf "PASS\n"
-
else
-
Printf.printf "FAIL\n"
-25
yaml/ocaml-yamle/tests/test_87e4.ml
···
-
open Yamle
-
-
let yaml = {|'implicit block key' : [
-
'implicit flow key' : value,
-
]|}
-
-
let () =
-
Printf.printf "Testing 87E4\n";
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Printf.printf "Parsed successfully with %d events\n" (List.length events);
-
List.iteri (fun i ev ->
-
Printf.printf "Event %d: " i;
-
(match ev.Event.event with
-
| Event.Sequence_start _ -> Printf.printf "Sequence_start"
-
| Event.Sequence_end -> Printf.printf "Sequence_end"
-
| Event.Mapping_start _ -> Printf.printf "Mapping_start"
-
| Event.Mapping_end -> Printf.printf "Mapping_end"
-
| Event.Scalar {value; _} -> Printf.printf "Scalar(%S)" value
-
| _ -> Printf.printf "Other");
-
Printf.printf "\n"
-
) events
-
with Error.Yamle_error _ ->
-
Printf.printf "ERROR\n"
-14
yaml/ocaml-yamle/tests/test_a984_minimal.ml
···
-
open Yamle
-
-
let test yaml =
-
Printf.printf "YAML:\n%s\n\n" yaml;
-
let scanner = Scanner.of_string yaml in
-
try
-
while Scanner.next scanner <> None do () done;
-
Printf.printf "Success!\n"
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-
-
let () =
-
test "d:\n e";
-
test "a: b\n c\nd:\n e\n f"
-20
yaml/ocaml-yamle/tests/test_a984_trace.ml
···
-
(* Trace A984 issue *)
-
open Yamle
-
-
let show_token tok =
-
Format.asprintf "%a" Token.pp_spanned tok
-
-
let () =
-
let yaml = "a: b\n c\nd:\n e\n f" in
-
Printf.printf "Testing A984:\n%s\n\n" yaml;
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "Tokens:\n";
-
let rec print_tokens () =
-
match Scanner.peek scanner with
-
| None -> Printf.printf "Done\n"
-
| Some tok ->
-
Printf.printf " %s\n" (show_token tok);
-
ignore (Scanner.next scanner);
-
print_tokens ()
-
in
-
print_tokens ()
-19
yaml/ocaml-yamle/tests/test_all_mentioned_cases.ml
···
-
open Yamle
-
-
let test name yaml =
-
Printf.printf "\n=== %s ===\n" name;
-
let scanner = Scanner.of_string yaml in
-
try
-
while Scanner.next scanner <> None do () done;
-
Printf.printf "PASS\n"
-
with e ->
-
Printf.printf "FAIL: %s\n" (Printexc.to_string e)
-
-
let () =
-
(* All cases mentioned in the issue *)
-
test "565N - Construct Binary" "generic: !!binary |\n R0lGODlh";
-
test "A984 - Multiline Scalar" "a: b\n c\nd:\n e\n f";
-
test "RZP5 - Trailing Comments" "- #lala\n seq2";
-
test "XW4D - Trailing Comments variant" "- #comment\n value";
-
test "Q9WF - Separation Spaces" "a: -\tb";
-
test "V9D5 - Compact Block Mappings" "- a: b"
-167
yaml/ocaml-yamle/tests/test_anchor_tag_issues.ml
···
-
(** Test cases for BU8L, SKE5, RZP5, XW4D *)
-
-
let print_token tok =
-
match tok.Yamle.Token.token with
-
| Yamle.Token.Stream_start _ -> "Stream_start"
-
| Yamle.Token.Stream_end -> "Stream_end"
-
| Yamle.Token.Document_start -> "Document_start"
-
| Yamle.Token.Document_end -> "Document_end"
-
| Yamle.Token.Block_sequence_start -> "Block_sequence_start"
-
| Yamle.Token.Block_mapping_start -> "Block_mapping_start"
-
| Yamle.Token.Block_end -> "Block_end"
-
| Yamle.Token.Flow_sequence_start -> "Flow_sequence_start"
-
| Yamle.Token.Flow_sequence_end -> "Flow_sequence_end"
-
| Yamle.Token.Flow_mapping_start -> "Flow_mapping_start"
-
| Yamle.Token.Flow_mapping_end -> "Flow_mapping_end"
-
| Yamle.Token.Block_entry -> "Block_entry"
-
| Yamle.Token.Flow_entry -> "Flow_entry"
-
| Yamle.Token.Key -> "Key"
-
| Yamle.Token.Value -> "Value"
-
| Yamle.Token.Alias name -> "Alias(" ^ name ^ ")"
-
| Yamle.Token.Anchor name -> "Anchor(" ^ name ^ ")"
-
| Yamle.Token.Tag { handle; suffix } -> "Tag(" ^ handle ^ suffix ^ ")"
-
| Yamle.Token.Scalar { value; _ } -> "Scalar(" ^ String.sub value 0 (min 20 (String.length value)) ^ ")"
-
| Yamle.Token.Version_directive _ -> "Version_directive"
-
| Yamle.Token.Tag_directive _ -> "Tag_directive"
-
-
let test_bu8l () =
-
print_endline "Testing BU8L: Node Anchor and Tag on Separate Lines";
-
let yaml = {|key: &anchor
-
!!map
-
a: b|} in
-
try
-
let scanner = Yamle.Scanner.of_string yaml in
-
let rec print_tokens n =
-
if n > 30 then (print_endline " ... (stopped at 30 tokens)"; ())
-
else
-
try
-
match Yamle.Scanner.peek scanner with
-
| Some { token = Stream_end; _ } as tok ->
-
Printf.printf " %s\n" (print_token (Option.get tok));
-
ignore (Yamle.Scanner.next scanner);
-
()
-
| Some tok ->
-
Printf.printf " %s\n" (print_token tok);
-
ignore (Yamle.Scanner.next scanner);
-
print_tokens (n + 1)
-
| None -> print_endline " (no more tokens)"
-
with
-
| Yamle.Error.Yamle_error e ->
-
Printf.printf " ERROR during scan: %s\n" (Yamle.Error.to_string e);
-
raise (Yamle.Error.Yamle_error e)
-
in
-
print_tokens 0;
-
print_endline "BU8L: Scanner SUCCESS\n"
-
with
-
| Yamle.Error.Yamle_error e ->
-
Printf.printf "BU8L: FAILED with %s\n\n" (Yamle.Error.to_string e)
-
| e ->
-
Printf.printf "BU8L: FAILED with %s\n\n" (Printexc.to_string e)
-
-
let test_ske5 () =
-
print_endline "Testing SKE5: Anchor before zero indented sequence";
-
let yaml = {|---
-
seq:
-
&anchor
-
- a
-
- b|} in
-
try
-
let scanner = Yamle.Scanner.of_string yaml in
-
let rec count_tokens n =
-
match Yamle.Scanner.peek scanner with
-
| Some { token = Stream_end; _ } ->
-
ignore (Yamle.Scanner.next scanner);
-
n
-
| Some _ ->
-
ignore (Yamle.Scanner.next scanner);
-
count_tokens (n + 1)
-
| None -> n
-
in
-
let count = count_tokens 0 in
-
Printf.printf "SKE5: SUCCESS (tokens: %d)\n\n" count
-
with
-
| Yamle.Error.Yamle_error e ->
-
Printf.printf "SKE5: FAILED with %s\n\n" (Yamle.Error.to_string e)
-
| e ->
-
Printf.printf "SKE5: FAILED with %s\n\n" (Printexc.to_string e)
-
-
let test_rzp5 () =
-
print_endline "Testing RZP5: Various Trailing Comments [1.3]";
-
let yaml = {|a: "double
-
quotes" # lala
-
b: plain
-
value # lala
-
c : #lala
-
d
-
? # lala
-
- seq1
-
: # lala
-
- #lala
-
seq2
-
e: &node # lala
-
- x: y
-
block: > # lala
-
abcde|} in
-
try
-
let scanner = Yamle.Scanner.of_string yaml in
-
let rec count_tokens n =
-
match Yamle.Scanner.peek scanner with
-
| Some { token = Stream_end; _ } ->
-
ignore (Yamle.Scanner.next scanner);
-
n
-
| Some _ ->
-
ignore (Yamle.Scanner.next scanner);
-
count_tokens (n + 1)
-
| None -> n
-
in
-
let count = count_tokens 0 in
-
Printf.printf "RZP5: SUCCESS (tokens: %d)\n\n" count
-
with
-
| Yamle.Error.Yamle_error e ->
-
Printf.printf "RZP5: FAILED with %s\n\n" (Yamle.Error.to_string e)
-
| e ->
-
Printf.printf "RZP5: FAILED with %s\n\n" (Printexc.to_string e)
-
-
let test_xw4d () =
-
print_endline "Testing XW4D: Various Trailing Comments";
-
let yaml = {|a: "double
-
quotes" # lala
-
b: plain
-
value # lala
-
c : #lala
-
d
-
? # lala
-
- seq1
-
: # lala
-
- #lala
-
seq2
-
e:
-
&node # lala
-
- x: y
-
block: > # lala
-
abcde|} in
-
try
-
let scanner = Yamle.Scanner.of_string yaml in
-
let rec count_tokens n =
-
match Yamle.Scanner.peek scanner with
-
| Some { token = Stream_end; _ } ->
-
ignore (Yamle.Scanner.next scanner);
-
n
-
| Some _ ->
-
ignore (Yamle.Scanner.next scanner);
-
count_tokens (n + 1)
-
| None -> n
-
in
-
let count = count_tokens 0 in
-
Printf.printf "XW4D: SUCCESS (tokens: %d)\n\n" count
-
with
-
| Yamle.Error.Yamle_error e ->
-
Printf.printf "XW4D: FAILED with %s\n\n" (Yamle.Error.to_string e)
-
| e ->
-
Printf.printf "XW4D: FAILED with %s\n\n" (Printexc.to_string e)
-
-
let () =
-
test_bu8l ();
-
test_ske5 ();
-
test_rzp5 ();
-
test_xw4d ()
-11
yaml/ocaml-yamle/tests/test_basic_yaml.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "key: value\n" in
-
Printf.printf "YAML: %S\n" yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Printf.printf "Events: %d\n" (List.length events)
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-18
yaml/ocaml-yamle/tests/test_bs4k.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "word1 # comment\nword2\n" in
-
Format.printf "YAML: %S@.@." yaml;
-
Format.printf "Parsing:@.";
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Format.printf "Events: %d (ERROR: should have failed)@." (List.length events);
-
List.iter (fun e ->
-
Format.printf " %a@." Event.pp e.Event.event
-
) events
-
with
-
| Yamle_error e ->
-
Format.printf "Error (expected): %a@." Error.pp e
-
| e ->
-
Format.printf "Error: %s@." (Printexc.to_string e)
-21
yaml/ocaml-yamle/tests/test_debug_stale.ml
···
-
open Yamle
-
-
(* Patch Scanner to add debug output *)
-
let test yaml =
-
Printf.printf "YAML:\n%s\n\n" yaml;
-
let scanner = Scanner.of_string yaml in
-
try
-
let rec loop () =
-
match Scanner.next scanner with
-
| None -> Printf.printf "Done\n"
-
| Some tok ->
-
Printf.printf "%s\n" (Format.asprintf "%a" Token.pp_spanned tok);
-
loop ()
-
in
-
loop ()
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-
-
let () =
-
(* This should work: simple key, value on next line *)
-
test "d:\n e"
-21
yaml/ocaml-yamle/tests/test_dk4h.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "---\n[ key\n : value ]\n" in
-
Printf.printf "YAML: %S\n" yaml;
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "\nTokens:\n";
-
try
-
let rec loop () =
-
match Scanner.next scanner with
-
| None -> Printf.printf " (none)\n"
-
| Some tok ->
-
Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
-
(Format.asprintf "%a" Token.pp tok.token);
-
match tok.token with
-
| Token.Stream_end -> ()
-
| _ -> loop ()
-
in
-
loop ()
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-9
yaml/ocaml-yamle/tests/test_error_type.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "d:\n e" in
-
let scanner = Scanner.of_string yaml in
-
try
-
while Scanner.next scanner <> None do () done
-
with Error.Yamle_error err ->
-
Printf.printf "Error: %s\n" (Error.to_string err)
-6
yaml/ocaml-yamle/tests/test_indent_debug.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "d:\n e" in
-
let scanner = Scanner.of_string yaml in
-
ignore (Scanner.to_list scanner)
-18
yaml/ocaml-yamle/tests/test_ks4u.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "---\n[\nsequence item\n]\ninvalid item\n" in
-
Format.printf "YAML: %S@.@." yaml;
-
Format.printf "Parsing:@.";
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Format.printf "Events: %d (ERROR: should have failed)@." (List.length events);
-
List.iter (fun e ->
-
Format.printf " %a@." Event.pp e.Event.event
-
) events
-
with
-
| Yamle_error e ->
-
Format.printf "Error (expected): %a@." Error.pp e
-
| e ->
-
Format.printf "Error: %s@." (Printexc.to_string e)
-21
yaml/ocaml-yamle/tests/test_lhl4.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "---\n!invalid{}tag scalar\n" in
-
Printf.printf "YAML: %S\n" yaml;
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "\nTokens:\n";
-
try
-
let rec loop () =
-
match Scanner.next scanner with
-
| None -> Printf.printf " (none)\n"
-
| Some tok ->
-
Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
-
(Format.asprintf "%a" Token.pp tok.token);
-
match tok.token with
-
| Token.Stream_end -> ()
-
| _ -> loop ()
-
in
-
loop ()
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-9
yaml/ocaml-yamle/tests/test_loader_debug.ml
···
-
module TL = Test_suite_lib.Test_suite_loader
-
-
let () =
-
Printf.printf "Testing test loader...\n";
-
try
-
let tests = TL.load_file "../yaml-test-suite/src/229Q.yaml" in
-
Printf.printf "Loaded %d tests\n" (List.length tests)
-
with e ->
-
Printf.printf "Error loading: %s\n" (Printexc.to_string e)
-11
yaml/ocaml-yamle/tests/test_mus6_debug.ml
···
-
open Yamle
-
let () =
-
let yaml = "%YAML 1.1#...\n---\n" in
-
Format.printf "YAML: %S@.@." yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
Format.printf "Events: %d (ERROR: should have failed)@." (List.length events)
-
with
-
| Yamle_error e ->
-
Format.printf "Error (expected): %a@." Error.pp e
-47
yaml/ocaml-yamle/tests/test_nat4_a.ml
···
-
(* Test NAT4 case a specifically *)
-
open Yamle
-
-
let test_case desc yaml expected =
-
Printf.printf "\n=== %s ===\n" desc;
-
Printf.printf "Input: %s\n" (String.escaped yaml);
-
try
-
let parser = Parser.of_string yaml in
-
let events = Parser.to_list parser in
-
List.iter (fun (e : Event.spanned) ->
-
match e.event with
-
| Event.Scalar { value; style; _ } ->
-
Printf.printf "Output: %s (len=%d, style=%s)\n"
-
(String.escaped value)
-
(String.length value)
-
(match style with
-
| Scalar_style.Single_quoted -> "single"
-
| Scalar_style.Double_quoted -> "double"
-
| _ -> "other");
-
Printf.printf "Expected: %s (len=%d)\n" (String.escaped expected) (String.length expected);
-
if value = expected then
-
Printf.printf "✓ PASS\n"
-
else
-
Printf.printf "✗ FAIL\n"
-
| _ -> ()
-
) events
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-
-
let () =
-
(* NAT4 case a: newline then spaces *)
-
test_case "a" "a: '\n '" " ";
-
-
(* NAT4 case b: spaces, newline, spaces *)
-
test_case "b" "a: ' \n '" " ";
-
-
(* NAT4 case e: newline, empty line, spaces *)
-
test_case "e" "a: '\n\n '" "\n";
-
-
(* NAT4 case g: newline, two empty lines, spaces *)
-
test_case "g" "a: '\n\n\n '" "\n\n";
-
-
(* Simple case: text on both lines *)
-
test_case "simple" "a: 'foo\nbar'" "foo bar";
-
-
(* Case with empty line between text *)
-
test_case "empty_between" "a: 'foo\n\nbar'" "foo\nbar";
-31
yaml/ocaml-yamle/tests/test_remaining.ml
···
-
open Yamle
-
-
let test yaml name =
-
Printf.printf "\n=== %s ===\n" name;
-
Printf.printf "YAML: %S\n" yaml;
-
try
-
let parser = Parser.of_string yaml in
-
let _ = Parser.to_list parser in
-
Printf.printf "SUCCESS\n"
-
with Error.Yamle_error _ ->
-
Printf.printf "ERROR\n"
-
-
let () =
-
(* CT4Q: Single Pair Explicit Entry *)
-
test {|[
-
? foo
-
bar : baz
-
]|} "CT4Q";
-
-
(* DFF7: Flow Mapping Entries *)
-
test {|{
-
? explicit: entry,
-
implicit: entry,
-
?
-
}|} "DFF7";
-
-
(* FRK4: Completely Empty Flow Nodes *)
-
test {|{
-
? foo :,
-
: bar,
-
}|} "FRK4";
-30
yaml/ocaml-yamle/tests/test_simple_key_debug.ml
···
-
open Yamle
-
-
let test_case name yaml =
-
Printf.printf "\n=== Testing %s ===\n" name;
-
Printf.printf "YAML:\n%s\n\n" yaml;
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "Tokens:\n";
-
let rec print_tokens () =
-
match Scanner.next scanner with
-
| None -> Printf.printf "Done\n"
-
| Some tok ->
-
Printf.printf " %s\n" (Format.asprintf "%a" Token.pp_spanned tok);
-
print_tokens ()
-
in
-
try
-
print_tokens ()
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-
-
let () =
-
(* Test A984 - Multiline Scalar in Mapping *)
-
test_case "A984" "a: b\n c\nd:\n e\n f";
-
-
(* Test RZP5 - Trailing Comments *)
-
test_case "RZP5" "- #lala\n seq2";
-
-
(* Simplified versions *)
-
test_case "Simple multiline" "a: b\n c";
-
test_case "Simple block entry with comment" "- # comment\n value";
-
test_case "After block scalar" "a: |\n text\nb: c"
-21
yaml/ocaml-yamle/tests/test_simple_single.ml
···
-
(* Simple test of single-quoted scalar *)
-
open Yamle
-
-
let () =
-
let yaml = "'foo\n\nbar'" in
-
Printf.printf "Input: %s\n" (String.escaped yaml);
-
-
let scanner = Scanner.of_string yaml in
-
Scanner.iter (fun tok ->
-
match tok.Token.token with
-
| Token.Scalar { value; style; _ } ->
-
Printf.printf "Scalar: %s (len=%d)\n" (String.escaped value) (String.length value);
-
Printf.printf "Style: %s\n" (match style with
-
| Scalar_style.Single_quoted -> "single"
-
| _ -> "other");
-
(* Print each character *)
-
for i = 0 to String.length value - 1 do
-
Printf.printf " [%d] = %C (code=%d)\n" i value.[i] (Char.code value.[i])
-
done
-
| _ -> ()
-
) scanner
+3 -1
yaml/ocaml-yamle/tests/test_suite_lib/test_suite_loader.ml
···
name : string;
yaml : string;
tree : string option;
+
json : string option; (* If present, indicates test should parse successfully *)
fail : bool;
}
···
| None -> ""
in
let tree = extract_mapping_value events "tree" in
+
let json = extract_mapping_value events "json" in
let fail = match extract_mapping_value events "fail" with
| Some "true" -> true
| _ -> Option.is_some (extract_mapping_value events "error")
in
-
{ id; name; yaml; tree; fail }
+
{ id; name; yaml; tree; json; fail }
(* Load tests from a single YAML file *)
let load_file path =
-21
yaml/ocaml-yamle/tests/test_sy6v.ml
···
-
open Yamle
-
-
let () =
-
let yaml = "&anchor - sequence entry\n" in
-
Printf.printf "YAML: %S\n" yaml;
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "\nTokens:\n";
-
try
-
let rec loop () =
-
match Scanner.next scanner with
-
| None -> Printf.printf " (none)\n"
-
| Some tok ->
-
Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
-
(Format.asprintf "%a" Token.pp tok.token);
-
match tok.token with
-
| Token.Stream_end -> ()
-
| _ -> loop ()
-
in
-
loop ()
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-24
yaml/ocaml-yamle/tests/test_tokens2.ml
···
-
open Yamle
-
-
let yaml = {|'implicit block key' : [
-
'implicit flow key' : value,
-
]|}
-
-
let () =
-
let scanner = Scanner.of_string yaml in
-
let rec print_all n =
-
match Scanner.next scanner with
-
| None -> ()
-
| Some tok ->
-
Printf.printf "%2d. " n;
-
(match tok.Token.token with
-
| Token.Flow_sequence_start -> Printf.printf "Flow_sequence_start"
-
| Token.Flow_sequence_end -> Printf.printf "Flow_sequence_end"
-
| Token.Flow_entry -> Printf.printf "Flow_entry"
-
| Token.Value -> Printf.printf "Value"
-
| Token.Scalar {value; _} -> Printf.printf "Scalar(%S)" value
-
| _ -> Printf.printf "Other");
-
Printf.printf " at %d:%d\n" tok.span.start.line tok.span.start.column;
-
print_all (n + 1)
-
in
-
print_all 0
-19
yaml/ocaml-yamle/tests/test_trace_a984.ml
···
-
open Yamle
-
-
let () =
-
(* Minimal A984 reproduction *)
-
let yaml = "d:\n e" in
-
Printf.printf "Testing minimal A984:\n%s\n\n" yaml;
-
let scanner = Scanner.of_string yaml in
-
Printf.printf "Tokens:\n";
-
let rec print_tokens () =
-
match Scanner.next scanner with
-
| None -> Printf.printf "Done\n"
-
| Some tok ->
-
Printf.printf " %s\n" (Format.asprintf "%a" Token.pp_spanned tok);
-
print_tokens ()
-
in
-
try
-
print_tokens ()
-
with e ->
-
Printf.printf "Error: %s\n" (Printexc.to_string e)
-41
yaml/ocaml-yamle/tests/test_y79y.ml
···
-
(* Debug Y79Y test cases *)
-
open Yamle
-
-
let () =
-
(* Test case 1: fail=true - tabs at wrong indentation in block scalar *)
-
let yaml1 = "foo: |\n \t\nbar: 1" in
-
Printf.printf "=== Test 1 (should fail) ===\n";
-
Printf.printf "Input: %S\n" yaml1;
-
Printf.printf "Visual:\n";
-
String.iter (fun c ->
-
if c = '\t' then Printf.printf "<TAB>"
-
else if c = '\n' then Printf.printf "<NL>\n"
-
else Printf.printf "%c" c
-
) yaml1;
-
Printf.printf "\n";
-
(try
-
let parser = Parser.of_string yaml1 in
-
let events = Parser.to_list parser in
-
Printf.printf "Events: %d\n" (List.length events);
-
Printf.printf "ERROR: Should have failed but didn't!\n\n"
-
with e ->
-
Printf.printf "Failed as expected: %s\n\n" (Printexc.to_string e));
-
-
(* Test case 2: should succeed - tab with proper indentation in block scalar *)
-
let yaml2 = "foo: |\n \t\nbar: 1" in
-
Printf.printf "=== Test 2 (should succeed) ===\n";
-
Printf.printf "Input: %S\n" yaml2;
-
Printf.printf "Visual:\n";
-
String.iter (fun c ->
-
if c = '\t' then Printf.printf "<TAB>"
-
else if c = '\n' then Printf.printf "<NL>\n"
-
else Printf.printf "%c" c
-
) yaml2;
-
Printf.printf "\n";
-
(try
-
let parser = Parser.of_string yaml2 in
-
let events = Parser.to_list parser in
-
Printf.printf "Events: %d\n" (List.length events);
-
Printf.printf "\n"
-
with e ->
-
Printf.printf "ERROR: Failed but should succeed: %s\n\n" (Printexc.to_string e))
-68
yaml/ocaml-yamle/tests/test_y79y_all.ml
···
-
(* Test all Y79Y cases *)
-
-
let test_case name yaml should_fail =
-
Printf.printf "=== %s ===\n" name;
-
try
-
let scanner = Yamle.Scanner.of_string yaml in
-
let _tokens = Yamle.Scanner.to_list scanner in
-
if should_fail then begin
-
Printf.printf "FAIL: Expected error but parsing succeeded\n";
-
false
-
end else begin
-
Printf.printf "PASS: Parsing succeeded as expected\n";
-
true
-
end
-
with e ->
-
if should_fail then begin
-
Printf.printf "PASS: Failed as expected (%s)\n" (Printexc.to_string e);
-
true
-
end else begin
-
Printf.printf "FAIL: Unexpected error (%s)\n" (Printexc.to_string e);
-
false
-
end
-
-
let () =
-
let results = ref [] in
-
-
(* Y79Y/00: Tab at start - should FAIL *)
-
results := test_case "Y79Y/00" "foo: |\n\t\nbar: 1" true :: !results;
-
-
(* Y79Y/01: Tab after 1 space - should PASS *)
-
results := test_case "Y79Y/01" "foo: |\n \t\nbar: 1" false :: !results;
-
-
(* Y79Y/02: Tab in flow sequence after newline - should PASS *)
-
results := test_case "Y79Y/02" "- [\n\t\n foo\n ]" false :: !results;
-
-
(* Y79Y/03: Tab immediately after flow start and content - should FAIL *)
-
results := test_case "Y79Y/03" "- [\n\tfoo,\n foo\n ]" true :: !results;
-
-
(* Y79Y/04: Tab after dash at root level - should FAIL *)
-
results := test_case "Y79Y/04" "-\t-" true :: !results;
-
-
(* Y79Y/05: Tab after dash with space - should FAIL *)
-
results := test_case "Y79Y/05" "- \t-" true :: !results;
-
-
(* Y79Y/06: Tab after ? at root level - should FAIL *)
-
results := test_case "Y79Y/06" "?\t-" true :: !results;
-
-
(* Y79Y/07: Tab after : in explicit mapping - should FAIL *)
-
results := test_case "Y79Y/07" "? -\n:\t-" true :: !results;
-
-
(* Y79Y/08: Tab after ? before key - should FAIL *)
-
results := test_case "Y79Y/08" "?\tkey:" true :: !results;
-
-
(* Y79Y/09: Tab after : in explicit mapping - should FAIL *)
-
results := test_case "Y79Y/09" "? key:\n:\tkey:" true :: !results;
-
-
(* Y79Y/10: Tab before number (content) - should PASS *)
-
results := test_case "Y79Y/10" "-\t-1" false :: !results;
-
-
Printf.printf "\n=== Summary ===\n";
-
let passed = List.filter (fun x -> x) !results |> List.length in
-
let total = List.length !results in
-
Printf.printf "%d/%d tests passed\n" passed total;
-
if passed = total then
-
Printf.printf "All tests PASSED!\n"
-
else
-
Printf.printf "Some tests FAILED\n";
-
exit (if passed = total then 0 else 1)
-13
yaml/ocaml-yamle/tests/test_y79y_simple.ml
···
-
(* Simple Y79Y test *)
-
-
let () =
-
(* Test case 1: should fail - tab at wrong indentation *)
-
let yaml1 = "foo: |\n \t\nbar: 1" in
-
Printf.printf "=== Test 1 (should fail) ===\n";
-
Printf.printf "Testing: %S\n" yaml1;
-
(try
-
let scanner = Yamle.Scanner.of_string yaml1 in
-
let _tokens = Yamle.Scanner.to_list scanner in
-
Printf.printf "ERROR: Scanning succeeded but should have failed!\n"
-
with e ->
-
Printf.printf "OK: Failed as expected: %s\n" (Printexc.to_string e))
-44
yaml/ocaml-yamle/tests/test_y79y_trace.ml
···
-
(* Trace Y79Y test *)
-
-
let test_case yaml desc should_fail expected_scalars =
-
Printf.printf "=== %s ===\n" desc;
-
Printf.printf "Testing: %S\n" yaml;
-
try
-
let scanner = Yamle.Scanner.of_string yaml in
-
let tokens = Yamle.Scanner.to_list scanner in
-
if should_fail then
-
Printf.printf "ERROR: Expected to fail but got %d tokens\n" (List.length tokens)
-
else begin
-
Printf.printf "OK: Got %d tokens\n" (List.length tokens);
-
let scalars = ref [] in
-
List.iter (fun (t : Yamle.Token.spanned) ->
-
match t.token with
-
| Yamle.Token.Scalar { value; _ } ->
-
scalars := value :: !scalars;
-
Printf.printf " Scalar: %S\n" value
-
| _ -> ()
-
) tokens;
-
let scalars = List.rev !scalars in
-
if scalars <> expected_scalars then begin
-
Printf.printf "ERROR: Expected scalars %s but got %s\n"
-
(String.concat ", " (List.map (Printf.sprintf "%S") expected_scalars))
-
(String.concat ", " (List.map (Printf.sprintf "%S") scalars))
-
end
-
end
-
with e ->
-
if should_fail then
-
Printf.printf "OK: Failed as expected: %s\n" (Printexc.to_string e)
-
else
-
Printf.printf "ERROR: Unexpected failure: %s\n" (Printexc.to_string e)
-
-
let () =
-
(* Test case 0 (Y79Y): should fail - tab at start of content *)
-
let yaml0 = "foo: |\n\t\nbar: 1" in
-
test_case yaml0 "Y79Y/00: tab at start (no spaces)" true [];
-
Printf.printf "\n";
-
-
(* Test case 1 (Y79Y/01): should succeed - tab after 1 space indent *)
-
(* Expected: foo="\t\n", bar="1" *)
-
let yaml1 = "foo: |\n \t\nbar: 1" in
-
test_case yaml1 "Y79Y/01: tab after 1 space" false ["foo"; "\t\n"; "bar"; "1"];
-
Printf.printf "\n"