@toon-format/spec 1.3.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +15 -3
  3. package/SPEC.md +435 -102
  4. package/VERSIONING.md +1 -14
  5. package/package.json +1 -1
  6. package/tests/README.md +42 -28
  7. package/tests/fixtures/decode/arrays-nested.json +20 -20
  8. package/tests/fixtures/decode/arrays-primitive.json +14 -14
  9. package/tests/fixtures/decode/arrays-tabular.json +28 -5
  10. package/tests/fixtures/decode/blank-lines.json +14 -14
  11. package/tests/fixtures/decode/delimiters.json +46 -29
  12. package/tests/fixtures/decode/indentation-errors.json +16 -29
  13. package/tests/fixtures/decode/numbers.json +142 -0
  14. package/tests/fixtures/decode/objects.json +29 -29
  15. package/tests/fixtures/decode/path-expansion.json +173 -0
  16. package/tests/fixtures/decode/primitives.json +44 -75
  17. package/tests/fixtures/decode/root-form.json +17 -0
  18. package/tests/fixtures/decode/validation-errors.json +29 -9
  19. package/tests/fixtures/decode/whitespace.json +61 -0
  20. package/tests/fixtures/encode/arrays-nested.json +15 -15
  21. package/tests/fixtures/encode/arrays-objects.json +16 -16
  22. package/tests/fixtures/encode/arrays-primitive.json +14 -14
  23. package/tests/fixtures/encode/arrays-tabular.json +8 -8
  24. package/tests/fixtures/encode/delimiters.json +23 -23
  25. package/tests/fixtures/encode/key-folding.json +218 -0
  26. package/tests/fixtures/encode/objects.json +27 -27
  27. package/tests/fixtures/encode/options.json +1 -1
  28. package/tests/fixtures/encode/primitives.json +61 -36
  29. package/tests/fixtures/encode/whitespace.json +18 -3
  30. package/tests/fixtures.schema.json +20 -4
  31. package/tests/fixtures/encode/normalization.json +0 -107
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3",
2
+ "version": "1.4",
3
3
  "category": "encode",
4
4
  "description": "Delimiter options - tab and pipe delimiters, delimiter-aware quoting",
5
5
  "tests": [
@@ -12,7 +12,7 @@
12
12
  "options": {
13
13
  "delimiter": "\t"
14
14
  },
15
- "specSection": "8"
15
+ "specSection": "11"
16
16
  },
17
17
  {
18
18
  "name": "encodes primitive arrays with pipe delimiter",
@@ -23,7 +23,7 @@
23
23
  "options": {
24
24
  "delimiter": "|"
25
25
  },
26
- "specSection": "8"
26
+ "specSection": "11"
27
27
  },
28
28
  {
29
29
  "name": "encodes primitive arrays with comma delimiter",
@@ -34,7 +34,7 @@
34
34
  "options": {
35
35
  "delimiter": ","
36
36
  },
37
- "specSection": "8"
37
+ "specSection": "11"
38
38
  },
39
39
  {
40
40
  "name": "encodes tabular arrays with tab delimiter",
@@ -48,7 +48,7 @@
48
48
  "options": {
49
49
  "delimiter": "\t"
50
50
  },
51
- "specSection": "8"
51
+ "specSection": "11"
52
52
  },
53
53
  {
54
54
  "name": "encodes tabular arrays with pipe delimiter",
@@ -62,7 +62,7 @@
62
62
  "options": {
63
63
  "delimiter": "|"
64
64
  },
65
- "specSection": "8"
65
+ "specSection": "11"
66
66
  },
67
67
  {
68
68
  "name": "encodes nested arrays with tab delimiter",
@@ -73,7 +73,7 @@
73
73
  "options": {
74
74
  "delimiter": "\t"
75
75
  },
76
- "specSection": "8"
76
+ "specSection": "11"
77
77
  },
78
78
  {
79
79
  "name": "encodes nested arrays with pipe delimiter",
@@ -84,7 +84,7 @@
84
84
  "options": {
85
85
  "delimiter": "|"
86
86
  },
87
- "specSection": "8"
87
+ "specSection": "11"
88
88
  },
89
89
  {
90
90
  "name": "encodes root arrays with tab delimiter",
@@ -93,7 +93,7 @@
93
93
  "options": {
94
94
  "delimiter": "\t"
95
95
  },
96
- "specSection": "8"
96
+ "specSection": "11"
97
97
  },
98
98
  {
99
99
  "name": "encodes root arrays with pipe delimiter",
@@ -102,7 +102,7 @@
102
102
  "options": {
103
103
  "delimiter": "|"
104
104
  },
105
- "specSection": "8"
105
+ "specSection": "11"
106
106
  },
