···11-(* Categorize test failures *)
22-open Yamle
33-module TL = Test_suite_lib.Test_suite_loader
44-module TF = Test_suite_lib.Tree_format
55-66-let test_suite_path = "../yaml-test-suite"
77-88-let normalize_tree s =
99- let lines = String.split_on_char '\n' s in
1010- let lines = List.filter (fun l -> String.trim l <> "") lines in
1111- String.concat "\n" lines
1212-1313-type failure =
1414- | Error_not_detected of string
1515- | Parse_error of string
1616- | Tree_mismatch of string * string
1717-1818-let run_test (test : TL.test_case) =
1919- if test.fail then begin
2020- try
2121- let parser = Parser.of_string test.yaml in
2222- let _events = Parser.to_list parser in
2323- Some (Error_not_detected test.name)
2424- with _ -> None
2525- end
2626- else begin
2727- match test.tree with
2828- | None -> None
2929- | Some expected ->
3030- try
3131- let parser = Parser.of_string test.yaml in
3232- let events = Parser.to_list parser in
3333- let actual = TF.of_spanned_events events in
3434- let expected_norm = normalize_tree expected in
3535- let actual_norm = normalize_tree actual in
3636- if expected_norm = actual_norm then None
3737- else Some (Tree_mismatch (expected_norm, actual_norm))
3838- with e ->
3939- let msg = Printexc.to_string e in
4040- Some (Parse_error msg)
4141- end
4242-4343-let diff_lines expected actual =
4444- let exp_lines = String.split_on_char '\n' expected in
4545- let act_lines = String.split_on_char '\n' actual in
4646- let rec find_diff i es as_ =
4747- match es, as_ with
4848- | [], [] -> None
4949- | [], _ -> Some (Printf.sprintf "Line count: expected %d, got %d" (List.length exp_lines) (List.length act_lines))
5050- | _, [] -> Some (Printf.sprintf "Line count: expected %d, got %d" (List.length exp_lines) (List.length act_lines))
5151- | e :: es', a :: as_' ->
5252- if e = a then find_diff (i + 1) es' as_'
5353- else Some (Printf.sprintf "Line %d differs:\n exp: %s\n got: %s" i e a)
5454- in
5555- find_diff 1 exp_lines act_lines
5656-5757-let () =
5858- let src_path = Filename.concat test_suite_path "src" in
5959- let all_tests = TL.load_directory src_path in
6060-6161- let error_not_detected = ref [] in
6262- let parse_errors = ref [] in
6363- let tree_mismatches = ref [] in
6464-6565- List.iter (fun test ->
6666- match run_test test with
6767- | None -> ()
6868- | Some (Error_not_detected name) ->
6969- error_not_detected := (test.TL.id, name) :: !error_not_detected
7070- | Some (Parse_error msg) ->
7171- parse_errors := (test.TL.id, test.TL.name, msg) :: !parse_errors
7272- | Some (Tree_mismatch (exp, act)) ->
7373- tree_mismatches := (test.TL.id, test.TL.name, exp, act) :: !tree_mismatches
7474- ) all_tests;
7575-7676- Printf.printf "=== ERROR TESTS NOT DETECTED (%d) ===\n" (List.length !error_not_detected);
7777- List.iter (fun (id, name) ->
7878- Printf.printf " %s: %s\n" id name
7979- ) (List.rev !error_not_detected);
8080-8181- Printf.printf "\n=== PARSE ERRORS (%d) ===\n" (List.length !parse_errors);
8282- List.iter (fun (id, name, msg) ->
8383- Printf.printf " %s: %s\n %s\n" id name msg
8484- ) (List.rev !parse_errors);
8585-8686- Printf.printf "\n=== TREE MISMATCHES (%d) ===\n" (List.length !tree_mismatches);
8787- List.iter (fun (id, name, exp, act) ->
8888- let diff = diff_lines exp act in
8989- Printf.printf " %s: %s\n" id name;
9090- match diff with
9191- | Some d -> Printf.printf " %s\n" d
9292- | None -> ()
9393- ) (List.rev !tree_mismatches)
-12
yaml/ocaml-yamle/tests/count_tests.ml
···11-module TL = Test_suite_lib.Test_suite_loader
22-33-let () =
44- let tests = TL.load_directory "../yaml-test-suite/src" in
55- let error_without_tree = List.filter (fun t -> t.TL.fail && t.TL.tree = None) tests in
66- let non_error_without_tree = List.filter (fun t -> (not t.TL.fail) && t.TL.tree = None) tests in
77- Printf.printf "Error tests without tree: %d\n" (List.length error_without_tree);
88- Printf.printf "Non-error tests without tree (will be skipped): %d\n" (List.length non_error_without_tree);
99- Printf.printf "\nError tests without tree:\n";
1010- List.iter (fun t -> Printf.printf " %s\n" t.TL.id) error_without_tree;
1111- Printf.printf "\nNon-error tests without tree:\n";
1212- List.iter (fun t -> Printf.printf " %s\n" t.TL.id) non_error_without_tree
-71
yaml/ocaml-yamle/tests/debug_5we3_6m2f.ml
···11-open Yamle
22-33-let show_token tok =
44- Format.asprintf "%a" Token.pp_spanned tok
55-66-let show_event evt =
77- Format.asprintf "%a" Event.pp_spanned evt
88-99-let test_5we3 () =
1010- Printf.printf "\n=== Test 5WE3: Explicit Block Mapping Entries ===\n";
1111- let yaml = "? explicit key # Empty value\n? |\n block key\n: - one # Explicit compact\n - two # block value" in
1212- Printf.printf "Input:\n%s\n\n" yaml;
1313- try
1414- let scanner = Scanner.of_string yaml in
1515- Printf.printf "Tokens:\n";
1616- let rec print_tokens () =
1717- match Scanner.peek scanner with
1818- | None -> Printf.printf "No more tokens\n"
1919- | Some tok ->
2020- Printf.printf " %s\n" (show_token tok);
2121- ignore (Scanner.next scanner);
2222- print_tokens ()
2323- in
2424- print_tokens ();
2525- Printf.printf "\nParsing:\n";
2626- let scanner = Scanner.of_string yaml in
2727- let parser = Parser.create scanner in
2828- let rec print_events () =
2929- match Parser.next parser with
3030- | None -> Printf.printf "No more events\n"
3131- | Some event ->
3232- Printf.printf " %s\n" (show_event event);
3333- print_events ()
3434- in
3535- print_events ()
3636- with e ->
3737- Printf.printf "ERROR: %s\n" (Printexc.to_string e)
3838-3939-let test_6m2f () =
4040- Printf.printf "\n=== Test 6M2F: Aliases in Explicit Block Mapping ===\n";
4141- let yaml = "? &a a\n: &b b\n: *a" in
4242- Printf.printf "Input:\n%s\n\n" yaml;
4343- try
4444- let scanner = Scanner.of_string yaml in
4545- Printf.printf "Tokens:\n";
4646- let rec print_tokens () =
4747- match Scanner.peek scanner with
4848- | None -> Printf.printf "No more tokens\n"
4949- | Some tok ->
5050- Printf.printf " %s\n" (show_token tok);
5151- ignore (Scanner.next scanner);
5252- print_tokens ()
5353- in
5454- print_tokens ();
5555- Printf.printf "\nParsing:\n";
5656- let scanner = Scanner.of_string yaml in
5757- let parser = Parser.create scanner in
5858- let rec print_events () =
5959- match Parser.next parser with
6060- | None -> Printf.printf "No more events\n"
6161- | Some event ->
6262- Printf.printf " %s\n" (show_event event);
6363- print_events ()
6464- in
6565- print_events ()
6666- with e ->
6767- Printf.printf "ERROR: %s\n" (Printexc.to_string e)
6868-6969-let () =
7070- test_5we3 ();
7171- test_6m2f ()
-62
yaml/ocaml-yamle/tests/debug_block_issues.ml
···11-open Yamle
22-open Test_suite_lib
33-44-let test_case name yaml expected_tree =
55- Printf.printf "\n=== Testing %s ===\n" name;
66- Printf.printf "YAML:\n%s\n" yaml;
77- Printf.printf "\nExpected tree:\n%s\n" expected_tree;
88-99- try
1010- let input = Input.of_string yaml in
1111- let scanner = Scanner.create input in
1212- let parser = Parser.create scanner in
1313-1414- (* Skip token output for now *)
1515- ();
1616-1717- Printf.printf "\nParsing...\n";
1818- let rec collect_events acc =
1919- match Parser.next parser with
2020- | None -> List.rev acc
2121- | Some evt -> collect_events (evt :: acc)
2222- in
2323- let events = collect_events [] in
2424-2525- let tree = Tree_format.of_spanned_events events in
2626- Printf.printf "\nFormatted tree:\n%s\n" tree;
2727-2828- if tree = expected_tree then
2929- Printf.printf "✓ PASS\n"
3030- else
3131- Printf.printf "✗ FAIL - Tree mismatch\n"
3232- with
3333- | Error.Yamle_error err ->
3434- Printf.printf "ERROR: %s\n" (Error.to_string err)
3535- | e ->
3636- Printf.printf "ERROR: %s\n" (Printexc.to_string e)
3737-3838-let () =
3939- (* JEF9 - Extra newlines at end *)
4040- test_case "JEF9"
4141- "- |+\n\n"
4242- "+STR\n +DOC\n +SEQ\n =VAL |\\n\\n\n -SEQ\n -DOC\n-STR";
4343-4444- (* K858 - Empty scalar chomping - block scalar consuming too much *)
4545- test_case "K858"
4646- "strip: >-\n\nclip: >\n\nkeep: |+\n\n"
4747- "+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";
4848-4949- (* L24T - Trailing whitespace-only line *)
5050- test_case "L24T"
5151- "foo: |\n x\n \n"
5252- "+STR\n +DOC\n +MAP\n =VAL :foo\n =VAL |x\\n \\n\n -MAP\n -DOC\n-STR";
5353-5454- (* MJS9 - Folded block newline handling *)
5555- test_case "MJS9"
5656- ">\n foo \n \n \t bar\n\n baz\n"
5757- "+STR\n +DOC\n =VAL >foo \\n\\n\\t bar\\n\\nbaz\\n\n -DOC\n-STR";
5858-5959- (* R4YG - Tab handling in folded block - just the problematic 4th test *)
6060- test_case "R4YG-4"
6161- "- >\n \t\n detected\n"
6262- "+STR\n +DOC\n +SEQ\n =VAL >\\t\\ndetected\\n\n -SEQ\n -DOC\n-STR"
···11-(* Run all yaml-test-suite tests *)
11+(* Run all yaml-test-suite tests with optional HTML output *)
22open Yamle
33module TL = Test_suite_lib.Test_suite_loader
44module TF = Test_suite_lib.Tree_format
5566+(* Configuration - single variable for test suite path *)
67let test_suite_path = "../yaml-test-suite"
7899+(* HTML escape function *)
1010+let html_escape s =
1111+ let buf = Buffer.create (String.length s) in
1212+ String.iter (function
1313+ | '<' -> Buffer.add_string buf "<"
1414+ | '>' -> Buffer.add_string buf ">"
1515+ | '&' -> Buffer.add_string buf "&"
1616+ | '"' -> Buffer.add_string buf """
1717+ | c -> Buffer.add_char buf c
1818+ ) s;
1919+ Buffer.contents buf
2020+821let normalize_tree s =
922 let lines = String.split_on_char '\n' s in
1023 let lines = List.filter (fun l -> String.trim l <> "") lines in
1124 String.concat "\n" lines
12251313-let run_test (test : TL.test_case) =
2626+type test_result = {
2727+ id : string;
2828+ name : string;
2929+ yaml : string;
3030+ expected_tree : string option;
3131+ is_error_test : bool;
3232+ status : [`Pass | `Fail of string | `Skip];
3333+ output : string;
3434+}
3535+3636+let run_test (test : TL.test_case) : test_result =
3737+ let base = {
3838+ id = test.id;
3939+ name = test.name;
4040+ yaml = test.yaml;
4141+ expected_tree = test.tree;
4242+ is_error_test = test.fail;
4343+ status = `Skip;
4444+ output = "";
4545+ } in
1446 if test.fail then begin
1547 try
1648 let parser = Parser.of_string test.yaml in
1717- let _events = Parser.to_list parser in
1818- `Fail "Expected parsing to fail"
4949+ let events = Parser.to_list parser in
5050+ let tree = TF.of_spanned_events events in
5151+ { base with
5252+ status = `Fail "Expected parsing to fail";
5353+ output = tree;
5454+ }
1955 with
2020- | Yamle_error _ -> `Pass
2121- | _ -> `Pass
5656+ | Yamle_error e ->
5757+ { base with
5858+ status = `Pass;
5959+ output = Format.asprintf "%a" Error.pp e;
6060+ }
6161+ | exn ->
6262+ { base with
6363+ status = `Pass;
6464+ output = Printexc.to_string exn;
6565+ }
2266 end
2367 else begin
2468 match test.tree with
2525- | None -> `Skip
6969+ | None ->
7070+ (* No expected tree - check if json indicates expected success *)
7171+ (match test.json with
7272+ | Some _ ->
7373+ (* Has json output, so should parse successfully *)
7474+ (try
7575+ let parser = Parser.of_string test.yaml in
7676+ let events = Parser.to_list parser in
7777+ let tree = TF.of_spanned_events events in
7878+ { base with status = `Pass; output = tree }
7979+ with exn ->
8080+ { base with
8181+ status = `Fail (Printf.sprintf "Should parse but got: %s" (Printexc.to_string exn));
8282+ output = Printexc.to_string exn;
8383+ })
8484+ | None ->
8585+ (* No tree, no json, no fail - ambiguous edge case, skip *)
8686+ { base with status = `Skip; output = "(no expected tree or json)" })
2687 | Some expected ->
2788 try
2889 let parser = Parser.of_string test.yaml in
···3091 let actual = TF.of_spanned_events events in
3192 let expected_norm = normalize_tree expected in
3293 let actual_norm = normalize_tree actual in
3333- if expected_norm = actual_norm then `Pass
3434- else begin
3535- let msg = Printf.sprintf "Tree mismatch:\nExpected:\n%s\nActual:\n%s" expected_norm actual_norm in
3636- `Fail msg
3737- end
3838- with e ->
3939- let msg = Printexc.to_string e in
4040- `Fail (Printf.sprintf "Exception: %s" msg)
9494+ if expected_norm = actual_norm then
9595+ { base with status = `Pass; output = actual }
9696+ else
9797+ { base with
9898+ status = `Fail (Printf.sprintf "Tree mismatch");
9999+ output = Printf.sprintf "Expected:\n%s\n\nActual:\n%s" expected_norm actual_norm;
100100+ }
101101+ with exn ->
102102+ { base with
103103+ status = `Fail (Printf.sprintf "Exception: %s" (Printexc.to_string exn));
104104+ output = Printexc.to_string exn;
105105+ }
41106 end
42107108108+let status_class = function
109109+ | `Pass -> "pass"
110110+ | `Fail _ -> "fail"
111111+ | `Skip -> "skip"
112112+113113+let status_text = function
114114+ | `Pass -> "PASS"
115115+ | `Fail _ -> "FAIL"
116116+ | `Skip -> "SKIP"
117117+118118+let generate_html results output_file =
119119+ let oc = open_out output_file in
120120+ let pass_count = List.length (List.filter (fun r -> r.status = `Pass) results) in
121121+ let fail_count = List.length (List.filter (fun r -> match r.status with `Fail _ -> true | _ -> false) results) in
122122+ let skip_count = List.length (List.filter (fun r -> r.status = `Skip) results) in
123123+ let total = List.length results in
124124+125125+ Printf.fprintf oc {|<!DOCTYPE html>
126126+<html lang="en">
127127+<head>
128128+ <meta charset="UTF-8">
129129+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
130130+ <title>Yamle Test Results</title>
131131+ <style>
132132+ :root {
133133+ --pass-color: #22c55e;
134134+ --fail-color: #ef4444;
135135+ --skip-color: #f59e0b;
136136+ --bg-color: #1a1a2e;
137137+ --card-bg: #16213e;
138138+ --text-color: #e2e8f0;
139139+ --border-color: #334155;
140140+ }
141141+ * { box-sizing: border-box; margin: 0; padding: 0; }
142142+ body {
143143+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
144144+ background: var(--bg-color);
145145+ color: var(--text-color);
146146+ line-height: 1.6;
147147+ padding: 2rem;
148148+ }
149149+ .container { max-width: 1400px; margin: 0 auto; }
150150+ h1 { margin-bottom: 1.5rem; font-size: 2rem; }
151151+ .summary {
152152+ display: flex;
153153+ gap: 1rem;
154154+ margin-bottom: 2rem;
155155+ flex-wrap: wrap;
156156+ }
157157+ .stat {
158158+ background: var(--card-bg);
159159+ padding: 1rem 1.5rem;
160160+ border-radius: 8px;
161161+ border-left: 4px solid var(--border-color);
162162+ }
163163+ .stat.pass { border-left-color: var(--pass-color); }
164164+ .stat.fail { border-left-color: var(--fail-color); }
165165+ .stat.skip { border-left-color: var(--skip-color); }
166166+ .stat-value { font-size: 2rem; font-weight: bold; }
167167+ .stat-label { font-size: 0.875rem; opacity: 0.8; }
168168+ .filters {
169169+ margin-bottom: 1.5rem;
170170+ display: flex;
171171+ gap: 0.5rem;
172172+ flex-wrap: wrap;
173173+ }
174174+ .filter-btn {
175175+ padding: 0.5rem 1rem;
176176+ border: 1px solid var(--border-color);
177177+ background: var(--card-bg);
178178+ color: var(--text-color);
179179+ border-radius: 4px;
180180+ cursor: pointer;
181181+ transition: all 0.2s;
182182+ }
183183+ .filter-btn:hover { border-color: var(--text-color); }
184184+ .filter-btn.active { background: var(--text-color); color: var(--bg-color); }
185185+ .search {
186186+ padding: 0.5rem 1rem;
187187+ border: 1px solid var(--border-color);
188188+ background: var(--card-bg);
189189+ color: var(--text-color);
190190+ border-radius: 4px;
191191+ width: 200px;
192192+ }
193193+ .tests { display: flex; flex-direction: column; gap: 1rem; }
194194+ .test {
195195+ background: var(--card-bg);
196196+ border-radius: 8px;
197197+ border: 1px solid var(--border-color);
198198+ overflow: hidden;
199199+ }
200200+ .test-header {
201201+ padding: 1rem;
202202+ display: flex;
203203+ align-items: center;
204204+ gap: 1rem;
205205+ cursor: pointer;
206206+ border-bottom: 1px solid var(--border-color);
207207+ }
208208+ .test-header:hover { background: rgba(255,255,255,0.05); }
209209+ .badge {
210210+ padding: 0.25rem 0.5rem;
211211+ border-radius: 4px;
212212+ font-size: 0.75rem;
213213+ font-weight: bold;
214214+ text-transform: uppercase;
215215+ }
216216+ .badge.pass { background: var(--pass-color); color: #000; }
217217+ .badge.fail { background: var(--fail-color); color: #fff; }
218218+ .badge.skip { background: var(--skip-color); color: #000; }
219219+ .badge.error-test { background: #8b5cf6; color: #fff; margin-left: auto; }
220220+ .test-id { font-family: monospace; font-weight: bold; }
221221+ .test-name { opacity: 0.8; flex: 1; }
222222+ .test-content { display: none; padding: 1rem; }
223223+ .test.expanded .test-content { display: block; }
224224+ .section { margin-bottom: 1rem; }
225225+ .section-title {
226226+ font-size: 0.875rem;
227227+ text-transform: uppercase;
228228+ opacity: 0.6;
229229+ margin-bottom: 0.5rem;
230230+ letter-spacing: 0.05em;
231231+ }
232232+ pre {
233233+ background: #0f172a;
234234+ padding: 1rem;
235235+ border-radius: 4px;
236236+ overflow-x: auto;
237237+ font-size: 0.875rem;
238238+ white-space: pre-wrap;
239239+ word-break: break-all;
240240+ }
241241+ .expand-icon { transition: transform 0.2s; }
242242+ .test.expanded .expand-icon { transform: rotate(90deg); }
243243+ </style>
244244+</head>
245245+<body>
246246+ <div class="container">
247247+ <h1>Yamle Test Results</h1>
248248+ <div class="summary">
249249+ <div class="stat pass">
250250+ <div class="stat-value">%d</div>
251251+ <div class="stat-label">Passed</div>
252252+ </div>
253253+ <div class="stat fail">
254254+ <div class="stat-value">%d</div>
255255+ <div class="stat-label">Failed</div>
256256+ </div>
257257+ <div class="stat skip">
258258+ <div class="stat-value">%d</div>
259259+ <div class="stat-label">Skipped</div>
260260+ </div>
261261+ <div class="stat">
262262+ <div class="stat-value">%d</div>
263263+ <div class="stat-label">Total</div>
264264+ </div>
265265+ </div>
266266+ <div class="filters">
267267+ <button class="filter-btn active" data-filter="all">All</button>
268268+ <button class="filter-btn" data-filter="pass">Pass</button>
269269+ <button class="filter-btn" data-filter="fail">Fail</button>
270270+ <button class="filter-btn" data-filter="skip">Skip</button>
271271+ <input type="text" class="search" placeholder="Search by ID or name...">
272272+ </div>
273273+ <div class="tests">
274274+|} pass_count fail_count skip_count total;
275275+276276+ List.iter (fun result ->
277277+ let error_badge = if result.is_error_test then
278278+ {|<span class="badge error-test">Error Test</span>|}
279279+ else "" in
280280+ Printf.fprintf oc {| <div class="test" data-status="%s" data-id="%s" data-name="%s">
281281+ <div class="test-header" onclick="this.parentElement.classList.toggle('expanded')">
282282+ <span class="expand-icon">▶</span>
283283+ <span class="badge %s">%s</span>
284284+ <span class="test-id">%s</span>
285285+ <span class="test-name">%s</span>
286286+ %s
287287+ </div>
288288+ <div class="test-content">
289289+ <div class="section">
290290+ <div class="section-title">YAML Input</div>
291291+ <pre>%s</pre>
292292+ </div>
293293+ <div class="section">
294294+ <div class="section-title">Yamle Output</div>
295295+ <pre>%s</pre>
296296+ </div>
297297+ </div>
298298+ </div>
299299+|}
300300+ (status_class result.status)
301301+ (html_escape result.id)
302302+ (html_escape (String.lowercase_ascii result.name))
303303+ (status_class result.status)
304304+ (status_text result.status)
305305+ (html_escape result.id)
306306+ (html_escape result.name)
307307+ error_badge
308308+ (html_escape result.yaml)
309309+ (html_escape result.output)
310310+ ) results;
311311+312312+ Printf.fprintf oc {| </div>
313313+ </div>
314314+ <script>
315315+ document.querySelectorAll('.filter-btn').forEach(btn => {
316316+ btn.addEventListener('click', () => {
317317+ document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
318318+ btn.classList.add('active');
319319+ filterTests();
320320+ });
321321+ });
322322+ document.querySelector('.search').addEventListener('input', filterTests);
323323+ function filterTests() {
324324+ const filter = document.querySelector('.filter-btn.active').dataset.filter;
325325+ const search = document.querySelector('.search').value.toLowerCase();
326326+ document.querySelectorAll('.test').forEach(test => {
327327+ const status = test.dataset.status;
328328+ const id = test.dataset.id.toLowerCase();
329329+ const name = test.dataset.name;
330330+ const matchesFilter = filter === 'all' || status === filter;
331331+ const matchesSearch = !search || id.includes(search) || name.includes(search);
332332+ test.style.display = matchesFilter && matchesSearch ? '' : 'none';
333333+ });
334334+ }
335335+ </script>
336336+</body>
337337+</html>
338338+|};
339339+ close_out oc
340340+43341let () =
342342+ let html_output = ref None in
343343+ let show_skipped = ref false in
344344+ let args = [
345345+ "--html", Arg.String (fun s -> html_output := Some s),
346346+ "<file> Generate HTML report to file";
347347+ "--show-skipped", Arg.Set show_skipped,
348348+ " Show details of skipped tests";
349349+ ] in
350350+ Arg.parse args (fun _ -> ()) "Usage: run_all_tests [--html <file>] [--show-skipped]";
351351+44352 let src_path = Filename.concat test_suite_path "src" in
45353 let all_tests = TL.load_directory src_path in
46354 Printf.printf "Total tests loaded: %d\n%!" (List.length all_tests);
473554848- let pass = ref 0 in
4949- let fail = ref 0 in
5050- let skip = ref 0 in
5151- let failures = ref [] in
356356+ let results = List.map run_test all_tests in
523575353- List.iter (fun test ->
5454- match run_test test with
5555- | `Pass -> incr pass
5656- | `Skip -> incr skip
5757- | `Fail msg ->
5858- incr fail;
5959- failures := (test.TL.id, test.TL.name, msg) :: !failures
6060- ) all_tests;
358358+ let pass_count = List.length (List.filter (fun r -> r.status = `Pass) results) in
359359+ let fail_count = List.length (List.filter (fun r -> match r.status with `Fail _ -> true | _ -> false) results) in
360360+ let skip_count = List.length (List.filter (fun r -> r.status = `Skip) results) in
6136162362 Printf.printf "\nResults: %d pass, %d fail, %d skip (total: %d)\n%!"
6363- !pass !fail !skip (!pass + !fail + !skip);
363363+ pass_count fail_count skip_count (pass_count + fail_count + skip_count);
643646565- if !fail > 0 then begin
365365+ if fail_count > 0 then begin
66366 Printf.printf "\nFailing tests:\n";
6767- List.iter (fun (id, name, _msg) ->
6868- Printf.printf " %s: %s\n" id name
6969- ) (List.rev !failures)
7070- end
367367+ List.iter (fun r ->
368368+ match r.status with
369369+ | `Fail msg -> Printf.printf " %s: %s - %s\n" r.id r.name msg
370370+ | _ -> ()
371371+ ) results
372372+ end;
373373+374374+ if !show_skipped && skip_count > 0 then begin
375375+ Printf.printf "\nSkipped tests (no expected tree):\n";
376376+ List.iter (fun r ->
377377+ if r.status = `Skip then begin
378378+ Printf.printf " %s: %s\n" r.id r.name;
379379+ Printf.printf " YAML (%d chars): %S\n" (String.length r.yaml)
380380+ (if String.length r.yaml <= 60 then r.yaml
381381+ else String.sub r.yaml 0 60 ^ "...")
382382+ end
383383+ ) results
384384+ end;
385385+386386+ match !html_output with
387387+ | Some file ->
388388+ generate_html results file;
389389+ Printf.printf "\nHTML report generated: %s\n" file
390390+ | None -> ()
-23
yaml/ocaml-yamle/tests/test_229q_direct.ml
···11-open Yamle
22-33-let () =
44- let yaml = In_channel.with_open_text "../yaml-test-suite/src/229Q.yaml" In_channel.input_all in
55- Printf.printf "YAML length: %d\n" (String.length yaml);
66- Printf.printf "First 200 chars: %S\n" (String.sub yaml 0 (min 200 (String.length yaml)));
77- let scanner = Scanner.of_string yaml in
88- Printf.printf "\nTokens:\n";
99- try
1010- let rec loop count =
1111- if count > 30 then Printf.printf " ... (stopped at 30 tokens)\n"
1212- else match Scanner.next scanner with
1313- | None -> Printf.printf " (none)\n"
1414- | Some tok ->
1515- Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
1616- (Format.asprintf "%a" Token.pp tok.token);
1717- match tok.token with
1818- | Token.Stream_end -> ()
1919- | _ -> loop (count + 1)
2020- in
2121- loop 0
2222- with e ->
2323- Printf.printf "Error: %s\n" (Printexc.to_string e)
-12
yaml/ocaml-yamle/tests/test_2cms.ml
···11-open Yamle
22-33-let () =
44- let yaml = "this\n is\n invalid: x\n" in
55- Printf.printf "YAML: %S\n" yaml;
66- Printf.printf "\nParsing:\n";
77- try
88- let parser = Parser.of_string yaml in
99- let events = Parser.to_list parser in
1010- Printf.printf "Events: %d (should have errored)\n" (List.length events)
1111- with e ->
1212- Printf.printf "Error (expected): %s\n" (Printexc.to_string e)
-18
yaml/ocaml-yamle/tests/test_2cms_quick.ml
···11-open Yamle
22-33-let () =
44- let yaml = "this\n is\n invalid: x\n" in
55- Format.printf "YAML: %S@.@." yaml;
66- Format.printf "Parsing:@.";
77- try
88- let parser = Parser.of_string yaml in
99- let events = Parser.to_list parser in
1010- Format.printf "Events: %d (ERROR: should have failed)@." (List.length events);
1111- List.iter (fun e ->
1212- Format.printf " %a@." Event.pp e.Event.event
1313- ) events
1414- with
1515- | Yamle_error e ->
1616- Format.printf "Error (expected): %a@." Error.pp e
1717- | e ->
1818- Format.printf "Error: %s@." (Printexc.to_string e)
-25
yaml/ocaml-yamle/tests/test_3hfz.ml
···11-open Yamle
22-33-let () =
44- let yaml = "---\nkey: value\n... invalid\n" in
55- Printf.printf "YAML: %S\n" yaml;
66- Printf.printf "Byte 18: %C (space=%b, break=%b)\n"
77- yaml.[18]
88- (yaml.[18] = ' ' || yaml.[18] = '\t')
99- (yaml.[18] = '\n' || yaml.[18] = '\r');
1010- let scanner = Scanner.of_string yaml in
1111- Printf.printf "\nTokens:\n";
1212- try
1313- let rec loop () =
1414- match Scanner.next scanner with
1515- | None -> Printf.printf " (none)\n"
1616- | Some tok ->
1717- Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
1818- (Format.asprintf "%a" Token.pp tok.token);
1919- match tok.token with
2020- | Token.Stream_end -> ()
2121- | _ -> loop ()
2222- in
2323- loop ()
2424- with e ->
2525- Printf.printf "Error: %s\n" (Printexc.to_string e)
-29
yaml/ocaml-yamle/tests/test_565n_debug.ml
···11-open Yamle
22-33-let () =
44- let yaml = "generic: !!binary |
55- R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
66- OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
77- +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
88- AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=" in
99-1010- let scanner = Scanner.of_string yaml in
1111- let rec find_binary () =
1212- match Scanner.next scanner with
1313- | None -> None
1414- | Some { token; _ } ->
1515- match token with
1616- | Token.Scalar { style = Scalar_style.Literal; value; _ } -> Some value
1717- | _ -> find_binary ()
1818- in
1919- match find_binary () with
2020- | None -> Printf.printf "No literal scalar found\n"
2121- | Some value ->
2222- Printf.printf "Got: %S\n" value;
2323- Printf.printf "First char: %C (code %d)\n" value.[0] (Char.code value.[0]);
2424- if value.[0] = ' ' then
2525- Printf.printf "FAIL: starts with space\n"
2626- else if value.[0] = 'R' then
2727- Printf.printf "PASS: starts with R\n"
2828- else
2929- Printf.printf "FAIL: starts with unexpected char\n"
-17
yaml/ocaml-yamle/tests/test_5llu_quick.ml
···11-open Yamle
22-(* Test 5LLU: Block scalar with wrong indented line after spaces only *)
33-let () =
44- (* block scalar: >
55- ␣ (1 space, empty line)
66- ␣␣ (2 spaces, empty line)
77- ␣␣␣ (3 spaces, empty line)
88- invalid (1 space + content - ERROR!) *)
99- let yaml = "block scalar: >\n \n \n \n invalid\n" in
1010- Format.printf "YAML: %S@.@." yaml;
1111- try
1212- let parser = Parser.of_string yaml in
1313- let events = Parser.to_list parser in
1414- Format.printf "Events: %d (ERROR: should have failed)@." (List.length events)
1515- with
1616- | Yamle_error e ->
1717- Format.printf "Error (expected): %a@." Error.pp e
-11
yaml/ocaml-yamle/tests/test_5u3a.ml
···11-open Yamle
22-33-let () =
44- let yaml = "key: - a\n - b\n" in
55- Printf.printf "YAML: %S\n" yaml;
66- try
77- let parser = Parser.of_string yaml in
88- let events = Parser.to_list parser in
99- Printf.printf "Events: %d (should have errored)\n" (List.length events)
1010- with e ->
1111- Printf.printf "Error (expected): %s\n" (Printexc.to_string e)
-29
yaml/ocaml-yamle/tests/test_6vjk_debug.ml
···11-open Yamle
22-33-let () =
44- let yaml = ">
55- Sammy Sosa completed another
66- fine season with great stats.
77-88- 63 Home Runs
99- 0.288 Batting Average
1010-1111- What a year!" in
1212- Printf.printf "Input YAML:\n%s\n\n" yaml;
1313-1414- (* Create scanner and get scalar token *)
1515- let scanner = Scanner.of_string yaml in
1616- let rec find_scalar () =
1717- match Scanner.next scanner with
1818- | None -> failwith "No scalar found"
1919- | Some { token; _ } ->
2020- match token with
2121- | Token.Scalar (style, value) ->
2222- Printf.printf "Scalar value: %S\n" value;
2323- Printf.printf "Style: %s\n" (match style with
2424- | Scalar_style.Literal -> "Literal"
2525- | Scalar_style.Folded -> "Folded"
2626- | _ -> "Other")
2727- | _ -> find_scalar ()
2828- in
2929- find_scalar ()
-31
yaml/ocaml-yamle/tests/test_6vjk_only.ml
···11-open Yamle
22-33-let () =
44- let yaml = ">
55- Sammy Sosa completed another
66- fine season with great stats.
77-88- 63 Home Runs
99- 0.288 Batting Average
1010-1111- What a year!" in
1212-1313- let scanner = Scanner.of_string yaml in
1414- let rec find_scalar () =
1515- match Scanner.next scanner with
1616- | None -> None
1717- | Some { token; _ } ->
1818- match token with
1919- | Token.Scalar { style = _; value } -> Some value
2020- | _ -> find_scalar ()
2121- in
2222- match find_scalar () with
2323- | None -> Printf.printf "No scalar found\n"
2424- | Some value ->
2525- Printf.printf "Got: %S\n" value;
2626- 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
2727- Printf.printf "Expected: %S\n" expected;
2828- if value = expected then
2929- Printf.printf "PASS\n"
3030- else
3131- Printf.printf "FAIL\n"
···11-open Yamle
22-33-let test name yaml =
44- Printf.printf "\n=== %s ===\n" name;
55- let scanner = Scanner.of_string yaml in
66- try
77- while Scanner.next scanner <> None do () done;
88- Printf.printf "PASS\n"
99- with e ->
1010- Printf.printf "FAIL: %s\n" (Printexc.to_string e)
1111-1212-let () =
1313- (* All cases mentioned in the issue *)
1414- test "565N - Construct Binary" "generic: !!binary |\n R0lGODlh";
1515- test "A984 - Multiline Scalar" "a: b\n c\nd:\n e\n f";
1616- test "RZP5 - Trailing Comments" "- #lala\n seq2";
1717- test "XW4D - Trailing Comments variant" "- #comment\n value";
1818- test "Q9WF - Separation Spaces" "a: -\tb";
1919- test "V9D5 - Compact Block Mappings" "- a: b"
-167
yaml/ocaml-yamle/tests/test_anchor_tag_issues.ml
···11-(** Test cases for BU8L, SKE5, RZP5, XW4D *)
22-33-let print_token tok =
44- match tok.Yamle.Token.token with
55- | Yamle.Token.Stream_start _ -> "Stream_start"
66- | Yamle.Token.Stream_end -> "Stream_end"
77- | Yamle.Token.Document_start -> "Document_start"
88- | Yamle.Token.Document_end -> "Document_end"
99- | Yamle.Token.Block_sequence_start -> "Block_sequence_start"
1010- | Yamle.Token.Block_mapping_start -> "Block_mapping_start"
1111- | Yamle.Token.Block_end -> "Block_end"
1212- | Yamle.Token.Flow_sequence_start -> "Flow_sequence_start"
1313- | Yamle.Token.Flow_sequence_end -> "Flow_sequence_end"
1414- | Yamle.Token.Flow_mapping_start -> "Flow_mapping_start"
1515- | Yamle.Token.Flow_mapping_end -> "Flow_mapping_end"
1616- | Yamle.Token.Block_entry -> "Block_entry"
1717- | Yamle.Token.Flow_entry -> "Flow_entry"
1818- | Yamle.Token.Key -> "Key"
1919- | Yamle.Token.Value -> "Value"
2020- | Yamle.Token.Alias name -> "Alias(" ^ name ^ ")"
2121- | Yamle.Token.Anchor name -> "Anchor(" ^ name ^ ")"
2222- | Yamle.Token.Tag { handle; suffix } -> "Tag(" ^ handle ^ suffix ^ ")"
2323- | Yamle.Token.Scalar { value; _ } -> "Scalar(" ^ String.sub value 0 (min 20 (String.length value)) ^ ")"
2424- | Yamle.Token.Version_directive _ -> "Version_directive"
2525- | Yamle.Token.Tag_directive _ -> "Tag_directive"
2626-2727-let test_bu8l () =
2828- print_endline "Testing BU8L: Node Anchor and Tag on Separate Lines";
2929- let yaml = {|key: &anchor
3030- !!map
3131- a: b|} in
3232- try
3333- let scanner = Yamle.Scanner.of_string yaml in
3434- let rec print_tokens n =
3535- if n > 30 then (print_endline " ... (stopped at 30 tokens)"; ())
3636- else
3737- try
3838- match Yamle.Scanner.peek scanner with
3939- | Some { token = Stream_end; _ } as tok ->
4040- Printf.printf " %s\n" (print_token (Option.get tok));
4141- ignore (Yamle.Scanner.next scanner);
4242- ()
4343- | Some tok ->
4444- Printf.printf " %s\n" (print_token tok);
4545- ignore (Yamle.Scanner.next scanner);
4646- print_tokens (n + 1)
4747- | None -> print_endline " (no more tokens)"
4848- with
4949- | Yamle.Error.Yamle_error e ->
5050- Printf.printf " ERROR during scan: %s\n" (Yamle.Error.to_string e);
5151- raise (Yamle.Error.Yamle_error e)
5252- in
5353- print_tokens 0;
5454- print_endline "BU8L: Scanner SUCCESS\n"
5555- with
5656- | Yamle.Error.Yamle_error e ->
5757- Printf.printf "BU8L: FAILED with %s\n\n" (Yamle.Error.to_string e)
5858- | e ->
5959- Printf.printf "BU8L: FAILED with %s\n\n" (Printexc.to_string e)
6060-6161-let test_ske5 () =
6262- print_endline "Testing SKE5: Anchor before zero indented sequence";
6363- let yaml = {|---
6464-seq:
6565- &anchor
6666-- a
6767-- b|} in
6868- try
6969- let scanner = Yamle.Scanner.of_string yaml in
7070- let rec count_tokens n =
7171- match Yamle.Scanner.peek scanner with
7272- | Some { token = Stream_end; _ } ->
7373- ignore (Yamle.Scanner.next scanner);
7474- n
7575- | Some _ ->
7676- ignore (Yamle.Scanner.next scanner);
7777- count_tokens (n + 1)
7878- | None -> n
7979- in
8080- let count = count_tokens 0 in
8181- Printf.printf "SKE5: SUCCESS (tokens: %d)\n\n" count
8282- with
8383- | Yamle.Error.Yamle_error e ->
8484- Printf.printf "SKE5: FAILED with %s\n\n" (Yamle.Error.to_string e)
8585- | e ->
8686- Printf.printf "SKE5: FAILED with %s\n\n" (Printexc.to_string e)
8787-8888-let test_rzp5 () =
8989- print_endline "Testing RZP5: Various Trailing Comments [1.3]";
9090- let yaml = {|a: "double
9191- quotes" # lala
9292-b: plain
9393- value # lala
9494-c : #lala
9595- d
9696-? # lala
9797- - seq1
9898-: # lala
9999- - #lala
100100- seq2
101101-e: &node # lala
102102- - x: y
103103-block: > # lala
104104- abcde|} in
105105- try
106106- let scanner = Yamle.Scanner.of_string yaml in
107107- let rec count_tokens n =
108108- match Yamle.Scanner.peek scanner with
109109- | Some { token = Stream_end; _ } ->
110110- ignore (Yamle.Scanner.next scanner);
111111- n
112112- | Some _ ->
113113- ignore (Yamle.Scanner.next scanner);
114114- count_tokens (n + 1)
115115- | None -> n
116116- in
117117- let count = count_tokens 0 in
118118- Printf.printf "RZP5: SUCCESS (tokens: %d)\n\n" count
119119- with
120120- | Yamle.Error.Yamle_error e ->
121121- Printf.printf "RZP5: FAILED with %s\n\n" (Yamle.Error.to_string e)
122122- | e ->
123123- Printf.printf "RZP5: FAILED with %s\n\n" (Printexc.to_string e)
124124-125125-let test_xw4d () =
126126- print_endline "Testing XW4D: Various Trailing Comments";
127127- let yaml = {|a: "double
128128- quotes" # lala
129129-b: plain
130130- value # lala
131131-c : #lala
132132- d
133133-? # lala
134134- - seq1
135135-: # lala
136136- - #lala
137137- seq2
138138-e:
139139- &node # lala
140140- - x: y
141141-block: > # lala
142142- abcde|} in
143143- try
144144- let scanner = Yamle.Scanner.of_string yaml in
145145- let rec count_tokens n =
146146- match Yamle.Scanner.peek scanner with
147147- | Some { token = Stream_end; _ } ->
148148- ignore (Yamle.Scanner.next scanner);
149149- n
150150- | Some _ ->
151151- ignore (Yamle.Scanner.next scanner);
152152- count_tokens (n + 1)
153153- | None -> n
154154- in
155155- let count = count_tokens 0 in
156156- Printf.printf "XW4D: SUCCESS (tokens: %d)\n\n" count
157157- with
158158- | Yamle.Error.Yamle_error e ->
159159- Printf.printf "XW4D: FAILED with %s\n\n" (Yamle.Error.to_string e)
160160- | e ->
161161- Printf.printf "XW4D: FAILED with %s\n\n" (Printexc.to_string e)
162162-163163-let () =
164164- test_bu8l ();
165165- test_ske5 ();
166166- test_rzp5 ();
167167- test_xw4d ()
-11
yaml/ocaml-yamle/tests/test_basic_yaml.ml
···11-open Yamle
22-33-let () =
44- let yaml = "key: value\n" in
55- Printf.printf "YAML: %S\n" yaml;
66- try
77- let parser = Parser.of_string yaml in
88- let events = Parser.to_list parser in
99- Printf.printf "Events: %d\n" (List.length events)
1010- with e ->
1111- Printf.printf "Error: %s\n" (Printexc.to_string e)
-18
yaml/ocaml-yamle/tests/test_bs4k.ml
···11-open Yamle
22-33-let () =
44- let yaml = "word1 # comment\nword2\n" in
55- Format.printf "YAML: %S@.@." yaml;
66- Format.printf "Parsing:@.";
77- try
88- let parser = Parser.of_string yaml in
99- let events = Parser.to_list parser in
1010- Format.printf "Events: %d (ERROR: should have failed)@." (List.length events);
1111- List.iter (fun e ->
1212- Format.printf " %a@." Event.pp e.Event.event
1313- ) events
1414- with
1515- | Yamle_error e ->
1616- Format.printf "Error (expected): %a@." Error.pp e
1717- | e ->
1818- Format.printf "Error: %s@." (Printexc.to_string e)
-21
yaml/ocaml-yamle/tests/test_debug_stale.ml
···11-open Yamle
22-33-(* Patch Scanner to add debug output *)
44-let test yaml =
55- Printf.printf "YAML:\n%s\n\n" yaml;
66- let scanner = Scanner.of_string yaml in
77- try
88- let rec loop () =
99- match Scanner.next scanner with
1010- | None -> Printf.printf "Done\n"
1111- | Some tok ->
1212- Printf.printf "%s\n" (Format.asprintf "%a" Token.pp_spanned tok);
1313- loop ()
1414- in
1515- loop ()
1616- with e ->
1717- Printf.printf "Error: %s\n" (Printexc.to_string e)
1818-1919-let () =
2020- (* This should work: simple key, value on next line *)
2121- test "d:\n e"
-21
yaml/ocaml-yamle/tests/test_dk4h.ml
···11-open Yamle
22-33-let () =
44- let yaml = "---\n[ key\n : value ]\n" in
55- Printf.printf "YAML: %S\n" yaml;
66- let scanner = Scanner.of_string yaml in
77- Printf.printf "\nTokens:\n";
88- try
99- let rec loop () =
1010- match Scanner.next scanner with
1111- | None -> Printf.printf " (none)\n"
1212- | Some tok ->
1313- Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
1414- (Format.asprintf "%a" Token.pp tok.token);
1515- match tok.token with
1616- | Token.Stream_end -> ()
1717- | _ -> loop ()
1818- in
1919- loop ()
2020- with e ->
2121- Printf.printf "Error: %s\n" (Printexc.to_string e)
-9
yaml/ocaml-yamle/tests/test_error_type.ml
···11-open Yamle
22-33-let () =
44- let yaml = "d:\n e" in
55- let scanner = Scanner.of_string yaml in
66- try
77- while Scanner.next scanner <> None do () done
88- with Error.Yamle_error err ->
99- Printf.printf "Error: %s\n" (Error.to_string err)
-6
yaml/ocaml-yamle/tests/test_indent_debug.ml
···11-open Yamle
22-33-let () =
44- let yaml = "d:\n e" in
55- let scanner = Scanner.of_string yaml in
66- ignore (Scanner.to_list scanner)
-18
yaml/ocaml-yamle/tests/test_ks4u.ml
···11-open Yamle
22-33-let () =
44- let yaml = "---\n[\nsequence item\n]\ninvalid item\n" in
55- Format.printf "YAML: %S@.@." yaml;
66- Format.printf "Parsing:@.";
77- try
88- let parser = Parser.of_string yaml in
99- let events = Parser.to_list parser in
1010- Format.printf "Events: %d (ERROR: should have failed)@." (List.length events);
1111- List.iter (fun e ->
1212- Format.printf " %a@." Event.pp e.Event.event
1313- ) events
1414- with
1515- | Yamle_error e ->
1616- Format.printf "Error (expected): %a@." Error.pp e
1717- | e ->
1818- Format.printf "Error: %s@." (Printexc.to_string e)
-21
yaml/ocaml-yamle/tests/test_lhl4.ml
···11-open Yamle
22-33-let () =
44- let yaml = "---\n!invalid{}tag scalar\n" in
55- Printf.printf "YAML: %S\n" yaml;
66- let scanner = Scanner.of_string yaml in
77- Printf.printf "\nTokens:\n";
88- try
99- let rec loop () =
1010- match Scanner.next scanner with
1111- | None -> Printf.printf " (none)\n"
1212- | Some tok ->
1313- Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
1414- (Format.asprintf "%a" Token.pp tok.token);
1515- match tok.token with
1616- | Token.Stream_end -> ()
1717- | _ -> loop ()
1818- in
1919- loop ()
2020- with e ->
2121- Printf.printf "Error: %s\n" (Printexc.to_string e)
-9
yaml/ocaml-yamle/tests/test_loader_debug.ml
···11-module TL = Test_suite_lib.Test_suite_loader
22-33-let () =
44- Printf.printf "Testing test loader...\n";
55- try
66- let tests = TL.load_file "../yaml-test-suite/src/229Q.yaml" in
77- Printf.printf "Loaded %d tests\n" (List.length tests)
88- with e ->
99- Printf.printf "Error loading: %s\n" (Printexc.to_string e)
-11
yaml/ocaml-yamle/tests/test_mus6_debug.ml
···11-open Yamle
22-let () =
33- let yaml = "%YAML 1.1#...\n---\n" in
44- Format.printf "YAML: %S@.@." yaml;
55- try
66- let parser = Parser.of_string yaml in
77- let events = Parser.to_list parser in
88- Format.printf "Events: %d (ERROR: should have failed)@." (List.length events)
99- with
1010- | Yamle_error e ->
1111- Format.printf "Error (expected): %a@." Error.pp e
-47
yaml/ocaml-yamle/tests/test_nat4_a.ml
···11-(* Test NAT4 case a specifically *)
22-open Yamle
33-44-let test_case desc yaml expected =
55- Printf.printf "\n=== %s ===\n" desc;
66- Printf.printf "Input: %s\n" (String.escaped yaml);
77- try
88- let parser = Parser.of_string yaml in
99- let events = Parser.to_list parser in
1010- List.iter (fun (e : Event.spanned) ->
1111- match e.event with
1212- | Event.Scalar { value; style; _ } ->
1313- Printf.printf "Output: %s (len=%d, style=%s)\n"
1414- (String.escaped value)
1515- (String.length value)
1616- (match style with
1717- | Scalar_style.Single_quoted -> "single"
1818- | Scalar_style.Double_quoted -> "double"
1919- | _ -> "other");
2020- Printf.printf "Expected: %s (len=%d)\n" (String.escaped expected) (String.length expected);
2121- if value = expected then
2222- Printf.printf "✓ PASS\n"
2323- else
2424- Printf.printf "✗ FAIL\n"
2525- | _ -> ()
2626- ) events
2727- with e ->
2828- Printf.printf "Error: %s\n" (Printexc.to_string e)
2929-3030-let () =
3131- (* NAT4 case a: newline then spaces *)
3232- test_case "a" "a: '\n '" " ";
3333-3434- (* NAT4 case b: spaces, newline, spaces *)
3535- test_case "b" "a: ' \n '" " ";
3636-3737- (* NAT4 case e: newline, empty line, spaces *)
3838- test_case "e" "a: '\n\n '" "\n";
3939-4040- (* NAT4 case g: newline, two empty lines, spaces *)
4141- test_case "g" "a: '\n\n\n '" "\n\n";
4242-4343- (* Simple case: text on both lines *)
4444- test_case "simple" "a: 'foo\nbar'" "foo bar";
4545-4646- (* Case with empty line between text *)
4747- test_case "empty_between" "a: 'foo\n\nbar'" "foo\nbar";
-31
yaml/ocaml-yamle/tests/test_remaining.ml
···11-open Yamle
22-33-let test yaml name =
44- Printf.printf "\n=== %s ===\n" name;
55- Printf.printf "YAML: %S\n" yaml;
66- try
77- let parser = Parser.of_string yaml in
88- let _ = Parser.to_list parser in
99- Printf.printf "SUCCESS\n"
1010- with Error.Yamle_error _ ->
1111- Printf.printf "ERROR\n"
1212-1313-let () =
1414- (* CT4Q: Single Pair Explicit Entry *)
1515- test {|[
1616-? foo
1717- bar : baz
1818-]|} "CT4Q";
1919-2020- (* DFF7: Flow Mapping Entries *)
2121- test {|{
2222-? explicit: entry,
2323-implicit: entry,
2424-?
2525-}|} "DFF7";
2626-2727- (* FRK4: Completely Empty Flow Nodes *)
2828- test {|{
2929- ? foo :,
3030- : bar,
3131-}|} "FRK4";
-30
yaml/ocaml-yamle/tests/test_simple_key_debug.ml
···11-open Yamle
22-33-let test_case name yaml =
44- Printf.printf "\n=== Testing %s ===\n" name;
55- Printf.printf "YAML:\n%s\n\n" yaml;
66- let scanner = Scanner.of_string yaml in
77- Printf.printf "Tokens:\n";
88- let rec print_tokens () =
99- match Scanner.next scanner with
1010- | None -> Printf.printf "Done\n"
1111- | Some tok ->
1212- Printf.printf " %s\n" (Format.asprintf "%a" Token.pp_spanned tok);
1313- print_tokens ()
1414- in
1515- try
1616- print_tokens ()
1717- with e ->
1818- Printf.printf "Error: %s\n" (Printexc.to_string e)
1919-2020-let () =
2121- (* Test A984 - Multiline Scalar in Mapping *)
2222- test_case "A984" "a: b\n c\nd:\n e\n f";
2323-2424- (* Test RZP5 - Trailing Comments *)
2525- test_case "RZP5" "- #lala\n seq2";
2626-2727- (* Simplified versions *)
2828- test_case "Simple multiline" "a: b\n c";
2929- test_case "Simple block entry with comment" "- # comment\n value";
3030- test_case "After block scalar" "a: |\n text\nb: c"
-21
yaml/ocaml-yamle/tests/test_simple_single.ml
···11-(* Simple test of single-quoted scalar *)
22-open Yamle
33-44-let () =
55- let yaml = "'foo\n\nbar'" in
66- Printf.printf "Input: %s\n" (String.escaped yaml);
77-88- let scanner = Scanner.of_string yaml in
99- Scanner.iter (fun tok ->
1010- match tok.Token.token with
1111- | Token.Scalar { value; style; _ } ->
1212- Printf.printf "Scalar: %s (len=%d)\n" (String.escaped value) (String.length value);
1313- Printf.printf "Style: %s\n" (match style with
1414- | Scalar_style.Single_quoted -> "single"
1515- | _ -> "other");
1616- (* Print each character *)
1717- for i = 0 to String.length value - 1 do
1818- Printf.printf " [%d] = %C (code=%d)\n" i value.[i] (Char.code value.[i])
1919- done
2020- | _ -> ()
2121- ) scanner
···66 name : string;
77 yaml : string;
88 tree : string option;
99+ json : string option; (* If present, indicates test should parse successfully *)
910 fail : bool;
1011}
1112···113114 | None -> ""
114115 in
115116 let tree = extract_mapping_value events "tree" in
117117+ let json = extract_mapping_value events "json" in
116118 let fail = match extract_mapping_value events "fail" with
117119 | Some "true" -> true
118120 | _ -> Option.is_some (extract_mapping_value events "error")
119121 in
120120- { id; name; yaml; tree; fail }
122122+ { id; name; yaml; tree; json; fail }
121123122124(* Load tests from a single YAML file *)
123125let load_file path =
-21
yaml/ocaml-yamle/tests/test_sy6v.ml
···11-open Yamle
22-33-let () =
44- let yaml = "&anchor - sequence entry\n" in
55- Printf.printf "YAML: %S\n" yaml;
66- let scanner = Scanner.of_string yaml in
77- Printf.printf "\nTokens:\n";
88- try
99- let rec loop () =
1010- match Scanner.next scanner with
1111- | None -> Printf.printf " (none)\n"
1212- | Some tok ->
1313- Printf.printf " %d:%d %s\n" tok.span.start.line tok.span.start.column
1414- (Format.asprintf "%a" Token.pp tok.token);
1515- match tok.token with
1616- | Token.Stream_end -> ()
1717- | _ -> loop ()
1818- in
1919- loop ()
2020- with e ->
2121- Printf.printf "Error: %s\n" (Printexc.to_string e)
-24
yaml/ocaml-yamle/tests/test_tokens2.ml
···11-open Yamle
22-33-let yaml = {|'implicit block key' : [
44- 'implicit flow key' : value,
55- ]|}
66-77-let () =
88- let scanner = Scanner.of_string yaml in
99- let rec print_all n =
1010- match Scanner.next scanner with
1111- | None -> ()
1212- | Some tok ->
1313- Printf.printf "%2d. " n;
1414- (match tok.Token.token with
1515- | Token.Flow_sequence_start -> Printf.printf "Flow_sequence_start"
1616- | Token.Flow_sequence_end -> Printf.printf "Flow_sequence_end"
1717- | Token.Flow_entry -> Printf.printf "Flow_entry"
1818- | Token.Value -> Printf.printf "Value"
1919- | Token.Scalar {value; _} -> Printf.printf "Scalar(%S)" value
2020- | _ -> Printf.printf "Other");
2121- Printf.printf " at %d:%d\n" tok.span.start.line tok.span.start.column;
2222- print_all (n + 1)
2323- in
2424- print_all 0
-19
yaml/ocaml-yamle/tests/test_trace_a984.ml
···11-open Yamle
22-33-let () =
44- (* Minimal A984 reproduction *)
55- let yaml = "d:\n e" in
66- Printf.printf "Testing minimal A984:\n%s\n\n" yaml;
77- let scanner = Scanner.of_string yaml in
88- Printf.printf "Tokens:\n";
99- let rec print_tokens () =
1010- match Scanner.next scanner with
1111- | None -> Printf.printf "Done\n"
1212- | Some tok ->
1313- Printf.printf " %s\n" (Format.asprintf "%a" Token.pp_spanned tok);
1414- print_tokens ()
1515- in
1616- try
1717- print_tokens ()
1818- with e ->
1919- Printf.printf "Error: %s\n" (Printexc.to_string e)
-41
yaml/ocaml-yamle/tests/test_y79y.ml
···11-(* Debug Y79Y test cases *)
22-open Yamle
33-44-let () =
55- (* Test case 1: fail=true - tabs at wrong indentation in block scalar *)
66- let yaml1 = "foo: |\n \t\nbar: 1" in
77- Printf.printf "=== Test 1 (should fail) ===\n";
88- Printf.printf "Input: %S\n" yaml1;
99- Printf.printf "Visual:\n";
1010- String.iter (fun c ->
1111- if c = '\t' then Printf.printf "<TAB>"
1212- else if c = '\n' then Printf.printf "<NL>\n"
1313- else Printf.printf "%c" c
1414- ) yaml1;
1515- Printf.printf "\n";
1616- (try
1717- let parser = Parser.of_string yaml1 in
1818- let events = Parser.to_list parser in
1919- Printf.printf "Events: %d\n" (List.length events);
2020- Printf.printf "ERROR: Should have failed but didn't!\n\n"
2121- with e ->
2222- Printf.printf "Failed as expected: %s\n\n" (Printexc.to_string e));
2323-2424- (* Test case 2: should succeed - tab with proper indentation in block scalar *)
2525- let yaml2 = "foo: |\n \t\nbar: 1" in
2626- Printf.printf "=== Test 2 (should succeed) ===\n";
2727- Printf.printf "Input: %S\n" yaml2;
2828- Printf.printf "Visual:\n";
2929- String.iter (fun c ->
3030- if c = '\t' then Printf.printf "<TAB>"
3131- else if c = '\n' then Printf.printf "<NL>\n"
3232- else Printf.printf "%c" c
3333- ) yaml2;
3434- Printf.printf "\n";
3535- (try
3636- let parser = Parser.of_string yaml2 in
3737- let events = Parser.to_list parser in
3838- Printf.printf "Events: %d\n" (List.length events);
3939- Printf.printf "\n"
4040- with e ->
4141- Printf.printf "ERROR: Failed but should succeed: %s\n\n" (Printexc.to_string e))
-68
yaml/ocaml-yamle/tests/test_y79y_all.ml
···11-(* Test all Y79Y cases *)
22-33-let test_case name yaml should_fail =
44- Printf.printf "=== %s ===\n" name;
55- try
66- let scanner = Yamle.Scanner.of_string yaml in
77- let _tokens = Yamle.Scanner.to_list scanner in
88- if should_fail then begin
99- Printf.printf "FAIL: Expected error but parsing succeeded\n";
1010- false
1111- end else begin
1212- Printf.printf "PASS: Parsing succeeded as expected\n";
1313- true
1414- end
1515- with e ->
1616- if should_fail then begin
1717- Printf.printf "PASS: Failed as expected (%s)\n" (Printexc.to_string e);
1818- true
1919- end else begin
2020- Printf.printf "FAIL: Unexpected error (%s)\n" (Printexc.to_string e);
2121- false
2222- end
2323-2424-let () =
2525- let results = ref [] in
2626-2727- (* Y79Y/00: Tab at start - should FAIL *)
2828- results := test_case "Y79Y/00" "foo: |\n\t\nbar: 1" true :: !results;
2929-3030- (* Y79Y/01: Tab after 1 space - should PASS *)
3131- results := test_case "Y79Y/01" "foo: |\n \t\nbar: 1" false :: !results;
3232-3333- (* Y79Y/02: Tab in flow sequence after newline - should PASS *)
3434- results := test_case "Y79Y/02" "- [\n\t\n foo\n ]" false :: !results;
3535-3636- (* Y79Y/03: Tab immediately after flow start and content - should FAIL *)
3737- results := test_case "Y79Y/03" "- [\n\tfoo,\n foo\n ]" true :: !results;
3838-3939- (* Y79Y/04: Tab after dash at root level - should FAIL *)
4040- results := test_case "Y79Y/04" "-\t-" true :: !results;
4141-4242- (* Y79Y/05: Tab after dash with space - should FAIL *)
4343- results := test_case "Y79Y/05" "- \t-" true :: !results;
4444-4545- (* Y79Y/06: Tab after ? at root level - should FAIL *)
4646- results := test_case "Y79Y/06" "?\t-" true :: !results;
4747-4848- (* Y79Y/07: Tab after : in explicit mapping - should FAIL *)
4949- results := test_case "Y79Y/07" "? -\n:\t-" true :: !results;
5050-5151- (* Y79Y/08: Tab after ? before key - should FAIL *)
5252- results := test_case "Y79Y/08" "?\tkey:" true :: !results;
5353-5454- (* Y79Y/09: Tab after : in explicit mapping - should FAIL *)
5555- results := test_case "Y79Y/09" "? key:\n:\tkey:" true :: !results;
5656-5757- (* Y79Y/10: Tab before number (content) - should PASS *)
5858- results := test_case "Y79Y/10" "-\t-1" false :: !results;
5959-6060- Printf.printf "\n=== Summary ===\n";
6161- let passed = List.filter (fun x -> x) !results |> List.length in
6262- let total = List.length !results in
6363- Printf.printf "%d/%d tests passed\n" passed total;
6464- if passed = total then
6565- Printf.printf "All tests PASSED!\n"
6666- else
6767- Printf.printf "Some tests FAILED\n";
6868- exit (if passed = total then 0 else 1)
-13
yaml/ocaml-yamle/tests/test_y79y_simple.ml
···11-(* Simple Y79Y test *)
22-33-let () =
44- (* Test case 1: should fail - tab at wrong indentation *)
55- let yaml1 = "foo: |\n \t\nbar: 1" in
66- Printf.printf "=== Test 1 (should fail) ===\n";
77- Printf.printf "Testing: %S\n" yaml1;
88- (try
99- let scanner = Yamle.Scanner.of_string yaml1 in
1010- let _tokens = Yamle.Scanner.to_list scanner in
1111- Printf.printf "ERROR: Scanning succeeded but should have failed!\n"
1212- with e ->
1313- Printf.printf "OK: Failed as expected: %s\n" (Printexc.to_string e))
-44
yaml/ocaml-yamle/tests/test_y79y_trace.ml
···11-(* Trace Y79Y test *)
22-33-let test_case yaml desc should_fail expected_scalars =
44- Printf.printf "=== %s ===\n" desc;
55- Printf.printf "Testing: %S\n" yaml;
66- try
77- let scanner = Yamle.Scanner.of_string yaml in
88- let tokens = Yamle.Scanner.to_list scanner in
99- if should_fail then
1010- Printf.printf "ERROR: Expected to fail but got %d tokens\n" (List.length tokens)
1111- else begin
1212- Printf.printf "OK: Got %d tokens\n" (List.length tokens);
1313- let scalars = ref [] in
1414- List.iter (fun (t : Yamle.Token.spanned) ->
1515- match t.token with
1616- | Yamle.Token.Scalar { value; _ } ->
1717- scalars := value :: !scalars;
1818- Printf.printf " Scalar: %S\n" value
1919- | _ -> ()
2020- ) tokens;
2121- let scalars = List.rev !scalars in
2222- if scalars <> expected_scalars then begin
2323- Printf.printf "ERROR: Expected scalars %s but got %s\n"
2424- (String.concat ", " (List.map (Printf.sprintf "%S") expected_scalars))
2525- (String.concat ", " (List.map (Printf.sprintf "%S") scalars))
2626- end
2727- end
2828- with e ->
2929- if should_fail then
3030- Printf.printf "OK: Failed as expected: %s\n" (Printexc.to_string e)
3131- else
3232- Printf.printf "ERROR: Unexpected failure: %s\n" (Printexc.to_string e)
3333-3434-let () =
3535- (* Test case 0 (Y79Y): should fail - tab at start of content *)
3636- let yaml0 = "foo: |\n\t\nbar: 1" in
3737- test_case yaml0 "Y79Y/00: tab at start (no spaces)" true [];
3838- Printf.printf "\n";
3939-4040- (* Test case 1 (Y79Y/01): should succeed - tab after 1 space indent *)
4141- (* Expected: foo="\t\n", bar="1" *)
4242- let yaml1 = "foo: |\n \t\nbar: 1" in
4343- test_case yaml1 "Y79Y/01: tab after 1 space" false ["foo"; "\t\n"; "bar"; "1"];
4444- Printf.printf "\n"