diff --git a/tests/fixtures/decode/arrays-nested.json b/tests/fixtures/decode/arrays-nested.json index 57ffe90..69e3a40 100644 --- a/tests/fixtures/decode/arrays-nested.json +++ b/tests/fixtures/decode/arrays-nested.json @@ -244,6 +244,63 @@ "shouldError": true, "specSection": "9.4", "minSpecVersion": "4.1" + }, + { + "name": "parses an array of arrays in list-item position", + "input": "[1]:\n - [1]:\n - [1]: 1", + "expected": [ + [ + [ + 1 + ] + ] + ], + "specSection": "9.4" + }, + { + "name": "parses an empty object as the first field of a list-item object", + "input": "items[1]:\n - a:\n b: 1", + "expected": { + "items": [ + { + "a": {}, + "b": 1 + } + ] + }, + "specSection": "10" + }, + { + "name": "parses a tabular array as a later field of a list-item object", + "input": "items[1]:\n - id: 1\n users[2]{id,name}:\n 1,Ada\n 2,Bob", + "expected": { + "items": [ + { + "id": 1, + "users": [ + { + "id": 1, + "name": "Ada" + }, + { + "id": 2, + "name": "Bob" + } + ] + } + ] + }, + "specSection": "10" + }, + { + "name": "parses quoted list item shaped like an inline array header", + "input": "xs[1]:\n - \"[2]: x\"", + "expected": { + "xs": [ + "[2]: x" + ] + }, + "specSection": "9.4" } ] } diff --git a/tests/fixtures/decode/arrays-primitive.json b/tests/fixtures/decode/arrays-primitive.json index e09b87f..fd5f610 100644 --- a/tests/fixtures/decode/arrays-primitive.json +++ b/tests/fixtures/decode/arrays-primitive.json @@ -154,6 +154,19 @@ "": [] }, "specSection": "9.1" + }, + { + "name": "parses quoted key containing escaped quotes and brackets with inline array", + "input": "\"has \\\"[2]\\\" in it\"[3]: 3,4,5", + "expected": { + "has \"[2]\" in it": [ + 3, + 4, + 5 + ] + }, + "specSection": "9.1", + "note": "An escaped quote does not close a quoted key, so the [2] inside it is not a bracket segment" } ] } diff --git a/tests/fixtures/decode/arrays-tabular.json b/tests/fixtures/decode/arrays-tabular.json index 9c18ed9..64830aa 100644 --- a/tests/fixtures/decode/arrays-tabular.json +++ b/tests/fixtures/decode/arrays-tabular.json @@ -217,6 +217,19 @@ "specSection": "14.1", "note": "A declared [N] never truncates a scope", "minSpecVersion": "4.1" + }, + { + "name": "parses quoted leading tabular cell shaped like an inline array header", + "input": "rows[1]{note,id}:\n \"[2]: x\",1", + "expected": { + "rows": [ + { + "note": "[2]: x", + "id": 1 + } + ] + }, + "specSection": "9.3" } ] } diff --git a/tests/fixtures/decode/objects.json b/tests/fixtures/decode/objects.json index 1e42dbf..af52a61 100644 --- a/tests/fixtures/decode/objects.json +++ b/tests/fixtures/decode/objects.json @@ -509,6 +509,35 @@ }, "specSection": "7.4", "minSpecVersion": "4.1" + }, + { + "name": "parses quoted empty string key opening a nested object", + "input": "\"\":\n a: 1", + "expected": { + "": { + "a": 1 + } + }, + "specSection": "8" + }, + { + "name": "parses quoted key shaped like an inline array header", + "input": "\"k[2]: y\": 1", + "expected": { + "k[2]: y": 1 + }, + "specSection": "5.2" + }, + { + "name": "materializes __proto__ array header key as an ordinary own key", + "input": "__proto__[2]: 1,2", + "expected": { + "__proto__": [ + 1, + 2 + ] + }, + "specSection": "15" } ] } diff --git a/tests/fixtures/decode/root-form.json b/tests/fixtures/decode/root-form.json index 32bc71f..6378932 100644 --- a/tests/fixtures/decode/root-form.json +++ b/tests/fixtures/decode/root-form.json @@ -78,6 +78,15 @@ "strict": true }, "specSection": "5" + }, + { + "name": "parses a root primitive after a leading blank line", + "input": "\nhello", + "expected": "hello", + "options": { + "strict": true + }, + "specSection": "5" } ] } diff --git a/tests/fixtures/decode/validation-errors.json b/tests/fixtures/decode/validation-errors.json index e3ad253..5e20b3e 100644 --- a/tests/fixtures/decode/validation-errors.json +++ b/tests/fixtures/decode/validation-errors.json @@ -503,6 +503,69 @@ "specSection": "5.2", "note": "A scalar line outside root primitive position is an error in strict and non-strict mode alike", "minSpecVersion": "4.1" + }, + { + "name": "throws on the removed [#N] length marker in a root header in strict mode", + "input": "[#2]: a,b", + "expected": null, + "shouldError": true, + "options": { + "strict": true + }, + "specSection": "6" + }, + { + "name": "throws on the removed [#N] length marker in a field header in strict mode", + "input": "xs[#2]: a,b", + "expected": null, + "shouldError": true, + "options": { + "strict": true + }, + "specSection": "6" + }, + { + "name": "throws on the removed [#N] length marker in a keyless list-item header in strict mode", + "input": "items[1]:\n - [#2]: a,b", + "expected": null, + "shouldError": true, + "options": { + "strict": true + }, + "specSection": "6" + }, + { + "name": "throws on the removed [#N] length marker in a list-item first-field header in strict mode", + "input": "items[1]:\n - xs[#2]: a,b", + "expected": null, + "shouldError": true, + "options": { + "strict": true + }, + "specSection": "6" + }, + { + "name": "throws on tabular row count mismatch in a later field of a list-item object", + "input": "items[1]:\n - id: 1\n users[2]{id,name}:\n 1,Ada", + "expected": null, + "shouldError": true, + "specSection": "14.1" + }, + { + "name": "throws on a tab after a quoted value's closing quote", + "input": "k: \"a\"\t", + "expected": null, + "shouldError": true, + "specSection": "7.4", + "minSpecVersion": "4.1" + }, + { + "name": "throws on a tab after a quoted key's closing quote", + "input": "\"a\"\t: 1", + "expected": null, + "shouldError": true, + "specSection": "7.4", + "minSpecVersion": "4.1" } ] } diff --git a/tests/fixtures/decode/whitespace.json b/tests/fixtures/decode/whitespace.json index fc22ed3..3667076 100644 --- a/tests/fixtures/decode/whitespace.json +++ b/tests/fixtures/decode/whitespace.json @@ -124,6 +124,33 @@ "specSection": "12", "note": "Trailing spaces are stripped before line classification", "minSpecVersion": "4.1" + }, + { + "name": "keeps a trailing tab in an unquoted value", + "input": "k: v\t", + "expected": { + "k": "v\t" + }, + "specSection": "12" + }, + { + "name": "keeps a tab after a comma delimiter as part of the token", + "input": "items[2]: a,\tb", + "expected": { + "items": [ + "a", + "\tb" + ] + }, + "specSection": "12" + }, + { + "name": "keeps a carriage return inside a line as content", + "input": "a: x\ry", + "expected": { + "a": "x\ry" + }, + "specSection": "12" } ] } diff --git a/tests/fixtures/encode/arrays-nested.json b/tests/fixtures/encode/arrays-nested.json index 69c570e..bc2abc4 100644 --- a/tests/fixtures/encode/arrays-nested.json +++ b/tests/fixtures/encode/arrays-nested.json @@ -127,6 +127,18 @@ "specSection": "9.3", "note": "A keyless fields-bearing header is valid only at the document root", "minSpecVersion": "4.1" + }, + { + "name": "uses list form for an array of arrays in list-item position", + "input": [ + [ + [ + 1 + ] + ] + ], + "expected": "[1]:\n - [1]:\n - [1]: 1", + "specSection": "9.4" } ] } diff --git a/tests/fixtures/encode/arrays-objects.json b/tests/fixtures/encode/arrays-objects.json index ad8342b..c462ded 100644 --- a/tests/fixtures/encode/arrays-objects.json +++ b/tests/fixtures/encode/arrays-objects.json @@ -186,6 +186,19 @@ "specSection": "9.5", "note": "Keyed tabular form is mandated in object-field and root positions, not in a column", "minSpecVersion": "4.1" + }, + { + "name": "places an empty object first field on the hyphen line", + "input": { + "items": [ + { + "a": {}, + "b": 1 + } + ] + }, + "expected": "items[1]:\n - a:\n b: 1", + "specSection": "10" } ] } diff --git a/tests/fixtures/encode/objects.json b/tests/fixtures/encode/objects.json index a63f92c..7441aa4 100644 --- a/tests/fixtures/encode/objects.json +++ b/tests/fixtures/encode/objects.json @@ -292,6 +292,16 @@ }, "expected": "note: \"#x\"", "specSection": "7.2" + }, + { + "name": "encodes empty string key opening a nested object", + "input": { + "": { + "a": 1 + } + }, + "expected": "\"\":\n a: 1", + "specSection": "8" } ] }