107
107
  {
108
108
  "name": "encodes root arrays of objects with tab delimiter",
@@ -111,7 +111,7 @@
111
111
  "options": {
112
112
  "delimiter": "\t"
113
113
  },
114
- "specSection": "8"
114
+ "specSection": "11"
115
115
  },
116
116
  {
117
117
  "name": "encodes root arrays of objects with pipe delimiter",
@@ -120,7 +120,7 @@
120
120
  "options": {
121
121
  "delimiter": "|"
122
122
  },
123
- "specSection": "8"
123
+ "specSection": "11"
124
124
  },
125
125
  {
126
126
  "name": "quotes strings containing tab delimiter",
@@ -131,7 +131,7 @@
131
131
  "options": {
132
132
  "delimiter": "\t"
133
133
  },
134
- "specSection": "8"
134
+ "specSection": "11"
135
135
  },
136
136
  {
137
137
  "name": "quotes strings containing pipe delimiter",
@@ -142,7 +142,7 @@
142
142
  "options": {
143
143
  "delimiter": "|"
144
144
  },
145
- "specSection": "8"
145
+ "specSection": "11"
146
146
  },
147
147
  {
148
148
  "name": "does not quote commas with tab delimiter",
@@ -153,7 +153,7 @@
153
153
  "options": {
154
154
  "delimiter": "\t"
155
155
  },
156
- "specSection": "8"
156
+ "specSection": "11"
157
157
  },
158
158
  {
159
159
  "name": "does not quote commas with pipe delimiter",
@@ -164,7 +164,7 @@
164
164
  "options": {
165
165
  "delimiter": "|"
166
166
  },
167
- "specSection": "8"
167
+ "specSection": "11"
168
168
  },
169
169
  {
170
170
  "name": "quotes tabular values containing comma delimiter",
@@ -178,7 +178,7 @@
178
178
  "options": {
179
179
  "delimiter": ","
180
180
  },
181
- "specSection": "8"
181
+ "specSection": "11"
182
182
  },
183
183
  {
184
184
  "name": "does not quote commas in tabular values with tab delimiter",
@@ -192,7 +192,7 @@
192
192
  "options": {
193
193
  "delimiter": "\t"
194
194
  },
195
- "specSection": "8"
195
+ "specSection": "11"
196
196
  },
197
197
  {
198
198
  "name": "does not quote commas in object values with pipe delimiter",
@@ -203,7 +203,7 @@
203
203
  "options": {
204
204
  "delimiter": "|"
205
205
  },
206
- "specSection": "8"
206
+ "specSection": "11"
207
207
  },
208
208
  {
209
209
  "name": "does not quote commas in object values with tab delimiter",
@@ -214,7 +214,7 @@
214
214
  "options": {
215
215
  "delimiter": "\t"
216
216
  },
217
- "specSection": "8"
217
+ "specSection": "11"
218
218
  },
219
219
  {
220
220
  "name": "quotes nested array values containing pipe delimiter",
@@ -225,7 +225,7 @@
225
225
  "options": {
226
226
  "delimiter": "|"
227
227
  },
228
- "specSection": "8"
228
+ "specSection": "11"
229
229
  },
230
230
  {
231
231
  "name": "quotes nested array values containing tab delimiter",
@@ -236,7 +236,7 @@
236
236
  "options": {
237
237
  "delimiter": "\t"
238
238
  },
239
- "specSection": "8"
239
+ "specSection": "11"
240
240
  },
241
241
  {
242
242
  "name": "preserves ambiguity quoting regardless of delimiter",
@@ -247,7 +247,7 @@
247
247
  "options": {
248
248
  "delimiter": "|"
249
249
  },
250
- "specSection": "8"
250
+ "specSection": "11"
251
251
  }
252
252
  ]
253
253
  }
