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

more

Changed files
+94 -198
yaml
ocaml-yamle
+1 -2
yaml/ocaml-yamle/tests/run_all_tests.ml
···
] 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 results = List.map run_test all_tests in
···
] in
Arg.parse args (fun _ -> ()) "Usage: run_all_tests [--html <file>] [--show-skipped]";
+
let all_tests = TL.load_directory test_suite_path in
Printf.printf "Total tests loaded: %d\n%!" (List.length all_tests);
let results = List.map run_test all_tests in
+79 -160
yaml/ocaml-yamle/tests/test_suite_lib/test_suite_loader.ml
···
-
(* Load yaml-test-suite test cases from YAML format *)
-
open Yamle
type test_case = {
id : string;
name : string;
yaml : string;
tree : string option;
-
json : string option; (* If present, indicates test should parse successfully *)
fail : bool;
}
let read_file path =
-
let ic = open_in path in
-
let n = in_channel_length ic in
-
let s = really_input_string ic n in
-
close_in ic;
-
s
-
(* Convert YAML test suite visual representations to actual characters *)
-
let convert_test_yaml yaml =
-
let result = Buffer.create (String.length yaml) in
-
let len = String.length yaml in
-
let rec process i =
-
if i >= len then ()
-
else
-
(* Check for multi-character sequences - must check longest first *)
-
(* ————» = em-dash em-dash em-dash em-dash guillemet (4 spaces = tab expanded) *)
-
if i + 14 <= len && String.sub yaml i 14 = "\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xc2\xbb" then begin
-
Buffer.add_char result '\t';
-
process (i + 14)
-
end
-
(* ———» = em-dash em-dash em-dash guillemet *)
-
else if i + 11 <= len && String.sub yaml i 11 = "\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xc2\xbb" then begin
-
Buffer.add_char result '\t';
-
process (i + 11)
-
end
-
(* ——» = em-dash em-dash guillemet *)
-
else if i + 8 <= len && String.sub yaml i 8 = "\xe2\x80\x94\xe2\x80\x94\xc2\xbb" then begin
-
Buffer.add_char result '\t';
-
process (i + 8)
-
end
-
(* —» = em-dash guillemet *)
-
else if i + 5 <= len && String.sub yaml i 5 = "\xe2\x80\x94\xc2\xbb" then begin
-
Buffer.add_char result '\t';
-
process (i + 5)
-
end
-
(* » = guillemet alone *)
-
else if i + 2 <= len && String.sub yaml i 2 = "\xc2\xbb" then begin
-
Buffer.add_char result '\t';
-
process (i + 2)
-
end
-
(* ␣ = open box for trailing space *)
-
else if i + 3 <= len && String.sub yaml i 3 = "\xe2\x90\xa3" then begin
-
Buffer.add_char result ' ';
-
process (i + 3)
-
end
-
(* ← = leftwards arrow for carriage return *)
-
else if i + 3 <= len && String.sub yaml i 3 = "\xe2\x86\x90" then begin
-
Buffer.add_char result '\r';
-
process (i + 3)
-
end
-
(* ⇔ = left-right double arrow for BOM *)
-
else if i + 3 <= len && String.sub yaml i 3 = "\xe2\x87\x94" then begin
-
Buffer.add_string result "\xEF\xBB\xBF";
-
process (i + 3)
-
end
-
(* ↵ = up-down arrow for explicit newline.
-
This represents a newline in the output AND replaces the following actual newline
-
(since each ↵ is on its own line in the test file's yaml field). *)
-
else if i + 3 <= len && String.sub yaml i 3 = "\xe2\x86\xb5" then begin
-
Buffer.add_char result '\n';
-
(* Skip the following newline if present (it's part of the test file structure, not content) *)
-
let next_i = i + 3 in
-
if next_i < len && yaml.[next_i] = '\n' then
-
process (next_i + 1)
-
else
-
process next_i
-
end
-
(* ∎ = end-of-proof symbol for empty stream *)
-
else if i + 3 <= len && String.sub yaml i 3 = "\xe2\x88\x8e" then begin
-
(* Skip this - it represents an empty file, so we add nothing *)
-
process (i + 3)
-
end
-
else begin
-
Buffer.add_char result yaml.[i];
-
process (i + 1)
-
end
-
in
-
process 0;
-
Buffer.contents result
-
(* Extract a field value from parsed YAML events *)
-
let extract_mapping_value events key =
-
let rec find_key = function
-
| [] -> None
-
| { Event.event = Event.Scalar { value; _ }; _ } :: rest when value = key ->
-
(* Found the key, now get the value *)
-
(match rest with
-
| { Event.event = Event.Scalar { value; _ }; _ } :: _ -> Some value
-
| _ -> None)
-
| _ :: rest -> find_key rest
-
in
-
find_key events
-
(* Parse a single test case from a mapping *)
-
let parse_test_case id events =
-
let name = match extract_mapping_value events "name" with
-
| Some n -> n
-
| None -> id
-
in
-
let yaml = match extract_mapping_value events "yaml" with
-
| Some y -> convert_test_yaml y
-
| 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; json; fail }
-
(* Load tests from a single YAML file *)
-
let load_file path =
-
let id = Filename.chop_extension (Filename.basename path) in
-
try
-
let content = read_file path in
-
let parser = Parser.of_string content in
-
let events = Parser.to_list parser in
-
(* File contains a sequence of test cases *)
-
let tests = ref [] in
-
let current_events = ref [] in
-
let in_mapping = ref false in
-
let depth = ref 0 in
-
let test_index = ref 0 in
-
List.iter (fun (e : Event.spanned) ->
-
match e.event with
-
| Event.Mapping_start _ when !depth = 1 ->
-
in_mapping := true;
-
current_events := [e];
-
incr depth
-
| Event.Mapping_end when !depth = 2 ->
-
current_events := e :: !current_events;
-
let test_id = if !test_index = 0 then id else Printf.sprintf "%s/%02d" id !test_index in
-
let test = parse_test_case test_id (List.rev !current_events) in
-
if test.yaml <> "" then tests := test :: !tests;
-
in_mapping := false;
-
current_events := [];
-
incr test_index;
-
decr depth
-
| _ when !in_mapping ->
-
current_events := e :: !current_events;
-
(match e.event with
-
| Event.Mapping_start _ | Event.Sequence_start _ -> incr depth
-
| Event.Mapping_end | Event.Sequence_end -> decr depth
-
| _ -> ())
-
| Event.Sequence_start _ when !depth = 0 -> depth := 1
-
| Event.Sequence_end when !depth = 1 -> depth := 0
-
| _ -> ()
-
) events;
-
List.rev !tests
-
with _ -> []
-
let load_directory src_path =
-
let entries = Sys.readdir src_path in
-
let tests = ref [] in
-
Array.iter (fun entry ->
-
if Filename.check_suffix entry ".yaml" then begin
-
let path = Filename.concat src_path entry in
-
let file_tests = load_file path in
-
tests := file_tests @ !tests
-
end
-
) entries;
-
List.sort (fun a b -> String.compare a.id b.id) !tests
···
+
(* Load yaml-test-suite test cases from data branch format *)
type test_case = {
id : string;
name : string;
yaml : string;
tree : string option;
+
json : string option;
fail : bool;
}
let read_file path =
+
try
+
let ic = open_in path in
+
let n = in_channel_length ic in
+
let s = really_input_string ic n in
+
close_in ic;
+
Some s
+
with _ -> None
+
let read_file_required path =
+
match read_file path with
+
| Some s -> s
+
| None -> ""
+
let file_exists path =
+
Sys.file_exists path
+
let is_directory path =
+
Sys.file_exists path && Sys.is_directory path
+
(* Load a single test from a directory *)
+
let load_test_dir base_id dir_path =
+
let name_file = Filename.concat dir_path "===" in
+
let yaml_file = Filename.concat dir_path "in.yaml" in
+
let tree_file = Filename.concat dir_path "test.event" in
+
let json_file = Filename.concat dir_path "in.json" in
+
let error_file = Filename.concat dir_path "error" in
+
(* Must have in.yaml to be a valid test *)
+
if not (file_exists yaml_file) then None
+
else
+
let name = match read_file name_file with
+
| Some s -> String.trim s
+
| None -> base_id
+
in
+
let yaml = read_file_required yaml_file in
+
let tree = read_file tree_file in
+
let json = read_file json_file in
+
let fail = file_exists error_file in
+
Some { id = base_id; name; yaml; tree; json; fail }
+
(* Load tests from a test ID directory (may have subdirectories for variants) *)
+
let load_test_id test_suite_path test_id =
+
let dir_path = Filename.concat test_suite_path test_id in
+
if not (is_directory dir_path) then []
+
else
+
(* Check if this directory has variant subdirectories (00, 01, etc.) *)
+
let entries = Sys.readdir dir_path in
+
let has_variants = Array.exists (fun e ->
+
let subdir = Filename.concat dir_path e in
+
is_directory subdir &&
+
String.length e >= 2 &&
+
e.[0] >= '0' && e.[0] <= '9'
+
) entries in
+
if has_variants then
+
(* Load each variant subdirectory *)
+
let variants = Array.to_list entries
+
|> List.filter (fun e ->
+
let subdir = Filename.concat dir_path e in
+
is_directory subdir && String.length e >= 2 && e.[0] >= '0' && e.[0] <= '9')
+
|> List.sort String.compare
+
in
+
List.filter_map (fun variant ->
+
let variant_path = Filename.concat dir_path variant in
+
let variant_id = Printf.sprintf "%s:%s" test_id variant in
+
load_test_dir variant_id variant_path
+
) variants
+
else
+
(* Single test in this directory *)
+
match load_test_dir test_id dir_path with
+
| Some t -> [t]
+
| None -> []
+
let load_directory test_suite_path =
+
if not (is_directory test_suite_path) then []
+
else
+
let entries = Sys.readdir test_suite_path in
+
let test_ids = Array.to_list entries
+
|> List.filter (fun e ->
+
is_directory (Filename.concat test_suite_path e) &&
+
String.length e >= 4 && (* Test IDs are 4 chars *)
+
e.[0] >= '0' && e.[0] <= 'Z') (* Start with alphanumeric *)
+
|> List.sort String.compare
+
in
+
List.concat_map (load_test_id test_suite_path) test_ids
+14 -36
yaml/ocaml-yamle/tests/test_suite_lib/tree_format.ml
···
let escape_string s =
let buf = Buffer.create (String.length s * 2) in
-
let len = String.length s in
-
(* Find the last non-space character to identify trailing spaces *)
-
let rec find_last_non_space i =
-
if i < 0 then -1
-
else if s.[i] <> ' ' then i
-
else find_last_non_space (i - 1)
-
in
-
let last_non_space = find_last_non_space (len - 1) in
-
-
String.iteri (fun i c ->
match c with
| '\n' -> Buffer.add_string buf "\\n"
| '\t' -> Buffer.add_string buf "\\t"
···
| '\x0c' -> Buffer.add_string buf "\\f"
| '\x1b' -> Buffer.add_string buf "\\e"
| '\xa0' -> Buffer.add_string buf "\\_"
-
| ' ' when i > last_non_space ->
-
(* Trailing space - show with open box character *)
-
Buffer.add_string buf "\xe2\x90\xa3"
| c -> Buffer.add_char buf c
) s;
Buffer.contents buf
···
| Scalar_style.Folded -> '>'
| Scalar_style.Any -> ':'
-
let format_event depth { Event.event; span = _span } =
-
let indent = String.make depth ' ' in
match event with
| Event.Stream_start _ -> "+STR"
| Event.Stream_end -> "-STR"
| Event.Document_start { implicit; _ } ->
-
if implicit then Printf.sprintf "%s+DOC" indent
-
else Printf.sprintf "%s+DOC ---" indent
| Event.Document_end { implicit } ->
-
if implicit then Printf.sprintf "%s-DOC" indent
-
else Printf.sprintf "%s-DOC ..." indent
| Event.Mapping_start { anchor; tag; style; _ } ->
let anchor_str = match anchor with Some a -> " &" ^ a | None -> "" in
let tag_str = match tag with Some t -> " <" ^ t ^ ">" | None -> "" in
let flow_str = match style with Layout_style.Flow -> " {}" | _ -> "" in
-
Printf.sprintf "%s+MAP%s%s%s" indent flow_str anchor_str tag_str
-
| Event.Mapping_end -> Printf.sprintf "%s-MAP" indent
| Event.Sequence_start { anchor; tag; style; _ } ->
let anchor_str = match anchor with Some a -> " &" ^ a | None -> "" in
let tag_str = match tag with Some t -> " <" ^ t ^ ">" | None -> "" in
let flow_str = match style with Layout_style.Flow -> " []" | _ -> "" in
-
Printf.sprintf "%s+SEQ%s%s%s" indent flow_str anchor_str tag_str
-
| Event.Sequence_end -> Printf.sprintf "%s-SEQ" indent
| Event.Scalar { anchor; tag; value; style; _ } ->
let anchor_str = match anchor with Some a -> " &" ^ a | None -> "" in
let tag_str = match tag with Some t -> " <" ^ t ^ ">" | None -> "" in
let style_c = style_char style in
-
Printf.sprintf "%s=VAL%s%s %c%s" indent anchor_str tag_str style_c (escape_string value)
| Event.Alias { anchor } ->
-
Printf.sprintf "%s=ALI *%s" indent anchor
let of_spanned_events events =
let buf = Buffer.create 256 in
-
let depth = ref 0 in
List.iter (fun (e : Event.spanned) ->
-
(match e.event with
-
| Event.Stream_end | Event.Document_end _ | Event.Mapping_end | Event.Sequence_end ->
-
decr depth
-
| _ -> ());
-
let line = format_event !depth e in
Buffer.add_string buf line;
-
Buffer.add_char buf '\n';
-
(match e.event with
-
| Event.Stream_start _ | Event.Document_start _ | Event.Mapping_start _ | Event.Sequence_start _ ->
-
incr depth
-
| _ -> ())
) events;
Buffer.contents buf
···
let escape_string s =
let buf = Buffer.create (String.length s * 2) in
+
String.iter (fun c ->
match c with
| '\n' -> Buffer.add_string buf "\\n"
| '\t' -> Buffer.add_string buf "\\t"
···
| '\x0c' -> Buffer.add_string buf "\\f"
| '\x1b' -> Buffer.add_string buf "\\e"
| '\xa0' -> Buffer.add_string buf "\\_"
| c -> Buffer.add_char buf c
) s;
Buffer.contents buf
···
| Scalar_style.Folded -> '>'
| Scalar_style.Any -> ':'
+
let format_event { Event.event; span = _span } =
match event with
| Event.Stream_start _ -> "+STR"
| Event.Stream_end -> "-STR"
| Event.Document_start { implicit; _ } ->
+
if implicit then "+DOC"
+
else "+DOC ---"
| Event.Document_end { implicit } ->
+
if implicit then "-DOC"
+
else "-DOC ..."
| Event.Mapping_start { anchor; tag; style; _ } ->
let anchor_str = match anchor with Some a -> " &" ^ a | None -> "" in
let tag_str = match tag with Some t -> " <" ^ t ^ ">" | None -> "" in
let flow_str = match style with Layout_style.Flow -> " {}" | _ -> "" in
+
Printf.sprintf "+MAP%s%s%s" flow_str anchor_str tag_str
+
| Event.Mapping_end -> "-MAP"
| Event.Sequence_start { anchor; tag; style; _ } ->
let anchor_str = match anchor with Some a -> " &" ^ a | None -> "" in
let tag_str = match tag with Some t -> " <" ^ t ^ ">" | None -> "" in
let flow_str = match style with Layout_style.Flow -> " []" | _ -> "" in
+
Printf.sprintf "+SEQ%s%s%s" flow_str anchor_str tag_str
+
| Event.Sequence_end -> "-SEQ"
| Event.Scalar { anchor; tag; value; style; _ } ->
let anchor_str = match anchor with Some a -> " &" ^ a | None -> "" in
let tag_str = match tag with Some t -> " <" ^ t ^ ">" | None -> "" in
let style_c = style_char style in
+
Printf.sprintf "=VAL%s%s %c%s" anchor_str tag_str style_c (escape_string value)
| Event.Alias { anchor } ->
+
Printf.sprintf "=ALI *%s" anchor
let of_spanned_events events =
let buf = Buffer.create 256 in
List.iter (fun (e : Event.spanned) ->
+
let line = format_event e in
Buffer.add_string buf line;
+
Buffer.add_char buf '\n'
) events;
Buffer.contents buf