this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

more tests

+179 -83
+50 -18
yaml/ocaml-yamle/bin/yamlcat.ml
··· 7 7 Printf.eprintf "If no files are given, reads from stdin.\n"; 8 8 Printf.eprintf "\n"; 9 9 Printf.eprintf "Options:\n"; 10 + Printf.eprintf " --all Output all documents (for multi-document YAML)\n"; 10 11 Printf.eprintf " --json Output as JSON format\n"; 11 12 Printf.eprintf " --flow Output YAML in flow style\n"; 12 13 Printf.eprintf " --debug Output internal representation (for debugging)\n"; ··· 46 47 json_to_string buf v; 47 48 Buffer.contents buf 48 49 49 - let process_string ~format content = 50 + let process_string ~format ~all content = 50 51 try 51 - match format with 52 - | Yaml -> 53 - let value = Yamle.of_string content in 54 - print_string (Yamle.to_string value) 55 - | Flow -> 56 - let value = Yamle.of_string content in 57 - print_string (Yamle.to_string ~layout_style:Yamle.Layout_style.Flow value) 58 - | Json -> 59 - let value = Yamle.of_string content in 60 - print_endline (value_to_json value) 61 - | Debug -> 62 - let yaml = Yamle.yaml_of_string content in 63 - Format.printf "%a@." Yamle.pp_yaml yaml 52 + if all then 53 + (* Multi-document mode *) 54 + match format with 55 + | Yaml -> 56 + let documents = Yamle.documents_of_string content in 57 + print_string (Yamle.documents_to_string documents) 58 + | Flow -> 59 + let documents = Yamle.documents_of_string content in 60 + print_string (Yamle.documents_to_string ~layout_style:Yamle.Layout_style.Flow documents) 61 + | Json -> 62 + let documents = Yamle.documents_of_string content in 63 + let first = ref true in 64 + List.iter (fun doc -> 65 + match Yamle.Document.root doc with 66 + | None -> () 67 + | Some yaml -> 68 + if not !first then print_endline "---"; 69 + first := false; 70 + let value = Yamle.to_json yaml in 71 + print_endline (value_to_json value) 72 + ) documents 73 + | Debug -> 74 + let documents = Yamle.documents_of_string content in 75 + List.iteri (fun i doc -> 76 + Format.printf "Document %d:@." (i + 1); 77 + Format.printf "%a@." Yamle.Document.pp doc 78 + ) documents 79 + else 80 + (* Single-document mode (original behavior) *) 81 + match format with 82 + | Yaml -> 83 + let value = Yamle.of_string content in 84 + print_string (Yamle.to_string value) 85 + | Flow -> 86 + let value = Yamle.of_string content in 87 + print_string (Yamle.to_string ~layout_style:Yamle.Layout_style.Flow value) 88 + | Json -> 89 + let value = Yamle.of_string content in 90 + print_endline (value_to_json value) 91 + | Debug -> 92 + let yaml = Yamle.yaml_of_string content in 93 + Format.printf "%a@." Yamle.pp_yaml yaml 64 94 with 65 95 | Yamle.Yamle_error e -> 66 96 Printf.eprintf "Error: %s\n" (Yamle.Error.to_string e); 67 97 exit 1 68 98 69 - let process_file ~format filename = 99 + let process_file ~format ~all filename = 70 100 let content = 71 101 if filename = "-" then 72 102 In_channel.input_all In_channel.stdin 73 103 else 74 104 In_channel.with_open_text filename In_channel.input_all 75 105 in 76 - process_string ~format content 106 + process_string ~format ~all content 77 107 78 108 let () = 79 109 let files = ref [] in 80 110 let format = ref Yaml in 81 111 let show_help = ref false in 112 + let all = ref false in 82 113 83 114 (* Parse arguments *) 84 115 let args = Array.to_list Sys.argv |> List.tl in 85 116 List.iter (fun arg -> 86 117 match arg with 87 118 | "--help" | "-h" -> show_help := true 119 + | "--all" -> all := true 88 120 | "--json" -> format := Json 89 121 | "--flow" -> format := Flow 90 122 | "--debug" -> format := Debug ··· 100 132 101 133 if files = [] then 102 134 (* Read from stdin *) 103 - process_file ~format:!format "-" 135 + process_file ~format:!format ~all:!all "-" 104 136 else 105 - List.iter (process_file ~format:!format) files 137 + List.iter (process_file ~format:!format ~all:!all) files
+41 -8
yaml/ocaml-yamle/lib/emitter.ml
··· 388 388 write_anchor t anchor; 389 389 write_tag t ~implicit tag; 390 390 if use_flow then begin 391 + write_char t ' '; 391 392 write_char t '['; 392 393 t.flow_level <- t.flow_level + 1; 393 394 t.need_separator <- false; ··· 420 421 write_char t ']'; 421 422 t.flow_level <- t.flow_level - 1; 422 423 t.need_separator <- true; 423 - pop_state t 424 + pop_state t; 425 + (* Write newline if returning to block context *) 426 + (match t.state with 427 + | In_block_mapping_key _ | In_block_sequence _ -> write_newline t 428 + | _ -> ()) 424 429 end else begin 425 430 t.indent <- t.indent - t.config.indent; 426 431 pop_state t ··· 495 500 write_anchor t anchor; 496 501 write_tag t ~implicit tag; 497 502 if use_flow then begin 503 + write_char t ' '; 498 504 write_char t '{'; 499 505 t.flow_level <- t.flow_level + 1; 500 506 t.need_separator <- false; ··· 527 533 write_char t '}'; 528 534 t.flow_level <- t.flow_level - 1; 529 535 t.need_separator <- true; 530 - pop_state t 536 + pop_state t; 537 + (* Write newline if returning to block context *) 538 + (match t.state with 539 + | In_block_mapping_key _ | In_block_sequence _ -> write_newline t 540 + | _ -> ()) 531 541 end else begin 532 542 t.indent <- t.indent - t.config.indent; 533 543 pop_state t ··· 551 561 emit t (Event.Alias { anchor = name }) 552 562 553 563 | `A seq -> 564 + let members = Sequence.members seq in 565 + let style = 566 + (* Force flow style for empty sequences *) 567 + if members = [] then Layout_style.Flow 568 + else Sequence.style seq 569 + in 554 570 emit t (Event.Sequence_start { 555 571 anchor = Sequence.anchor seq; 556 572 tag = Sequence.tag seq; 557 573 implicit = Sequence.implicit seq; 558 - style = Sequence.style seq; 574 + style; 559 575 }); 560 - List.iter (emit_yaml_node t) (Sequence.members seq); 576 + List.iter (emit_yaml_node t) members; 561 577 emit t Event.Sequence_end 562 578 563 579 | `O map -> 580 + let members = Mapping.members map in 581 + let style = 582 + (* Force flow style for empty mappings *) 583 + if members = [] then Layout_style.Flow 584 + else Mapping.style map 585 + in 564 586 emit t (Event.Mapping_start { 565 587 anchor = Mapping.anchor map; 566 588 tag = Mapping.tag map; 567 589 implicit = Mapping.implicit map; 568 - style = Mapping.style map; 590 + style; 569 591 }); 570 592 List.iter (fun (k, v) -> 571 593 emit_yaml_node t k; 572 594 emit_yaml_node t v 573 - ) (Mapping.members map); 595 + ) members; 574 596 emit t Event.Mapping_end 575 597 576 598 let emit_yaml t yaml = ··· 632 654 633 655 | `A items -> 634 656 let style = 635 - if t.config.layout_style = Layout_style.Flow then Layout_style.Flow 657 + (* Force flow style for empty sequences *) 658 + if items = [] then Layout_style.Flow 659 + else if t.config.layout_style = Layout_style.Flow then Layout_style.Flow 636 660 else Layout_style.Block 637 661 in 638 662 emit t (Event.Sequence_start { ··· 645 669 646 670 | `O pairs -> 647 671 let style = 648 - if t.config.layout_style = Layout_style.Flow then Layout_style.Flow 672 + (* Force flow style for empty mappings *) 673 + if pairs = [] then Layout_style.Flow 674 + else if t.config.layout_style = Layout_style.Flow then Layout_style.Flow 649 675 else Layout_style.Block 650 676 in 651 677 emit t (Event.Mapping_start { ··· 699 725 let t = create ~config () in 700 726 emit_yaml t yaml; 701 727 contents t 728 + 729 + let documents_to_string ?(config = default_config) documents = 730 + let t = create ~config () in 731 + emit t (Event.Stream_start { encoding = config.encoding }); 732 + List.iter (emit_document t) documents; 733 + emit t Event.Stream_end; 734 + contents t
+6 -2
yaml/ocaml-yamle/lib/loader.ml
··· 137 137 | [doc] -> 138 138 (match Document.root doc with 139 139 | None -> `Null 140 - | Some yaml -> Yaml.to_value yaml) 140 + | Some yaml -> 141 + let yaml = Yaml.resolve_aliases yaml in 142 + Yaml.to_value yaml) 141 143 | _ -> Error.raise Multiple_documents 142 144 143 145 (** Load single document as Yaml *) ··· 175 177 state.documents <- []; 176 178 Some (match Document.root doc with 177 179 | None -> `Null 178 - | Some yaml -> Yaml.to_value yaml) 180 + | Some yaml -> 181 + let yaml = Yaml.resolve_aliases yaml in 182 + Yaml.to_value yaml) 179 183 | [] -> None) 180 184 | Event.Stream_end -> None 181 185 | _ -> loop ()
+3 -3
yaml/ocaml-yamle/lib/scanner.ml
··· 233 233 (* Non-specific tag: ! *) 234 234 ("!", "") 235 235 | Some '!' -> 236 - (* Secondary handle *) 237 - let handle = scan_tag_handle t in 236 + (* Secondary handle: !! *) 237 + ignore (Input.next t.input); (* consume second ! *) 238 238 let suffix = scan_tag_suffix t in 239 - (handle, suffix) 239 + ("!!", suffix) 240 240 | _ -> 241 241 (* Primary handle or just suffix *) 242 242 let first_part = scan_tag_suffix t in
+18 -1
yaml/ocaml-yamle/lib/yamle.ml
··· 16 16 17 17 let of_string s = Loader.value_of_string s 18 18 19 + let documents_of_string s = Loader.documents_of_string s 20 + 19 21 (** {1 JSON-compatible emission} *) 20 22 21 23 let to_string ··· 50 52 } in 51 53 Emitter.yaml_to_string ~config yaml 52 54 55 + let documents_to_string 56 + ?(encoding = Encoding.Utf8) 57 + ?(scalar_style = Scalar_style.Any) 58 + ?(layout_style = Layout_style.Any) 59 + documents = 60 + let config = { 61 + Emitter.default_config with 62 + encoding; 63 + scalar_style; 64 + layout_style; 65 + } in 66 + Emitter.documents_to_string ~config documents 67 + 53 68 (** {1 Conversion} *) 54 69 55 - let to_json yaml = Yaml.to_value yaml 70 + let to_json yaml = 71 + let yaml = Yaml.resolve_aliases yaml in 72 + Yaml.to_value yaml 56 73 57 74 let of_json value = Yaml.of_value value 58 75
+22 -18
yaml/ocaml-yamle/tests/cram/collections.t
··· 100 100 config: 101 101 concurrency: 10 102 102 empty_collections: 103 - empty_sequence: 104 - empty_mapping: 103 + empty_sequence: [] 104 + empty_mapping: {} 105 105 sequence_with_empty: 106 106 - value1 107 - - 107 + - [] 108 108 - value2 109 109 mapping_with_empty: 110 110 key1: value1 111 - key2: 111 + key2: {} 112 112 key3: value3 113 113 114 114 Test collections_block.yml with JSON output ··· 248 248 - design 249 249 compact_with_empty: 250 250 - id: 1 251 - data: 252 - meta: 251 + data: [] 252 + meta: {} 253 253 - id: 2 254 254 data: 255 255 - item1 ··· 282 282 - path: '/users/:id' 283 283 method: GET 284 284 auth: required 285 - params: 285 + params: [] 286 286 - path: /users 287 287 method: POST 288 288 auth: required ··· 377 377 - b 378 378 - c 379 379 empty_flow: 380 - empty_seq: 381 - empty_map: 380 + empty_seq: [] 381 + empty_map: {} 382 382 both: 383 - - 384 - - flow_in_block: 383 + - [] 384 + - {} 385 + flow_in_block: 385 386 sequence: 386 387 - 1 387 388 - 2 ··· 494 495 single_item_map: 495 496 only: one 496 497 nested_empty: 498 + - [] 497 499 - 500 + - {} 498 501 - 499 - - - 500 - - - 502 + - {} 503 + - [] 501 504 all_empty: 502 - - - 503 - - a: 504 - - b: 505 + - {} 506 + - [] 507 + - a: [] 508 + - b: {} 505 509 506 510 Test collections_flow.yml with JSON output 507 511 ··· 771 775 772 776 $ echo 'empty_seq: [] 773 777 > empty_map: {}' | yamlcat 774 - empty_seq: 775 - empty_map: 778 + empty_seq: [] 779 + empty_map: {} 776 780 777 781 $ echo 'empty_seq: [] 778 782 > empty_map: {}' | yamlcat --json
+26 -14
yaml/ocaml-yamle/tests/cram/failing_anchors.t
··· 7 7 8 8 $ echo 'anchor: &anc value 9 9 > alias: *anc' | yamlcat 2>&1 10 - Error: unresolved alias: *anc 11 - [1] 10 + anchor: value 11 + alias: value 12 12 13 13 Test: Numeric anchor and alias 14 14 15 15 $ echo 'original: &num 42 16 16 > copy: *num' | yamlcat 2>&1 17 - Error: unresolved alias: *num 18 - [1] 17 + original: 42 18 + copy: 42 19 19 20 20 Test: Sequence anchor and alias 21 21 ··· 23 23 > - one 24 24 > - two 25 25 > copy: *items' | yamlcat 2>&1 26 - Error: unresolved alias: *items 27 - [1] 26 + list: 27 + - one 28 + - two 29 + copy: 30 + - one 31 + - two 28 32 29 33 Test: Mapping anchor and alias 30 34 ··· 32 36 > name: Alice 33 37 > age: 30 34 38 > copy: *p' | yamlcat 2>&1 35 - Error: unresolved alias: *p 36 - [1] 39 + person: 40 + name: Alice 41 + age: 30 42 + copy: 43 + name: Alice 44 + age: 30 37 45 38 46 Test: Multiple aliases to same anchor 39 47 ··· 41 49 > first: *v 42 50 > second: *v 43 51 > third: *v' | yamlcat 2>&1 44 - Error: unresolved alias: *v 45 - [1] 52 + value: 100 53 + first: 100 54 + second: 100 55 + third: 100 46 56 47 57 Test: Anchor in flow context 48 58 49 59 $ echo '[&item apple, *item]' | yamlcat 2>&1 50 - Error: unresolved alias: *item 51 - [1] 60 + - apple 61 + - apple 52 62 53 63 Test: Anchor with mapping in flow 54 64 55 65 $ echo '{original: &cfg {a: 1}, copy: *cfg}' | yamlcat 2>&1 56 - Error: unresolved alias: *cfg 57 - [1] 66 + original: 67 + a: 1 68 + copy: 69 + a: 1 58 70 59 71 Test: Anchors file from test suite 60 72
+7 -7
yaml/ocaml-yamle/tests/cram/failing_empty.t
··· 10 10 Test: Empty sequence emits as nothing instead of [] 11 11 12 12 $ echo 'empty_seq: []' | yamlcat 13 - empty_seq: 13 + empty_seq: [] 14 14 15 15 The above outputs just "empty_seq:" with nothing after it. 16 16 Expected output should be: empty_seq: [] ··· 18 18 Test: Empty mapping emits as nothing instead of {} 19 19 20 20 $ echo 'empty_map: {}' | yamlcat 21 - empty_map: 21 + empty_map: {} 22 22 23 23 Test: Multiple empty collections 24 24 25 25 $ echo 'seq: [] 26 26 > map: {} 27 27 > data: value' | yamlcat 28 - seq: 29 - map: 28 + seq: [] 29 + map: {} 30 30 data: value 31 31 32 32 Test: Nested empty collections ··· 35 35 > inner_seq: [] 36 36 > inner_map: {}' | yamlcat 37 37 outer: 38 - inner_seq: 39 - inner_map: 38 + inner_seq: [] 39 + inner_map: {} 40 40 41 41 Test: Empty collection in sequence 42 42 ··· 46 46 > - third' | yamlcat 47 47 items: 48 48 - first 49 - - 49 + - [] 50 50 - third 51 51 52 52 Test: Verify JSON output is correct (for comparison)
+6 -12
yaml/ocaml-yamle/tests/cram/failing_tags.t
··· 6 6 Test: String tag shorthand 7 7 8 8 $ echo '!!str 123' | yamlcat 9 - Error: invalid tag: !str 10 - [1] 9 + '123' 11 10 12 11 Expected: 123 (as a string) 13 12 14 13 Test: Integer tag shorthand 15 14 16 15 $ echo '!!int "42"' | yamlcat 17 - Error: invalid tag: !int 18 - [1] 16 + 42 19 17 20 18 Expected: 42 21 19 22 20 Test: Boolean tag shorthand 23 21 24 22 $ echo '!!bool "yes"' | yamlcat 25 - Error: invalid tag: !bool 26 - [1] 23 + true 27 24 28 25 Expected: true 29 26 30 27 Test: Null tag shorthand 31 28 32 29 $ echo '!!null ""' | yamlcat 33 - Error: invalid tag: !null 34 - [1] 30 + null 35 31 36 32 Expected: null 37 33 38 34 Test: Float tag shorthand 39 35 40 36 $ echo '!!float 3.14' | yamlcat 41 - Error: invalid tag: !float 42 - [1] 37 + 3.14 43 38 44 39 Expected: 3.14 45 40 46 41 Test: Tag shorthand in mapping value 47 42 48 43 $ echo 'value: !!str 42' | yamlcat 49 - Error: invalid tag: !str 50 - [1] 44 + value: '42' 51 45 52 46 Expected: value: "42" (string representation) 53 47