Skip to content

Commit 9da2f95

Browse files
committed
sgf-parsing: Add individual tests of escaping/whitespace behaviour
11c36323-93fc-495d-bb23-c88ee5844b8c crams too much into one test case. Split it up into multiple ones. In addition, 11c36323-93fc-495d-bb23-c88ee5844b8c has behaviour that violates the specification. The violation is that `\t` and `\n` (written as `"\\t"` and `"\\n"` in the JSON string, respectively), do not hold any sort of special significance in SGF, according to the specification: https://www.red-bean.com/sgf/sgf4.html Reimplement in 08e4b8ba-bb07-4431-a3d9-b1f4cdea6dab. The reimplemented case is mostly as it was when the exercise was originally implemented in exercism/exercism@7a5075b and the reimplemented case is in accordance with the specification. Note that the original case also got it wrong in that newlines should remain newlines; this is corrected in 08e4b8ba-bb07-4431-a3d9-b1f4cdea6dab.
1 parent e1eef73 commit 9da2f95

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

exercises/sgf-parsing/canonical-data.json

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,171 @@
170170
"children": []
171171
}
172172
},
173+
{
174+
"uuid": "28092c06-275f-4b9f-a6be-95663e69d4db",
175+
"description": "within property values, whitespace characters such as tab are converted to spaces",
176+
"property": "parse",
177+
"input": {
178+
"encoded": "(;A[hello\t\tworld])"
179+
},
180+
"expected": {
181+
"properties": {
182+
"A": ["hello world"]
183+
},
184+
"children": []
185+
}
186+
},
187+
{
188+
"uuid": "deaecb9d-b6df-4658-aa92-dcd70f4d472a",
189+
"description": "within property values, newlines remain as newlines",
190+
"property": "parse",
191+
"input": {
192+
"encoded": "(;A[hello\n\nworld])"
193+
},
194+
"expected": {
195+
"properties": {
196+
"A": ["hello\n\nworld"]
197+
},
198+
"children": []
199+
}
200+
},
201+
{
202+
"uuid": "8e4c970e-42d7-440e-bfef-5d7a296868ef",
203+
"description": "Escaped closing bracket in property value is inserted verbatim",
204+
"property": "parse",
205+
"input": {
206+
"encoded": "(;A[\\]])"
207+
},
208+
"expected": {
209+
"properties": {
210+
"A": ["]"]
211+
},
212+
"children": []
213+
}
214+
},
215+
{
216+
"uuid": "cf371fa8-ba4a-45ec-82fb-38668edcb15f",
217+
"description": "Escaped backslash in property value is inserted verbatim",
218+
"property": "parse",
219+
"input": {
220+
"encoded": "(;A[\\\\])"
221+
},
222+
"expected": {
223+
"properties": {
224+
"A": ["\\"]
225+
},
226+
"children": []
227+
}
228+
},
229+
{
230+
"uuid": "dc13ca67-fac0-4b65-b3fe-c584d6a2c523",
231+
"description": "Opening bracket in property value doesn't need to be escaped",
232+
"property": "parse",
233+
"input": {
234+
"encoded": "(;A[x[y\\]z]B[foo];C[bar])"
235+
},
236+
"expected": {
237+
"properties": {
238+
"A": ["x[y]z"],
239+
"B": ["foo"]
240+
},
241+
"children": [
242+
{
243+
"properties": {
244+
"C": ["bar"]
245+
},
246+
"children": []
247+
}
248+
]
249+
}
250+
},
251+
{
252+
"uuid": "a780b97e-8dbb-474e-8f7e-4031902190e8",
253+
"description": "Semicolon in property value doesn't need to be escaped",
254+
"property": "parse",
255+
"input": {
256+
"encoded": "(;A[a;b]B[foo];C[bar])"
257+
},
258+
"expected": {
259+
"properties": {
260+
"A": ["a;b"],
261+
"B": ["foo"]
262+
},
263+
"children": [
264+
{
265+
"properties": {
266+
"C": ["bar"]
267+
},
268+
"children": []
269+
}
270+
]
271+
}
272+
},
273+
{
274+
"uuid": "0b57a79e-8d89-49e5-82b6-2eaaa6b88ed7",
275+
"description": "Parentheses in property value don't need to be escaped",
276+
"property": "parse",
277+
"input": {
278+
"encoded": "(;A[x(y)z]B[foo];C[bar])"
279+
},
280+
"expected": {
281+
"properties": {
282+
"A": ["x(y)z"],
283+
"B": ["foo"]
284+
},
285+
"children": [
286+
{
287+
"properties": {
288+
"C": ["bar"]
289+
},
290+
"children": []
291+
}
292+
]
293+
}
294+
},
295+
{
296+
"uuid": "3a1023d2-7484-4498-8d73-3666bb386e81",
297+
"description": "Escaped newline is in property value converted to nothing at all",
298+
"property": "parse",
299+
"input": {
300+
"encoded": "(;A[hello\\\nworld])"
301+
},
302+
"expected": {
303+
"properties": {
304+
"A": ["helloworld"]
305+
},
306+
"children": []
307+
}
308+
},
309+
{
310+
"uuid": "25abf1a4-5205-46f1-8c72-53273b94d009",
311+
"description": "Escaped t and n in property value are just letters, not whitespace",
312+
"property": "parse",
313+
"input": {
314+
"encoded": "(;A[\\t = t and \\n = n])"
315+
},
316+
"expected": {
317+
"properties": {
318+
"A": ["t = t and n = n"]
319+
},
320+
"children": []
321+
}
322+
},
323+
{
324+
"uuid": "08e4b8ba-bb07-4431-a3d9-b1f4cdea6dab",
325+
"reimplements": "11c36323-93fc-495d-bb23-c88ee5844b8c",
326+
"description": "mixing various kinds of whitespace and escaped characters in property value",
327+
"property": "parse",
328+
"input": {
329+
"encoded": "(;A[\\]b\nc\\\nd\t\te\\\\ \\\n\\]])"
330+
},
331+
"expected": {
332+
"properties": {
333+
"A": ["]b\ncd e\\ ]"]
334+
},
335+
"children": []
336+
}
337+
},
173338
{
174339
"uuid": "11c36323-93fc-495d-bb23-c88ee5844b8c",
175340
"description": "escaped property",

0 commit comments

Comments
 (0)