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

features

+49 -47
yaml/ocaml-yamle/bin/yamlcat.ml
···
json_to_string buf v;
Buffer.contents buf
-
let process_string ~format ~all ~resolve_aliases ~max_nodes ~max_depth content =
+
let process_string ~format ~resolve_aliases ~max_nodes ~max_depth content =
try
-
if all then
-
(* Multi-document mode *)
-
match format with
-
| Yaml ->
-
let documents = Yamle.documents_of_string content in
-
print_string (Yamle.documents_to_string documents)
-
| Flow ->
-
let documents = Yamle.documents_of_string content in
-
print_string (Yamle.documents_to_string ~layout_style:Yamle.Layout_style.Flow documents)
-
| Json ->
-
let documents = Yamle.documents_of_string content in
-
let first = ref true in
-
List.iter (fun doc ->
-
match Yamle.Document.root doc with
-
| None -> ()
-
| Some yaml ->
-
if not !first then print_endline "---";
-
first := false;
-
let value = Yamle.to_json ~resolve_aliases ~max_nodes ~max_depth yaml in
-
print_endline (value_to_json value)
-
) documents
-
| Debug ->
-
let documents = Yamle.documents_of_string content in
-
List.iteri (fun i doc ->
-
Format.printf "Document %d:@." (i + 1);
-
Format.printf "%a@." Yamle.Document.pp doc
-
) documents
-
else
-
(* Single-document mode (original behavior) *)
-
match format with
-
| Yaml ->
-
let value = Yamle.of_string ~resolve_aliases ~max_nodes ~max_depth content in
-
print_string (Yamle.to_string value)
-
| Flow ->
-
let value = Yamle.of_string ~resolve_aliases ~max_nodes ~max_depth content in
-
print_string (Yamle.to_string ~layout_style:Yamle.Layout_style.Flow value)
-
| Json ->
-
let value = Yamle.of_string ~resolve_aliases ~max_nodes ~max_depth content in
-
print_endline (value_to_json value)
-
| Debug ->
-
let yaml = Yamle.yaml_of_string ~resolve_aliases ~max_nodes ~max_depth content in
-
Format.printf "%a@." Yamle.pp_yaml yaml
+
(* Always parse as multi-document stream *)
+
let documents = Yamle.documents_of_string content in
+
+
match format with
+
| Yaml ->
+
(* Convert through Value to apply tag-based type coercion *)
+
let first = ref true in
+
List.iter (fun doc ->
+
if not !first then print_string "---\n";
+
first := false;
+
match Yamle.Document.root doc with
+
| None -> print_endline ""
+
| Some yaml ->
+
let value = Yamle.to_json ~resolve_aliases ~max_nodes ~max_depth yaml in
+
print_string (Yamle.to_string value)
+
) documents
+
| Flow ->
+
(* Convert through Value to apply tag-based type coercion *)
+
let first = ref true in
+
List.iter (fun doc ->
+
if not !first then print_string "---\n";
+
first := false;
+
match Yamle.Document.root doc with
+
| None -> print_endline ""
+
| Some yaml ->
+
let value = Yamle.to_json ~resolve_aliases ~max_nodes ~max_depth yaml in
+
print_string (Yamle.to_string ~layout_style:Yamle.Layout_style.Flow value)
+
) documents
+
| Json ->
+
let first = ref true in
+
List.iter (fun doc ->
+
match Yamle.Document.root doc with
+
| None -> ()
+
| Some yaml ->
+
if not !first then print_endline "---";
+
first := false;
+
let value = Yamle.to_json ~resolve_aliases ~max_nodes ~max_depth yaml in
+
print_endline (value_to_json value)
+
) documents
+
| Debug ->
+
List.iteri (fun i doc ->
+
Format.printf "Document %d:@." (i + 1);
+
Format.printf "%a@." Yamle.Document.pp doc
+
) documents
with
| Yamle.Yamle_error e ->
Printf.eprintf "Error: %s\n" (Yamle.Error.to_string e);
exit 1
-
let process_file ~format ~all ~resolve_aliases ~max_nodes ~max_depth filename =
+
let process_file ~format ~resolve_aliases ~max_nodes ~max_depth filename =
let content =
if filename = "-" then
In_channel.input_all In_channel.stdin
else
In_channel.with_open_text filename In_channel.input_all
in
-
process_string ~format ~all ~resolve_aliases ~max_nodes ~max_depth content
+
process_string ~format ~resolve_aliases ~max_nodes ~max_depth content
-
let run format all resolve_aliases max_nodes max_depth files =
+
let run format _all resolve_aliases max_nodes max_depth files =
let files = if files = [] then ["-"] else files in
-
List.iter (process_file ~format ~all ~resolve_aliases ~max_nodes ~max_depth) files;
+
List.iter (process_file ~format ~resolve_aliases ~max_nodes ~max_depth) files;
`Ok ()
(* Command-line arguments *)
+34 -4
yaml/ocaml-yamle/lib/emitter.ml
···
emit t (Event.Document_end { implicit = true });
emit t Event.Stream_end
-
let emit_document t doc =
+
(** Strip anchors from a YAML tree *)
+
let rec strip_anchors (yaml : Yaml.t) : Yaml.t =
+
match yaml with
+
| `Scalar s ->
+
if Scalar.anchor s = None then yaml
+
else
+
`Scalar (Scalar.make
+
?tag:(Scalar.tag s)
+
~plain_implicit:(Scalar.plain_implicit s)
+
~quoted_implicit:(Scalar.quoted_implicit s)
+
~style:(Scalar.style s)
+
(Scalar.value s))
+
| `Alias _ -> yaml
+
| `A seq ->
+
`A (Sequence.make
+
?tag:(Sequence.tag seq)
+
~implicit:(Sequence.implicit seq)
+
~style:(Sequence.style seq)
+
(List.map strip_anchors (Sequence.members seq)))
+
| `O map ->
+
`O (Mapping.make
+
?tag:(Mapping.tag map)
+
~implicit:(Mapping.implicit map)
+
~style:(Mapping.style map)
+
(List.map (fun (k, v) -> (strip_anchors k, strip_anchors v)) (Mapping.members map)))
+
+
let emit_document ?(resolve_aliases = true) t doc =
emit t (Event.Document_start {
version = Document.version doc;
implicit = Document.implicit_start doc;
});
(match Document.root doc with
-
| Some yaml -> emit_yaml_node t yaml
+
| Some yaml ->
+
let yaml = if resolve_aliases then
+
yaml |> Yaml.resolve_aliases |> strip_anchors
+
else yaml in
+
emit_yaml_node t yaml
| None ->
emit t (Event.Scalar {
anchor = None; tag = None;
···
emit_yaml t yaml;
contents t
-
let documents_to_string ?(config = default_config) documents =
+
let documents_to_string ?(config = default_config) ?(resolve_aliases = true) documents =
let t = create ~config () in
emit t (Event.Stream_start { encoding = config.encoding });
-
List.iter (emit_document t) documents;
+
List.iter (emit_document ~resolve_aliases t) documents;
emit t Event.Stream_end;
contents t
+2 -1
yaml/ocaml-yamle/lib/yamle.ml
···
?(encoding = Encoding.Utf8)
?(scalar_style = Scalar_style.Any)
?(layout_style = Layout_style.Any)
+
?(resolve_aliases = true)
documents =
let config = {
Emitter.default_config with
···
scalar_style;
layout_style;
} in
-
Emitter.documents_to_string ~config documents
+
Emitter.documents_to_string ~config ~resolve_aliases documents
(** {1 Conversion} *)
+375
yaml/ocaml-yamle/tests/cram/anchors.t
···
+
Anchor and Alias Support (currently not supported)
+
+
These tests document anchor (&) and alias (*) support that is not yet
+
implemented. Currently, aliases fail with "unresolved alias" error.
+
+
Test: Simple scalar anchor and alias
+
+
$ echo 'anchor: &anc value
+
> alias: *anc' | yamlcat 2>&1
+
anchor: value
+
alias: value
+
+
Test: Numeric anchor and alias
+
+
$ echo 'original: &num 42
+
> copy: *num' | yamlcat 2>&1
+
original: 42
+
copy: 42
+
+
Test: Sequence anchor and alias
+
+
$ echo 'list: &items
+
> - one
+
> - two
+
> copy: *items' | yamlcat 2>&1
+
list:
+
- one
+
- two
+
copy:
+
- one
+
- two
+
+
Test: Mapping anchor and alias
+
+
$ echo 'person: &p
+
> name: Alice
+
> age: 30
+
> copy: *p' | yamlcat 2>&1
+
person:
+
name: Alice
+
age: 30
+
copy:
+
name: Alice
+
age: 30
+
+
Test: Multiple aliases to same anchor
+
+
$ echo 'value: &v 100
+
> first: *v
+
> second: *v
+
> third: *v' | yamlcat 2>&1
+
value: 100
+
first: 100
+
second: 100
+
third: 100
+
+
Test: Anchor in flow context
+
+
$ echo '[&item apple, *item]' | yamlcat 2>&1
+
- apple
+
- apple
+
+
Test: Anchor with mapping in flow
+
+
$ echo '{original: &cfg {a: 1}, copy: *cfg}' | yamlcat 2>&1
+
original:
+
a: 1
+
copy:
+
a: 1
+
+
Test: Anchors file from test suite
+
+
$ yamlcat ../yaml/anchors_basic.yml 2>&1
+
scalar_anchor: Hello, World!
+
scalar_alias: Hello, World!
+
---
+
original: 42
+
copy: 42
+
another_copy: 42
+
---
+
original_list:
+
- apple
+
- banana
+
- cherry
+
copied_list:
+
- apple
+
- banana
+
- cherry
+
---
+
original_map:
+
name: Alice
+
age: 30
+
city: London
+
copied_map:
+
name: Alice
+
age: 30
+
city: London
+
---
+
defaults:
+
timeout: 30
+
retries: 3
+
colors:
+
- red
+
- green
+
- blue
+
config:
+
settings:
+
timeout: 30
+
retries: 3
+
palette:
+
- red
+
- green
+
- blue
+
---
+
template:
+
metadata:
+
version: 1
+
author: John Doe
+
settings:
+
enabled: true
+
debug: false
+
instance1:
+
metadata:
+
version: 1
+
author: John Doe
+
settings:
+
enabled: true
+
debug: false
+
instance2:
+
metadata:
+
version: 1
+
author: John Doe
+
settings:
+
enabled: true
+
debug: false
+
---
+
items:
+
- id: 1
+
name: First
+
- id: 2
+
name: Second
+
- id: 1
+
name: First
+
---
+
shared_value: 100
+
calculations:
+
base: 100
+
doubled: 200
+
reference: 100
+
another_ref: 100
+
---
+
feature_flag: true
+
features:
+
login: true
+
signup: true
+
export: true
+
---
+
empty: null
+
values:
+
first: null
+
second: null
+
---
+
message: "This is a multi-line\nmessage with some\nspecial content!\n"
+
output1: "This is a multi-line\nmessage with some\nspecial content!\n"
+
output2: "This is a multi-line\nmessage with some\nspecial content!\n"
+
---
+
database:
+
primary:
+
host: localhost
+
port: 5432
+
ssl: true
+
replica:
+
host: localhost
+
port: 5432
+
ssl: true
+
backup:
+
host: localhost
+
port: 5432
+
ssl: true
+
+
$ yamlcat ../yaml/anchors_merge.yml 2>&1
+
defaults:
+
timeout: 30
+
retries: 3
+
verbose: false
+
production:
+
<<:
+
timeout: 30
+
retries: 3
+
verbose: false
+
environment: production
+
---
+
base:
+
color: red
+
size: medium
+
weight: 100
+
custom:
+
<<:
+
color: red
+
size: medium
+
weight: 100
+
color: blue
+
shape: circle
+
---
+
connection:
+
host: localhost
+
port: 8080
+
authentication:
+
username: admin
+
password: secret
+
server:
+
<<:
+
- host: localhost
+
port: 8080
+
- username: admin
+
password: secret
+
ssl: true
+
---
+
defaults:
+
timeout: 30
+
retries: 3
+
advanced:
+
cache: true
+
pool_size: 10
+
config:
+
<<:
+
- timeout: 30
+
retries: 3
+
- cache: true
+
pool_size: 10
+
timeout: 60
+
custom: value
+
---
+
base_style:
+
font: Arial
+
size: 12
+
heading_defaults:
+
<<:
+
font: Arial
+
size: 12
+
weight: bold
+
main_heading:
+
<<:
+
<<:
+
font: Arial
+
size: 12
+
weight: bold
+
size: 18
+
color: navy
+
---
+
common:
+
enabled: true
+
log_level: info
+
services:
+
- name: web
+
<<:
+
enabled: true
+
log_level: info
+
port: 80
+
- name: api
+
<<:
+
enabled: true
+
log_level: info
+
port: 3000
+
- name: worker
+
<<:
+
enabled: true
+
log_level: info
+
threads: 4
+
---
+
empty: {}
+
config:
+
<<: {}
+
key: value
+
---
+
metadata:
+
created: 2023-01-01
+
author: Admin
+
tags:
+
- v1
+
- stable
+
document:
+
<<:
+
created: 2023-01-01
+
author: Admin
+
tags:
+
- v1
+
- stable
+
title: Important Document
+
content: Some content here
+
---
+
level1:
+
a: 1
+
b: 2
+
level2:
+
<<:
+
a: 1
+
b: 2
+
c: 3
+
level3:
+
<<:
+
<<:
+
a: 1
+
b: 2
+
c: 3
+
d: 4
+
---
+
first:
+
name: First
+
value: 100
+
priority: low
+
second:
+
name: Second
+
value: 200
+
category: important
+
combined:
+
<<:
+
- name: First
+
value: 100
+
priority: low
+
- name: Second
+
value: 200
+
category: important
+
name: Combined
+
---
+
numbers:
+
count: 42
+
ratio: 3.14
+
active: true
+
derived:
+
<<:
+
count: 42
+
ratio: 3.14
+
active: true
+
label: Test
+
---
+
db_defaults:
+
pool_size: 5
+
timeout: 30
+
ssl: false
+
cache_defaults:
+
ttl: 3600
+
max_size: 1000
+
development:
+
database:
+
<<:
+
pool_size: 5
+
timeout: 30
+
ssl: false
+
host: localhost
+
name: dev_db
+
cache:
+
<<:
+
ttl: 3600
+
max_size: 1000
+
backend: memory
+
production:
+
database:
+
<<:
+
pool_size: 5
+
timeout: 30
+
ssl: false
+
host: prod.example.com
+
name: prod_db
+
ssl: true
+
pool_size: 20
+
cache:
+
<<:
+
ttl: 3600
+
max_size: 1000
+
backend: redis
+
ttl: 7200
+
+
Note: The anchor test files also use multiple documents, so they fail
+
with multi-document errors before even hitting anchor issues.
+12 -6
yaml/ocaml-yamle/tests/cram/bomb.t
···
> EOF
$ yamlcat --no-resolve-aliases --debug simple_alias.yml
-
mapping(
-
style=block,
-
members={
-
scalar("anchor", style=plain): scalar("hello", anchor=anc, style=plain),
-
scalar("alias", style=plain): *anc
-
})
+
Document 1:
+
document(
+
implicit_start=true,
+
implicit_end=true,
+
root=mapping(
+
style=block,
+
members={
+
scalar("anchor", style=plain):
+
scalar("hello", anchor=anc, style=plain),
+
scalar("alias", style=plain): *anc
+
})
+
)
With resolve (default), aliases are expanded:
+49
yaml/ocaml-yamle/tests/cram/empty.t
···
+
Empty Collection YAML Emission
+
+
These tests verify that empty sequences and mappings are correctly emitted
+
as [] and {} in YAML output.
+
+
Test: Empty sequence
+
+
$ echo 'empty_seq: []' | yamlcat
+
empty_seq: []
+
+
Test: Empty mapping
+
+
$ echo 'empty_map: {}' | yamlcat
+
empty_map: {}
+
+
Test: Multiple empty collections
+
+
$ echo 'seq: []
+
> map: {}
+
> data: value' | yamlcat
+
seq: []
+
map: {}
+
data: value
+
+
Test: Nested empty collections
+
+
$ echo 'outer:
+
> inner_seq: []
+
> inner_map: {}' | yamlcat
+
outer:
+
inner_seq: []
+
inner_map: {}
+
+
Test: Empty collection in sequence
+
+
$ echo 'items:
+
> - first
+
> - []
+
> - third' | yamlcat
+
items:
+
- first
+
- []
+
- third
+
+
Test: Verify JSON output is correct (for comparison)
+
+
$ echo 'empty_seq: []
+
> empty_map: {}' | yamlcat --json
+
{"empty_seq": [], "empty_map": {}}
-82
yaml/ocaml-yamle/tests/cram/failing_anchors.t
···
-
Anchor and Alias Support (currently not supported)
-
-
These tests document anchor (&) and alias (*) support that is not yet
-
implemented. Currently, aliases fail with "unresolved alias" error.
-
-
Test: Simple scalar anchor and alias
-
-
$ echo 'anchor: &anc value
-
> alias: *anc' | yamlcat 2>&1
-
anchor: value
-
alias: value
-
-
Test: Numeric anchor and alias
-
-
$ echo 'original: &num 42
-
> copy: *num' | yamlcat 2>&1
-
original: 42
-
copy: 42
-
-
Test: Sequence anchor and alias
-
-
$ echo 'list: &items
-
> - one
-
> - two
-
> copy: *items' | yamlcat 2>&1
-
list:
-
- one
-
- two
-
copy:
-
- one
-
- two
-
-
Test: Mapping anchor and alias
-
-
$ echo 'person: &p
-
> name: Alice
-
> age: 30
-
> copy: *p' | yamlcat 2>&1
-
person:
-
name: Alice
-
age: 30
-
copy:
-
name: Alice
-
age: 30
-
-
Test: Multiple aliases to same anchor
-
-
$ echo 'value: &v 100
-
> first: *v
-
> second: *v
-
> third: *v' | yamlcat 2>&1
-
value: 100
-
first: 100
-
second: 100
-
third: 100
-
-
Test: Anchor in flow context
-
-
$ echo '[&item apple, *item]' | yamlcat 2>&1
-
- apple
-
- apple
-
-
Test: Anchor with mapping in flow
-
-
$ echo '{original: &cfg {a: 1}, copy: *cfg}' | yamlcat 2>&1
-
original:
-
a: 1
-
copy:
-
a: 1
-
-
Test: Anchors file from test suite
-
-
$ yamlcat ../yaml/anchors_basic.yml 2>&1
-
Error: multiple documents found when single expected
-
[1]
-
-
$ yamlcat ../yaml/anchors_merge.yml 2>&1
-
Error: multiple documents found when single expected
-
[1]
-
-
Note: The anchor test files also use multiple documents, so they fail
-
with multi-document errors before even hitting anchor issues.
-56
yaml/ocaml-yamle/tests/cram/failing_empty.t
···
-
Empty Collection YAML Emission (currently outputs nothing instead of [] or {})
-
-
These tests document the empty collection emission issue where empty
-
sequences and mappings are emitted as nothing (interpreted as null)
-
instead of [] or {} in YAML output.
-
-
Note: JSON output correctly shows [] and {} for empty collections.
-
The issue is only with YAML-format output.
-
-
Test: Empty sequence emits as nothing instead of []
-
-
$ echo 'empty_seq: []' | yamlcat
-
empty_seq: []
-
-
The above outputs just "empty_seq:" with nothing after it.
-
Expected output should be: empty_seq: []
-
-
Test: Empty mapping emits as nothing instead of {}
-
-
$ echo 'empty_map: {}' | yamlcat
-
empty_map: {}
-
-
Test: Multiple empty collections
-
-
$ echo 'seq: []
-
> map: {}
-
> data: value' | yamlcat
-
seq: []
-
map: {}
-
data: value
-
-
Test: Nested empty collections
-
-
$ echo 'outer:
-
> inner_seq: []
-
> inner_map: {}' | yamlcat
-
outer:
-
inner_seq: []
-
inner_map: {}
-
-
Test: Empty collection in sequence
-
-
$ echo 'items:
-
> - first
-
> - []
-
> - third' | yamlcat
-
items:
-
- first
-
- []
-
- third
-
-
Test: Verify JSON output is correct (for comparison)
-
-
$ echo 'empty_seq: []
-
> empty_map: {}' | yamlcat --json
-
{"empty_seq": [], "empty_map": {}}
-73
yaml/ocaml-yamle/tests/cram/failing_multidoc.t
···
-
Multi-document stream support (currently not supported)
-
-
These tests document expected behavior for multi-document YAML streams.
-
They currently fail with "multiple documents found when single expected".
-
-
Test: Two documents separated by ---
-
-
$ echo '---
-
> first: document
-
> ---
-
> second: document' | yamlcat 2>&1
-
Error: multiple documents found when single expected
-
[1]
-
-
Test: Three documents with different types
-
-
$ echo '---
-
> mapping: value
-
> ---
-
> - sequence
-
> - items
-
> ---
-
> scalar value' | yamlcat 2>&1
-
Error: multiple documents found when single expected
-
[1]
-
-
Test: Documents with explicit end markers
-
-
$ echo '---
-
> doc1: value
-
> ...
-
> ---
-
> doc2: value
-
> ...' | yamlcat 2>&1
-
Error: multiple documents found when single expected
-
[1]
-
-
Test: Empty documents
-
-
$ echo '---
-
> ---
-
> content: here
-
> ---' | yamlcat 2>&1
-
Error: multiple documents found when single expected
-
[1]
-
-
Test: Multi-document file
-
-
$ yamlcat ../yaml/documents_multi.yml 2>&1
-
Error: multiple documents found when single expected
-
[1]
-
-
$ yamlcat ../yaml/documents_multi_three.yml 2>&1
-
Error: multiple documents found when single expected
-
[1]
-
-
$ yamlcat ../yaml/documents_multi_with_end.yml 2>&1
-
Error: multiple documents found when single expected
-
[1]
-
-
$ yamlcat ../yaml/documents_multi_empty.yml 2>&1
-
Error: multiple documents found when single expected
-
[1]
-
-
Test: Anchors file (uses multiple documents)
-
-
$ yamlcat ../yaml/anchors_basic.yml 2>&1
-
Error: multiple documents found when single expected
-
[1]
-
-
$ yamlcat ../yaml/anchors_merge.yml 2>&1
-
Error: multiple documents found when single expected
-
[1]
-63
yaml/ocaml-yamle/tests/cram/failing_tags.t
···
-
Tag Shorthand Support (currently not supported)
-
-
These tests document YAML tag shorthand (!!) support that is not yet
-
implemented. Currently, tags are parsed as part of plain scalar content.
-
-
Test: String tag shorthand
-
-
$ echo '!!str 123' | yamlcat
-
'123'
-
-
Expected: 123 (as a string)
-
-
Test: Integer tag shorthand
-
-
$ echo '!!int "42"' | yamlcat
-
42
-
-
Expected: 42
-
-
Test: Boolean tag shorthand
-
-
$ echo '!!bool "yes"' | yamlcat
-
true
-
-
Expected: true
-
-
Test: Null tag shorthand
-
-
$ echo '!!null ""' | yamlcat
-
null
-
-
Expected: null
-
-
Test: Float tag shorthand
-
-
$ echo '!!float 3.14' | yamlcat
-
3.14
-
-
Expected: 3.14
-
-
Test: Tag shorthand in mapping value
-
-
$ echo 'value: !!str 42' | yamlcat
-
value: '42'
-
-
Expected: value: "42" (string representation)
-
-
Test: Local tags
-
-
$ echo '!local_tag value' | yamlcat
-
value
-
-
Expected: value (with local tag applied)
-
-
Test: Verbatim tags
-
-
$ echo '!<tag:example.com:type> value' | yamlcat
-
value
-
-
Expected: value (with verbatim tag applied)
-
-
Note: Tags are being parsed as literal text in the scalar value,
-
with exclamation marks escaped in the output.
+407
yaml/ocaml-yamle/tests/cram/multidoc.t
···
+
Multi-document stream support (currently not supported)
+
+
These tests document expected behavior for multi-document YAML streams.
+
They currently fail with "multiple documents found when single expected".
+
+
Test: Two documents separated by ---
+
+
$ echo '---
+
> first: document
+
> ---
+
> second: document' | yamlcat 2>&1
+
first: document
+
---
+
second: document
+
+
Test: Three documents with different types
+
+
$ echo '---
+
> mapping: value
+
> ---
+
> - sequence
+
> - items
+
> ---
+
> scalar value' | yamlcat 2>&1
+
mapping: value
+
---
+
- sequence
+
- items
+
---
+
scalar value
+
+
Test: Documents with explicit end markers
+
+
$ echo '---
+
> doc1: value
+
> ...
+
> ---
+
> doc2: value
+
> ...' | yamlcat 2>&1
+
doc1: value
+
---
+
doc2: value
+
+
Test: Empty documents
+
+
$ echo '---
+
> ---
+
> content: here
+
> ---' | yamlcat 2>&1
+
null
+
---
+
content: here
+
---
+
null
+
+
Test: Multi-document file
+
+
$ yamlcat ../yaml/documents_multi.yml 2>&1
+
document: first
+
type: mapping
+
data:
+
key1: value1
+
key2: value2
+
---
+
document: second
+
type: mapping
+
data:
+
key3: value3
+
key4: value4
+
+
$ yamlcat ../yaml/documents_multi_three.yml 2>&1
+
name: John Doe
+
age: 30
+
city: New York
+
---
+
- apple
+
- banana
+
- orange
+
- grape
+
---
+
This is a plain scalar document
+
+
$ yamlcat ../yaml/documents_multi_with_end.yml 2>&1
+
first:
+
document: data1
+
value: 100
+
---
+
second:
+
document: data2
+
value: 200
+
---
+
third:
+
document: data3
+
value: 300
+
+
$ yamlcat ../yaml/documents_multi_empty.yml 2>&1
+
null
+
---
+
key: value
+
---
+
null
+
---
+
- item1
+
- item2
+
+
Test: Anchors file (uses multiple documents)
+
+
$ yamlcat ../yaml/anchors_basic.yml 2>&1
+
scalar_anchor: Hello, World!
+
scalar_alias: Hello, World!
+
---
+
original: 42
+
copy: 42
+
another_copy: 42
+
---
+
original_list:
+
- apple
+
- banana
+
- cherry
+
copied_list:
+
- apple
+
- banana
+
- cherry
+
---
+
original_map:
+
name: Alice
+
age: 30
+
city: London
+
copied_map:
+
name: Alice
+
age: 30
+
city: London
+
---
+
defaults:
+
timeout: 30
+
retries: 3
+
colors:
+
- red
+
- green
+
- blue
+
config:
+
settings:
+
timeout: 30
+
retries: 3
+
palette:
+
- red
+
- green
+
- blue
+
---
+
template:
+
metadata:
+
version: 1
+
author: John Doe
+
settings:
+
enabled: true
+
debug: false
+
instance1:
+
metadata:
+
version: 1
+
author: John Doe
+
settings:
+
enabled: true
+
debug: false
+
instance2:
+
metadata:
+
version: 1
+
author: John Doe
+
settings:
+
enabled: true
+
debug: false
+
---
+
items:
+
- id: 1
+
name: First
+
- id: 2
+
name: Second
+
- id: 1
+
name: First
+
---
+
shared_value: 100
+
calculations:
+
base: 100
+
doubled: 200
+
reference: 100
+
another_ref: 100
+
---
+
feature_flag: true
+
features:
+
login: true
+
signup: true
+
export: true
+
---
+
empty: null
+
values:
+
first: null
+
second: null
+
---
+
message: "This is a multi-line\nmessage with some\nspecial content!\n"
+
output1: "This is a multi-line\nmessage with some\nspecial content!\n"
+
output2: "This is a multi-line\nmessage with some\nspecial content!\n"
+
---
+
database:
+
primary:
+
host: localhost
+
port: 5432
+
ssl: true
+
replica:
+
host: localhost
+
port: 5432
+
ssl: true
+
backup:
+
host: localhost
+
port: 5432
+
ssl: true
+
+
$ yamlcat ../yaml/anchors_merge.yml 2>&1
+
defaults:
+
timeout: 30
+
retries: 3
+
verbose: false
+
production:
+
<<:
+
timeout: 30
+
retries: 3
+
verbose: false
+
environment: production
+
---
+
base:
+
color: red
+
size: medium
+
weight: 100
+
custom:
+
<<:
+
color: red
+
size: medium
+
weight: 100
+
color: blue
+
shape: circle
+
---
+
connection:
+
host: localhost
+
port: 8080
+
authentication:
+
username: admin
+
password: secret
+
server:
+
<<:
+
- host: localhost
+
port: 8080
+
- username: admin
+
password: secret
+
ssl: true
+
---
+
defaults:
+
timeout: 30
+
retries: 3
+
advanced:
+
cache: true
+
pool_size: 10
+
config:
+
<<:
+
- timeout: 30
+
retries: 3
+
- cache: true
+
pool_size: 10
+
timeout: 60
+
custom: value
+
---
+
base_style:
+
font: Arial
+
size: 12
+
heading_defaults:
+
<<:
+
font: Arial
+
size: 12
+
weight: bold
+
main_heading:
+
<<:
+
<<:
+
font: Arial
+
size: 12
+
weight: bold
+
size: 18
+
color: navy
+
---
+
common:
+
enabled: true
+
log_level: info
+
services:
+
- name: web
+
<<:
+
enabled: true
+
log_level: info
+
port: 80
+
- name: api
+
<<:
+
enabled: true
+
log_level: info
+
port: 3000
+
- name: worker
+
<<:
+
enabled: true
+
log_level: info
+
threads: 4
+
---
+
empty: {}
+
config:
+
<<: {}
+
key: value
+
---
+
metadata:
+
created: 2023-01-01
+
author: Admin
+
tags:
+
- v1
+
- stable
+
document:
+
<<:
+
created: 2023-01-01
+
author: Admin
+
tags:
+
- v1
+
- stable
+
title: Important Document
+
content: Some content here
+
---
+
level1:
+
a: 1
+
b: 2
+
level2:
+
<<:
+
a: 1
+
b: 2
+
c: 3
+
level3:
+
<<:
+
<<:
+
a: 1
+
b: 2
+
c: 3
+
d: 4
+
---
+
first:
+
name: First
+
value: 100
+
priority: low
+
second:
+
name: Second
+
value: 200
+
category: important
+
combined:
+
<<:
+
- name: First
+
value: 100
+
priority: low
+
- name: Second
+
value: 200
+
category: important
+
name: Combined
+
---
+
numbers:
+
count: 42
+
ratio: 3.14
+
active: true
+
derived:
+
<<:
+
count: 42
+
ratio: 3.14
+
active: true
+
label: Test
+
---
+
db_defaults:
+
pool_size: 5
+
timeout: 30
+
ssl: false
+
cache_defaults:
+
ttl: 3600
+
max_size: 1000
+
development:
+
database:
+
<<:
+
pool_size: 5
+
timeout: 30
+
ssl: false
+
host: localhost
+
name: dev_db
+
cache:
+
<<:
+
ttl: 3600
+
max_size: 1000
+
backend: memory
+
production:
+
database:
+
<<:
+
pool_size: 5
+
timeout: 30
+
ssl: false
+
host: prod.example.com
+
name: prod_db
+
ssl: true
+
pool_size: 20
+
cache:
+
<<:
+
ttl: 3600
+
max_size: 1000
+
backend: redis
+
ttl: 7200
+60
yaml/ocaml-yamle/tests/cram/tags.t
···
+
Tag Support Tests
+
+
These tests verify YAML tag support including type coercion and
+
different tag formats.
+
+
Test: String tag shorthand
+
+
$ printf '!!str 123' | yamlcat
+
'123'
+
+
The !!str tag forces the value to be treated as a string.
+
+
Test: Integer tag shorthand
+
+
$ printf '!!int "42"' | yamlcat
+
42
+
+
The !!int tag coerces the quoted string to an integer.
+
+
Test: Boolean tag shorthand
+
+
$ printf '!!bool "yes"' | yamlcat
+
true
+
+
The !!bool tag coerces the string to a boolean.
+
+
Test: Null tag shorthand
+
+
$ printf '!!null ""' | yamlcat
+
null
+
+
The !!null tag coerces the value to null.
+
+
Test: Float tag shorthand
+
+
$ printf '!!float 3.14' | yamlcat
+
3.14
+
+
The !!float tag specifies a floating-point number.
+
+
Test: Tag shorthand in mapping value
+
+
$ printf 'value: !!str 42' | yamlcat
+
value: '42'
+
+
Tags work in mapping values and force type coercion.
+
+
Test: Local tags
+
+
$ printf '!local_tag value' | yamlcat
+
value
+
+
Local tags (single !) are treated as unknown and default to string type.
+
+
Test: Verbatim tags
+
+
$ printf '!<tag:example.com:type> value' | yamlcat
+
value
+
+
Verbatim tags (!<...>) are treated as unknown and default to string type.