Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions tests/fixtures/decode/arrays-nested.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"specSection": "9.4"
},
{
"name": "parses list items whose first field is a tabular array",
"input": "items[1]:\n - users[2]{id,name}:\n 1,Ada\n 2,Bob\n status: active",
"name": "parses list items whose first field is a tabular array, with and without sibling fields",
"input": "items[2]:\n - users[2]{id,name}:\n 1,Ada\n 2,Bob\n status: active\n - users[2]{id,name}:\n 3,Cy\n 4,Dee",
"expected": {
"items": [
{
Expand All @@ -62,26 +62,17 @@
{ "id": 2, "name": "Bob" }
],
"status": "active"
}
]
},
"specSection": "10",
"note": "Canonical encoding: tabular header on hyphen line, rows at depth +2, sibling fields at depth +1"
},
{
"name": "parses single-field list-item object with tabular array",
"input": "items[1]:\n - users[2]{id,name}:\n 1,Ada\n 2,Bob",
"expected": {
"items": [
},
{
"users": [
{ "id": 1, "name": "Ada" },
{ "id": 2, "name": "Bob" }
{ "id": 3, "name": "Cy" },
{ "id": 4, "name": "Dee" }
]
}
]
},
"specSection": "10"
"specSection": "10",
"note": "Canonical encoding: tabular header on hyphen line, rows at depth +2, sibling fields at depth +1"
},
{
"name": "parses a legacy [0] header as a later field of a list-item object",
Expand Down
19 changes: 3 additions & 16 deletions tests/fixtures/decode/arrays-tabular.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@
"specSection": "9.3"
},
{
"name": "applies LWW for duplicate field names in non-strict mode",
"input": "items[1]{a,a}:\n 1,2",
"name": "applies LWW for duplicate field names, bare or grouped, in non-strict mode",
"input": "items[1]{a,a,b,b{x}}:\n 1,2,3,4",
"expected": {
"items": [
{ "a": 2 }
{ "a": 2, "b": { "x": 4 } }
]
},
"options": {
Expand All @@ -161,19 +161,6 @@
"specSection": "14.3",
"note": "Duplicate field names yield duplicate sibling keys per row; non-strict resolves last-write-wins"
},
{
"name": "applies LWW when a bare field and a nested group share a name in non-strict mode",
"input": "items[1]{a,a{x}}:\n 1,2",
"expected": {
"items": [
{ "a": { "x": 2 } }
]
},
"options": {
"strict": false
},
"specSection": "14.3"
},
{
"name": "accepts a field name outside the encoder unquoted-key pattern",
"input": "items[1]{2key}:\n 1",
Expand Down
15 changes: 2 additions & 13 deletions tests/fixtures/decode/blank-lines.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@
},
{
"name": "ignores blank lines inside list array when strict=false",
"input": "items[2]:\n - a\n\n - b",
"input": "items[3]:\n - a\n\n - b\n\n\n - c",
"expected": {
"items": ["a", "b"]
"items": ["a", "b", "c"]
},
"options": {
"strict": false
Expand All @@ -160,17 +160,6 @@
},
"specSection": "12"
},
{
"name": "ignores multiple blank lines in arrays when strict=false",
"input": "items[2]:\n - a\n\n\n - b",
"expected": {
"items": ["a", "b"]
},
"options": {
"strict": false
},
"specSection": "12"
},
{
"name": "throws on blank line between list items after nested tabular rows",
"input": "outer[2]:\n - inner[2]{a}:\n 1\n 2\n\n - x",
Expand Down
35 changes: 6 additions & 29 deletions tests/fixtures/decode/comments.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Comment lines – full-line decode-side comments stripped before structural interpretation",
"tests": [
{
"name": "strips comment line between tabular rows without terminating rows",
"input": "items[2]{id,name}:\n 1,Ada\n # note\n 2,Bob",
"name": "strips comment lines after the header and between tabular rows",
"input": "items[2]{id,name}:\n # leading\n 1,Ada\n # note\n 2,Bob",
"expected": {
"items": [
{
Expand All @@ -19,22 +19,7 @@
]
},
"specSection": "5.1",
"note": "The comment is not counted as a row and does not end the tabular scope"
},
{
"name": "strips comment line between header and first row",
"input": "items[2]{id}:\n # leading\n 1\n 2",
"expected": {
"items": [
{
"id": 1
},
{
"id": 2
}
]
},
"specSection": "5.1"
"note": "Comments are not counted as rows and do not end the tabular scope"
},
{
"name": "strips comment line whose indentation is not a multiple of indentSize",
Expand Down Expand Up @@ -175,18 +160,10 @@
"note": "\"#\" is not the line's first non-space character; comments are full-line only"
},
{
"name": "parses hash after key-value colon as string value",
"input": "note: #x",
"expected": {
"note": "#x"
},
"specSection": "5.1",
"note": "No inline comments; the unquoted token decodes as the string #x"
},
{
"name": "parses hash mid-value as data, not a trailing comment",
"input": "msg: hello # world",
"name": "parses hash after a key-value colon or mid-value as data, not an inline comment",
"input": "note: #x\nmsg: hello # world",
"expected": {
"note": "#x",
"msg": "hello # world"
},
"specSection": "5.1"
Expand Down
21 changes: 4 additions & 17 deletions tests/fixtures/decode/indentation-errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,12 @@
"specSection": "12"
},
{
"name": "accepts non-multiple indentation when strict=false",
"input": "a:\n b: 1\n c: 2",
"expected": {
"a": { "b": 1, "c": 2 }
},
"options": {
"indentSize": 2,
"strict": false
},
"specSection": "12"
},
{
"name": "accepts deeply nested non-multiples when strict=false",
"input": "a:\n b:\n c: 1",
"name": "accepts non-multiple indentation at nested depths when strict=false",
"input": "a:\n b:\n c: 1\n d: 2",
"expected": {
"a": {
"b": {
"c": 1
}
"b": { "c": 1 },
"d": 2
}
},
"options": {
Expand Down
64 changes: 14 additions & 50 deletions tests/fixtures/decode/numbers.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,25 @@
"specSection": "4"
},
{
"name": "parses negative number with positive exponent",
"input": "value: -1E+03",
"name": "parses exponent forms in either case with optional exponent sign",
"input": "a: -1E+03\nb: 2.5e2\nc: 3E-02",
"expected": {
"value": -1000
},
"specSection": "4"
},
{
"name": "parses lowercase exponent",
"input": "value: 2.5e2",
"expected": {
"value": 250
},
"specSection": "4"
},
{
"name": "parses uppercase exponent with negative sign",
"input": "value: 3E-02",
"expected": {
"value": 0.03
"a": -1000,
"b": 250,
"c": 0.03
},
"specSection": "4"
},
{
"name": "parses negative zero as zero",
"input": "value: -0",
"input": "a: -0\nb: -0.0",
"expected": {
"value": 0
"a": 0,
"b": 0
},
"specSection": "4",
"note": "Most host environments do not distinguish -0 from 0"
},
{
"name": "parses negative zero with fractional part",
"input": "value: -0.0",
"expected": {
"value": 0
},
"specSection": "4"
},
{
"name": "parses array with mixed numeric forms",
"input": "nums[5]: 42,-1E+03,1.5000,-0,2.5e2",
Expand Down Expand Up @@ -101,30 +80,15 @@
"specSection": "4"
},
{
"name": "treats bare fraction without integer part as string",
"input": "value: .5",
"expected": {
"value": ".5"
},
"specSection": "4",
"note": "Outside the number grammar, so a host parser would read 0.5 and corrupt the round-trip"
},
{
"name": "treats integer with trailing dot as string",
"input": "value: 1.",
"expected": {
"value": "1."
},
"specSection": "4"
},
{
"name": "treats leading-plus integer as string",
"input": "value: +1",
"name": "treats bare-fraction, trailing-dot, and leading-plus tokens as strings",
"input": "a: .5\nb: 1.\nc: +1",
"expected": {
"value": "+1"
"a": ".5",
"b": "1.",
"c": "+1"
},
"specSection": "4",
"note": "The grammar admits only an optional leading minus, so +1 stays a string"
"note": "Outside the number grammar, so a host number parser would corrupt the round-trip"
},
{
"name": "treats leading-plus tokens in array as strings",
Expand Down
35 changes: 10 additions & 25 deletions tests/fixtures/decode/objects-keyed.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,14 @@
"specSection": "9.5"
},
{
"name": "parses keyed headers with the pipe delimiter",
"input": "servers[2:|]{host|port}:\n alpha: a|8080\n beta: b|9090",
"name": "parses keyed headers with the pipe and tab delimiters",
"input": "pipe[2:|]{host|port}:\n alpha: a|8080\n beta: b|9090\ntab[2:\t]{host\tport}:\n alpha: a\t8080\n beta: b\t9090",
"expected": {
"servers": {
"pipe": {
"alpha": { "host": "a", "port": 8080 },
"beta": { "host": "b", "port": 9090 }
}
},
"specSection": "9.5"
},
{
"name": "parses keyed headers with the tab delimiter",
"input": "servers[2:\t]{host\tport}:\n alpha: a\t8080\n beta: b\t9090",
"expected": {
"servers": {
},
"tab": {
"alpha": { "host": "a", "port": 8080 },
"beta": { "host": "b", "port": 9090 }
}
Expand Down Expand Up @@ -93,24 +86,16 @@
"note": "A keyed scope ends only by dedent or end of input"
},
{
"name": "splits an entry row at its first unquoted colon when a delimiter precedes it",
"input": "m[1:]{x}:\n a,b: 5",
"expected": {
"m": { "a,b": { "x": 5 } }
},
"specSection": "9.5",
"note": "The colon split comes before the delimiter split, so the delimiter before the colon is part of the entry key"
},
{
"name": "splits an entry row at its first unquoted colon before delimiter splitting",
"input": "m[1:]{v}:\n k[2]: 5",
"name": "splits an entry row at its first unquoted colon before delimiter or header parsing",
"input": "m[2:]{v}:\n a,b: 5\n k[2]: 6",
"expected": {
"m": {
"k[2]": { "v": 5 }
"a,b": { "v": 5 },
"k[2]": { "v": 6 }
}
},
"specSection": "9.5",
"note": "The token before the first unquoted colon is the entry key, accepted as a literal key per §7.4 even though an encoder would quote it"
"note": "The entry key is everything before the first unquoted colon, taken as a literal key per §7.4 even though an encoder would quote it"
},
{
"name": "decodes the cell token [] as a string, not an empty array",
Expand Down
Loading
Loading