@@ -0,0 +1,218 @@
1
+ {
2
+ "version": "1.5",
3
+ "category": "encode",
4
+ "description": "Key folding with safe mode, depth control, collision avoidance",
5
+ "tests": [
6
+ {
7
+ "name": "encodes folded chain to primitive (safe mode)",
8
+ "input": {
9
+ "a": {
10
+ "b": {
11
+ "c": 1
12
+ }
13
+ }
14
+ },
15
+ "expected": "a.b.c: 1",
16
+ "options": {
17
+ "keyFolding": "safe"
18
+ },
19
+ "specSection": "13.4"
20
+ },
21
+ {
22
+ "name": "encodes folded chain with inline array",
23
+ "input": {
24
+ "data": {
25
+ "meta": {
26
+ "items": ["x", "y"]
27
+ }
28
+ }
29
+ },
30
+ "expected": "data.meta.items[2]: x,y",
31
+ "options": {
32
+ "keyFolding": "safe"
33
+ },
34
+ "specSection": "13.4"
35
+ },
36
+ {
37
+ "name": "encodes folded chain with tabular array",
38
+ "input": {
39
+ "a": {
40
+ "b": {
41
+ "items": [
42
+ { "id": 1, "name": "A" },
43
+ { "id": 2, "name": "B" }
44
+ ]
45
+ }
46
+ }
47
+ },
48
+ "expected": "a.b.items[2]{id,name}:\n 1,A\n 2,B",
49
+ "options": {
50
+ "keyFolding": "safe"
51
+ },
52
+ "specSection": "13.4"
53
+ },
54
+ {
55
+ "name": "skips folding when segment requires quotes (safe mode)",
56
+ "input": {
57
+ "data": {
58
+ "full-name": {
59
+ "x": 1
60
+ }
61
+ }
62
+ },
63
+ "expected": "data:\n \"full-name\":\n x: 1",
64
+ "options": {
65
+ "keyFolding": "safe"
66
+ },
67
+ "specSection": "13.4"
68
+ },
69
+ {
70
+ "name": "skips folding on sibling literal-key collision (safe mode)",
71
+ "input": {
72
+ "data": {
73
+ "meta": {
74
+ "items": [1, 2]
75
+ }
76
+ },
77
+ "data.meta.items": "literal"
78
+ },
79
+ "expected": "data:\n meta:\n items[2]: 1,2\ndata.meta.items: literal",
80
+ "options": {
81
+ "keyFolding": "safe"
82
+ },
83
+ "specSection": "13.4",
84
+ "note": "Collision avoidance: folding would create duplicate key"
85
+ },
86
+ {
87
+ "name": "encodes partial folding with flattenDepth=2",
88
+ "input": {
89
+ "a": {
90
+ "b": {
91
+ "c": {
92
+ "d": 1
93
+ }
94
+ }
95
+ }
96
+ },
97
+ "expected": "a.b:\n c:\n d: 1",
98
+ "options": {
99
+ "keyFolding": "safe",
100
+ "flattenDepth": 2
101
+ },
102
+ "specSection": "13.4"
103
+ },
104
+ {
105
+ "name": "encodes full chain with flattenDepth=Infinity (default)",
106
+ "input": {
107
+ "a": {
108
+ "b": {
109
+ "c": {
110
+ "d": 1
111
+ }
112
+ }
113
+ }
114
+ },
115
+ "expected": "a.b.c.d: 1",
116
+ "options": {
117
+ "keyFolding": "safe"
118
+ },
119
+ "specSection": "13.4"
120
+ },
121
+ {
122
+ "name": "encodes standard nesting with flattenDepth=0 (no folding)",
123
+ "input": {
124
+ "a": {
125
+ "b": {
126
+ "c": 1
127
+ }
128
+ }
129
+ },
130
+ "expected": "a:\n b:\n c: 1",
131
+ "options": {
132
+ "keyFolding": "safe",
133
+ "flattenDepth": 0
134
+ },
135
+ "specSection": "13.4",
136
+ "note": "flattenDepth=0 disables all folding"
137
+ },
138
+ {
139
+ "name": "encodes standard nesting with flattenDepth=1 (no practical effect)",
140
+ "input": {
141
+ "a": {
142
+ "b": {
143
+ "c": 1
144
+ }
145
+ }
146
+ },
147
+ "expected": "a:\n b:\n c: 1",
148
+ "options": {
149
+ "keyFolding": "safe",
150
+ "flattenDepth": 1
151
+ },
152
+ "specSection": "13.4",
153
+ "note": "flattenDepth=1 has no practical folding effect (requires at least 2 segments)"
154
+ },
155
+ {
156
+ "name": "encodes standard nesting with keyFolding=off (baseline)",
157
+ "input": {
158
+ "a": {
159
+ "b": {
160
+ "c": 1
161
+ }
162
+ }
163
+ },
164
+ "expected": "a:\n b:\n c: 1",
165
+ "options": {
166
+ "keyFolding": "off"
167
+ },
168
+ "specSection": "13.4"
169
+ },
170
+ {
171
+ "name": "encodes folded chain ending with empty object",
172
+ "input": {
173
+ "a": {
174
+ "b": {
175
+ "c": {}
176
+ }
177
+ }
178
+ },
179
+ "expected": "a.b.c:",
180
+ "options": {
181
+ "keyFolding": "safe"
182
+ },
183
+ "specSection": "13.4"
184
+ },
185
+ {
186
+ "name": "stops folding at array boundary (not single-key object)",
187
+ "input": {
188
+ "a": {
189
+ "b": [1, 2]
190
+ }
191
+ },
192
+ "expected": "a.b[2]: 1,2",
193
+ "options": {
194
+ "keyFolding": "safe"
195
+ },
196
+ "specSection": "13.4"
197
+ },
198
+ {
199
+ "name": "encodes partial fold preserving sibling field order",
200
+ "input": {
201
+ "folded": {
202
+ "path": {
203
+ "value": 1
204
+ }
205
+ },
206
+ "normal": 2,
207
+ "nested": {
208
+ "x": 3
209
+ }
210
+ },
211
+ "expected": "folded.path.value: 1\nnormal: 2\nnested:\n x: 3",
212
+ "options": {
213
+ "keyFolding": "safe"
214
+ },
215
+ "specSection": "13.4"
216
+ }
217
+ ]
218
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3",
2
+ "version": "1.4",
3
3
  "category": "encode",
4
4
  "description": "Object encoding - simple objects, nested objects, key encoding",
5
5
  "tests": [
@@ -11,7 +11,7 @@
11
11
  "active": true
12
12
  },
13
13
  "expected": "id: 123\nname: Ada\nactive: true",
14
- "specSection": "6"
14
+ "specSection": "8"
15
15
  },
