Pure OCaml Yaml 1.2 reader and writer using Bytesrw

break out cram tests to avoid echo

+1
tests/cram/anchor_flow_map.yml
···
+
{original: &cfg {a: 1}, copy: *cfg}
+1
tests/cram/anchor_flow_seq.yml
···
+
[&item apple, *item]
+4
tests/cram/anchor_list.yml
···
+
list: &items
+
- one
+
- two
+
copy: *items
+4
tests/cram/anchor_mapping.yml
···
+
person: &p
+
name: Alice
+
age: 30
+
copy: *p
+4
tests/cram/anchor_multiple_refs.yml
···
+
value: &v 100
+
first: *v
+
second: *v
+
third: *v
+2
tests/cram/anchor_number.yml
···
+
original: &num 42
+
copy: *num
+2
tests/cram/anchor_simple.yml
···
+
anchor: &anc value
+
alias: *anc
+7 -18
tests/cram/anchors.t
···
Test: Simple scalar anchor and alias
-
$ echo 'anchor: &anc value
-
> alias: *anc' | yamlcat 2>&1
+
$ yamlcat anchor_simple.yml 2>&1
anchor: value
alias: value
Test: Numeric anchor and alias
-
$ echo 'original: &num 42
-
> copy: *num' | yamlcat 2>&1
+
$ yamlcat anchor_number.yml 2>&1
original: 42
copy: 42
Test: Sequence anchor and alias
-
$ echo 'list: &items
-
> - one
-
> - two
-
> copy: *items' | yamlcat 2>&1
+
$ yamlcat anchor_list.yml 2>&1
list:
- one
- two
···
Test: Mapping anchor and alias
-
$ echo 'person: &p
-
> name: Alice
-
> age: 30
-
> copy: *p' | yamlcat 2>&1
+
$ yamlcat anchor_mapping.yml 2>&1
person:
name: Alice
age: 30
···
Test: Multiple aliases to same anchor
-
$ echo 'value: &v 100
-
> first: *v
-
> second: *v
-
> third: *v' | yamlcat 2>&1
+
$ yamlcat anchor_multiple_refs.yml 2>&1
value: 100
first: 100
second: 100
···
Test: Anchor in flow context
-
$ echo '[&item apple, *item]' | yamlcat 2>&1
+
$ yamlcat anchor_flow_seq.yml 2>&1
- apple
- apple
Test: Anchor with mapping in flow
-
$ echo '{original: &cfg {a: 1}, copy: *cfg}' | yamlcat 2>&1
+
$ yamlcat anchor_flow_map.yml 2>&1
original:
a: 1
copy:
+4
tests/cram/directive_with_comment.yml
···
+
%YAML 1.2
+
# Comment after directive
+
---
+
key: value
+2
tests/cram/directive_without_start.yml
···
+
%YAML 1.2
+
simple: document
+4
tests/cram/doc_with_comments.yml
···
+
# This is a comment
+
name: Alice
+
# Another comment
+
value: 42
+4
tests/cram/doc_with_end.yml
···
+
---
+
title: Example
+
content: data
+
...
+10 -34
tests/cram/documents.t
···
Test 9: Inline - implicit document (no markers)
====================================
-
$ echo 'name: John
-
> age: 30
-
> city: New York' | yamlcat
+
$ yamlcat person_john.yml
name: John
age: 30
city: New York
···
Test 10: Inline - explicit start marker
====================================
-
$ echo '---
-
> name: Jane
-
> age: 25' | yamlcat
+
$ yamlcat person_jane.yml
name: Jane
age: 25
Test 11: Inline - explicit start and end markers
====================================
-
$ echo '---
-
> title: Example
-
> content: data
-
> ...' | yamlcat
+
$ yamlcat doc_with_end.yml
title: Example
content: data
Test 12: Inline - document with %YAML 1.2 directive
====================================
-
$ echo '%YAML 1.2
-
> ---
-
> version: 1.2
-
> enabled: true' | yamlcat
+
$ yamlcat yaml12_version.yml
version: 1.2
enabled: true
Test 13: Inline - document with comment before content
====================================
-
$ echo '# This is a comment
-
> name: Alice
-
> # Another comment
-
> value: 42' | yamlcat
+
$ yamlcat doc_with_comments.yml
name: Alice
value: 42
Test 14: Inline - document with comment after directive
====================================
-
$ echo '%YAML 1.2
-
> # Comment after directive
-
> ---
-
> key: value' | yamlcat
+
$ yamlcat directive_with_comment.yml
key: value
Test 15: Inline - explicit markers with comments
====================================
-
$ echo '--- # Document start
-
> data: content
-
> # Mid-document comment
-
> more: values
-
> ... # Document end' | yamlcat
+
$ yamlcat start_with_comment.yml
data: content
more: values
···
Test 18: Empty document with explicit markers
====================================
-
$ echo '---
-
> ...' | yamlcat
+
$ yamlcat empty_doc_markers.yml
null
Test 19: Document with only whitespace and markers
====================================
-
$ echo '---
-
>
-
> ...' | yamlcat
+
$ yamlcat empty_doc_with_blank.yml
null
Test 20: Directive followed by content without explicit start
====================================
-
$ echo '%YAML 1.2
-
> simple: document' | yamlcat
+
$ yamlcat directive_without_start.yml
Error: expected document start '---' at line 2, columns 1-1
[1]
+2
tests/cram/empty_both.yml
···
+
empty_seq: []
+
empty_map: {}
+6 -14
tests/cram/empty_collections.t
···
Test: Empty sequence
-
$ echo 'empty_seq: []' | yamlcat
+
$ yamlcat empty_seq.yml
empty_seq: []
Test: Empty mapping
-
$ echo 'empty_map: {}' | yamlcat
+
$ yamlcat empty_map.yml
empty_map: {}
Test: Multiple empty collections
-
$ echo 'seq: []
-
> map: {}
-
> data: value' | yamlcat
+
$ yamlcat multiple_empty.yml
seq: []
map: {}
data: value
Test: Nested empty collections
-
$ echo 'outer:
-
> inner_seq: []
-
> inner_map: {}' | yamlcat
+
$ yamlcat nested_empty.yml
outer:
inner_seq: []
inner_map: {}
Test: Empty collection in sequence
-
$ echo 'items:
-
> - first
-
> - []
-
> - third' | yamlcat
+
$ yamlcat empty_in_seq.yml
items:
- first
- []
···
Test: Verify JSON output is correct (for comparison)
-
$ echo 'empty_seq: []
-
> empty_map: {}' | yamlcat --json
+
$ yamlcat --json empty_both.yml
{"empty_seq": [], "empty_map": {}}
+2
tests/cram/empty_doc_markers.yml
···
+
---
+
...
+3
tests/cram/empty_doc_with_blank.yml
···
+
---
+
+
...
+4
tests/cram/empty_in_seq.yml
···
+
items:
+
- first
+
- []
+
- third
+1
tests/cram/empty_map.yml
···
+
empty_map: {}
+1
tests/cram/empty_seq.yml
···
+
empty_seq: []
+3
tests/cram/folded_block.yml
···
+
text: >
+
line one
+
line two
+3
tests/cram/fruits_list.yml
···
+
- apple
+
- banana
+
- cherry
+3
tests/cram/fruits_mapping.yml
···
+
fruits:
+
- apple
+
- banana
+4
tests/cram/hobbies.yml
···
+
name: Alice
+
hobbies:
+
- reading
+
- coding
+3
tests/cram/literal_block.yml
···
+
text: |
+
line one
+
line two
+3
tests/cram/multiple_empty.yml
···
+
seq: []
+
map: {}
+
data: value
+3
tests/cram/nested_empty.yml
···
+
outer:
+
inner_seq: []
+
inner_map: {}
+5
tests/cram/nested_mappings.yml
···
+
server:
+
host: localhost
+
port: 8080
+
database:
+
name: mydb
+2
tests/cram/person.yml
···
+
name: Alice
+
age: 30
+3
tests/cram/person_jane.yml
···
+
---
+
name: Jane
+
age: 25
+3
tests/cram/person_john.yml
···
+
name: John
+
age: 30
+
city: New York
+2
tests/cram/quoted_strings.yml
···
+
single: 'hello world'
+
double: "hello world"
+1
tests/cram/simple_hello.yml
···
+
hello: world
+5
tests/cram/special_values.yml
···
+
null_val: null
+
bool_true: true
+
bool_false: false
+
number: 42
+
float: 3.14
+4
tests/cram/start_with_comment.yml
···
+
--- # Document start
+
data: content
+
# Mid-document comment
+
more: values
+4
tests/cram/yaml12_version.yml
···
+
%YAML 1.2
+
---
+
version: 1.2
+
enabled: true
+11 -33
tests/cram/yamlcat.t
···
Test yamlcat with simple YAML
-
$ echo 'hello: world' | yamlcat
+
$ yamlcat simple_hello.yml
hello: world
-
$ echo 'name: Alice
-
> age: 30' | yamlcat
+
$ yamlcat person.yml
name: Alice
age: 30
Test nested mappings
-
$ echo 'server:
-
> host: localhost
-
> port: 8080
-
> database:
-
> name: mydb' | yamlcat
+
$ yamlcat nested_mappings.yml
server:
host: localhost
port: 8080
···
Test sequences
-
$ echo '- apple
-
> - banana
-
> - cherry' | yamlcat
+
$ yamlcat fruits_list.yml
- apple
- banana
- cherry
Test mapping with sequence value
-
$ echo 'fruits:
-
> - apple
-
> - banana' | yamlcat
+
$ yamlcat fruits_mapping.yml
fruits:
- apple
- banana
Test flow style output
-
$ echo 'name: Alice
-
> hobbies:
-
> - reading
-
> - coding' | yamlcat --flow
+
$ yamlcat --flow hobbies.yml
{name: Alice, hobbies: [reading, coding]}
Test JSON output
-
$ echo 'name: Alice
-
> age: 30' | yamlcat --json
+
$ yamlcat --json person.yml
{"name": "Alice", "age": 30}
Test seq.yml file (multiline plain scalar)
···
Test special values
-
$ echo 'null_val: null
-
> bool_true: true
-
> bool_false: false
-
> number: 42
-
> float: 3.14' | yamlcat --json
+
$ yamlcat --json special_values.yml
{"null_val": null, "bool_true": true, "bool_false": false, "number": 42, "float": 3.14}
Test quoted strings
-
$ echo 'single: '"'"'hello world'"'"'
-
> double: "hello world"' | yamlcat
+
$ yamlcat quoted_strings.yml
single: hello world
double: hello world
Test literal block scalar
-
$ echo 'text: |
-
> line one
-
> line two' | yamlcat --json
+
$ yamlcat --json literal_block.yml
{"text": "line one\nline two\n"}
Test folded block scalar
-
$ echo 'text: >
-
> line one
-
> line two' | yamlcat --json
+
$ yamlcat --json folded_block.yml
{"text": "line one line two\n"}
Test linuxkit.yml (sequences of mappings)