16
16
  {
17
17
  "name": "encodes null values in objects",
@@ -20,13 +20,13 @@
20
20
  "value": null
21
21
  },
22
22
  "expected": "id: 123\nvalue: null",
23
- "specSection": "6"
23
+ "specSection": "8"
24
24
  },
25
25
  {
26
26
  "name": "encodes empty objects as empty string",
27
27
  "input": {},
28
28
  "expected": "",
29
- "specSection": "6"
29
+ "specSection": "8"
30
30
  },
31
31
  {
32
32
  "name": "quotes string value with colon",
@@ -34,7 +34,7 @@
34
34
  "note": "a:b"
35
35
  },
36
36
  "expected": "note: \"a:b\"",
37
- "specSection": "6"
37
+ "specSection": "7.2"
38
38
  },
39
39
  {
40
40
  "name": "quotes string value with comma",
@@ -42,7 +42,7 @@
42
42
  "note": "a,b"
43
43
  },
44
44
  "expected": "note: \"a,b\"",
45
- "specSection": "6"
45
+ "specSection": "7.2"
46
46
  },
47
47
  {
48
48
  "name": "quotes string value with newline",
@@ -50,7 +50,7 @@
50
50
  "text": "line1\nline2"
51
51
  },
52
52
  "expected": "text: \"line1\\nline2\"",
53
- "specSection": "6"
53
+ "specSection": "7.2"
54
54
  },
55
55
  {
56
56
  "name": "quotes string value with embedded quotes",
@@ -58,7 +58,7 @@
58
58
  "text": "say \"hello\""
59
59
  },
60
60
  "expected": "text: \"say \\\"hello\\\"\"",
61
- "specSection": "6"
61
+ "specSection": "7.2"
62
62
  },
63
63
  {
64
64
  "name": "quotes string value with leading space",
@@ -66,7 +66,7 @@
66
66
  "text": " padded "
67
67
  },
68
68
  "expected": "text: \" padded \"",
69
- "specSection": "6"
69
+ "specSection": "7.2"
70
70
  },
71
71
  {
72
72
  "name": "quotes string value with only spaces",
@@ -74,7 +74,7 @@
74
74
  "text": " "
75
75
  },
76
76
  "expected": "text: \" \"",
77
- "specSection": "6"
77
+ "specSection": "7.2"
78
78
  },
79
79
  {
80
80
  "name": "quotes string value that looks like true",
@@ -82,7 +82,7 @@
82
82
  "v": "true"
83
83
  },
84
84
  "expected": "v: \"true\"",
85
- "specSection": "6"
85
+ "specSection": "7.2"
86
86
  },
87
87
  {
88
88
  "name": "quotes string value that looks like number",
@@ -90,7 +90,7 @@
90
90
  "v": "42"
91
91
  },
92
92
  "expected": "v: \"42\"",
93
- "specSection": "6"
93
+ "specSection": "7.2"
94
94
  },
95
95
  {
96
96
  "name": "quotes string value that looks like negative decimal",
@@ -98,7 +98,7 @@
98
98
  "v": "-7.5"
99
99
  },
100
100
  "expected": "v: \"-7.5\"",
101
- "specSection": "6"
101
+ "specSection": "7.2"
102
102
  },
103
103
  {
104
104
  "name": "quotes key with colon",
@@ -106,7 +106,7 @@
106
106
  "order:id": 7
107
107
  },
108
108
  "expected": "\"order:id\": 7",
109
- "specSection": "6"
109
+ "specSection": "7.3"
110
110
  },
111
111
  {
112
112
  "name": "quotes key with brackets",
@@ -114,7 +114,7 @@
114
114
  "[index]": 5
115
115
  },
116
116
  "expected": "\"[index]\": 5",
117
- "specSection": "6"
117
+ "specSection": "7.3"
118
118
  },
119
119
  {
120
120
  "name": "quotes key with braces",
@@ -122,7 +122,7 @@
122
122
  "{key}": 5
123
123
  },
124
124
  "expected": "\"{key}\": 5",
125
- "specSection": "6"
125
+ "specSection": "7.3"
126
126
  },
127
127
  {
128
128
  "name": "quotes key with comma",
@@ -130,7 +130,7 @@
130
130
  "a,b": 1
131
131
  },
132
132
  "expected": "\"a,b\": 1",
133
- "specSection": "6"
133
+ "specSection": "7.3"
134
134
  },
135
135
  {
136
136
  "name": "quotes key with spaces",
@@ -138,7 +138,7 @@
138
138
  "full name": "Ada"
139
139
  },
140
140
  "expected": "\"full name\": Ada",
141
- "specSection": "6"
141
+ "specSection": "7.3"
142
142
  },
143
143
  {
144
144
  "name": "quotes key with leading hyphen",
@@ -146,7 +146,7 @@
146
146
  "-lead": 1
147
147
  },
148
148
  "expected": "\"-lead\": 1",
149
- "specSection": "6"
149
+ "specSection": "7.3"
150
150
  },
151
151
  {
152
152
  "name": "quotes key with leading and trailing spaces",
@@ -154,7 +154,7 @@
154
154
  " a ": 1
155
155
  },
156
156
  "expected": "\" a \": 1",
157
- "specSection": "6"
157
+ "specSection": "7.3"
158
158
  },
159
159
  {
160
160
  "name": "quotes numeric key",
@@ -162,7 +162,7 @@
162
162
  "123": "x"
163
163
  },
164
164
  "expected": "\"123\": x",
165
- "specSection": "6"
165
+ "specSection": "7.3"
166
166
  },
167
167
  {
168
168
  "name": "quotes empty string key",
@@ -170,7 +170,7 @@
170
170
  "": 1
171
171
  },
172
172
  "expected": "\"\": 1",
173
- "specSection": "6"
173
+ "specSection": "7.3"
174
174
  },
175
175
  {
176
176
  "name": "escapes newline in key",
@@ -178,7 +178,7 @@
178
178
  "line\nbreak": 1
179
179
  },
180
180
  "expected": "\"line\\nbreak\": 1",
181
- "specSection": "6"
181
+ "specSection": "7.1"
182
182
  },
183
183
  {
184
184
  "name": "escapes tab in key",
@@ -186,7 +186,7 @@
186
186
  "tab\there": 2
187
187
  },
188
188
  "expected": "\"tab\\there\": 2",
189
- "specSection": "6"
189
+ "specSection": "7.1"
190
190
  },
191
191
  {
192
192
  "name": "escapes quotes in key",
@@ -194,7 +194,7 @@
194
194
  "he said \"hi\"": 1
195
195
  },
196
196
  "expected": "\"he said \\\"hi\\\"\": 1",
197
- "specSection": "6"
197
+ "specSection": "7.1"
198
198
  },
199
199
  {
200
200
  "name": "encodes deeply nested objects",
@@ -206,7 +206,7 @@
206
206
  }
207
207
  },
208
208
  "expected": "a:\n b:\n c: deep",
209
- "specSection": "6"
209
+ "specSection": "8"
210
210
  },
211
211
  {
212
212
  "name": "encodes empty nested object",
@@ -214,7 +214,7 @@
214
214
  "user": {}
215
215
  },
216
216
  "expected": "user:",
217
- "specSection": "6"
217
+ "specSection": "8"
218
218
  }
219
219
  ]
220
220
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3",
2
+ "version": "1.4",
3
3
  "category": "encode",
4
4
  "description": "Encoding options - lengthMarker option and combinations with delimiters",
5
5
  "tests": [