@@ -241,13 +241,25 @@ defmodule RDF.Turtle.DecoderTest do
241
241
end
242
242
243
243
describe "quoted literals" do
244
- test "an untyped string literal" do
244
+ test "an untyped string literal with double quotes " do
245
245
assert Turtle.Decoder . decode! ( """
246
246
<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/realname> "Peter Parker" .
247
247
""" ) == Graph . new ( { EX . spiderman ( ) , P . realname ( ) , RDF . literal ( "Peter Parker" ) } )
248
248
end
249
249
250
- test "an untyped long quoted string literal" do
250
+ test "an untyped string literal with single quotes" do
251
+ assert Turtle.Decoder . decode! ( """
252
+ <http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/realname> 'Peter Parker' .
253
+ """ ) == Graph . new ( { EX . spiderman ( ) , P . realname ( ) , RDF . literal ( "Peter Parker" ) } )
254
+ end
255
+
256
+ test "an untyped long double quoted string literal" do
257
+ assert Turtle.Decoder . decode! ( """
258
+ <http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/realname> \" ""Peter Parker\" "" .
259
+ """ ) == Graph . new ( { EX . spiderman ( ) , P . realname ( ) , RDF . literal ( "Peter Parker" ) } )
260
+ end
261
+
262
+ test "an untyped long single quoted string literal" do
251
263
assert Turtle.Decoder . decode! ( """
252
264
<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/realname> '''Peter Parker''' .
253
265
""" ) == Graph . new ( { EX . spiderman ( ) , P . realname ( ) , RDF . literal ( "Peter Parker" ) } )
@@ -284,6 +296,80 @@ defmodule RDF.Turtle.DecoderTest do
284
296
end
285
297
end
286
298
299
+ describe "escaping" do
300
+ test "STRING_LITERAL_QUOTE" do
301
+ assert Turtle.Decoder . decode! ( """
302
+ <http://example.org/#S> <http://example.org/#p> "String with \\ t tab and \\ n newline" .
303
+ """ ) == Graph . new ( { EX.S , EX . p ( ) , RDF . literal ( "String with \t tab and \n newline" ) } )
304
+
305
+ assert Turtle.Decoder . decode! ( """
306
+ <http://example.org/#S> <http://example.org/#p> "String with Unicode: \\ u00A9" .
307
+ """ ) == Graph . new ( { EX.S , EX . p ( ) , RDF . literal ( "String with Unicode: ©" ) } )
308
+
309
+ assert Turtle.Decoder . decode! ( """
310
+ <http://example.org/#S> <http://example.org/#p> "String with \\ "quotes\\ "" .
311
+ """ ) == Graph . new ( { EX.S , EX . p ( ) , RDF . literal ( "String with \" quotes\" " ) } )
312
+
313
+ assert Turtle.Decoder . decode! ( """
314
+ <http://example.org/#S> <http://example.org/#p> "String with \\ b backspace and \\ f form feed" .
315
+ """ ) ==
316
+ Graph . new ( { EX.S , EX . p ( ) , RDF . literal ( "String with \b backspace and \f form feed" ) } )
317
+
318
+ assert Turtle.Decoder . decode! ( """
319
+ <http://example.org/#S> <http://example.org/#p> "String with \\ \\ \\ \\ multiple backslashes" .
320
+ """ ) ==
321
+ Graph . new ( { EX.S , EX . p ( ) , RDF . literal ( "String with \\ \\ multiple backslashes" ) } )
322
+ end
323
+
324
+ test "STRING_LITERAL_SINGLE_QUOTE" do
325
+ assert Turtle.Decoder . decode! ( """
326
+ <http://example.org/#S> <http://example.org/#p> 'String with \\ t tab and \\ n newline' .
327
+ """ ) == Graph . new ( { EX.S , EX . p ( ) , RDF . literal ( "String with \t tab and \n newline" ) } )
328
+
329
+ assert Turtle.Decoder . decode! ( """
330
+ <http://example.org/#S> <http://example.org/#p> 'String with Unicode: \\ u00A9' .
331
+ """ ) == Graph . new ( { EX.S , EX . p ( ) , RDF . literal ( "String with Unicode: ©" ) } )
332
+
333
+ assert Turtle.Decoder . decode! ( """
334
+ <http://example.org/#S> <http://example.org/#p> 'String with \\ 'quotes\\ '' .
335
+ """ ) == Graph . new ( { EX.S , EX . p ( ) , RDF . literal ( "String with 'quotes'" ) } )
336
+ end
337
+
338
+ test "STRING_LITERAL_LONG_QUOTE" do
339
+ assert Turtle.Decoder . decode! ( """
340
+ <http://example.org/#S> <http://example.org/#p> \" ""Long string with "embedded quotes" and ""escaped quotes"\\ \" """ .
341
+ """ ) ==
342
+ Graph . new (
343
+ { EX.S , EX . p ( ) ,
344
+ RDF . literal ( "Long string with \" embedded quotes\" and \" \" escaped quotes\" \" " ) }
345
+ )
346
+
347
+ assert Turtle.Decoder . decode! ( """
348
+ <http://example.org/#S> <http://example.org/#p> \" \" \" Long string ending with quote\\ \" \" \" \" .
349
+ """ ) == Graph . new ( { EX.S , EX . p ( ) , RDF . literal ( "Long string ending with quote\" " ) } )
350
+ end
351
+
352
+ test "STRING_LITERAL_LONG_SINGLE_QUOTE" do
353
+ assert Turtle.Decoder . decode! ( """
354
+ <http://example.org/#S> <http://example.org/#p> '''Long string
355
+ with multiple
356
+ lines''' .
357
+ """ ) == Graph . new ( { EX.S , EX . p ( ) , RDF . literal ( "Long string\n with multiple\n lines" ) } )
358
+
359
+ assert Turtle.Decoder . decode! ( """
360
+ <http://example.org/#S> <http://example.org/#p> '''Long string with 'embedded quotes' and ''escaped quotes'\\ '''' .
361
+ """ ) ==
362
+ Graph . new (
363
+ { EX.S , EX . p ( ) ,
364
+ RDF . literal ( "Long string with 'embedded quotes' and ''escaped quotes''" ) }
365
+ )
366
+
367
+ assert Turtle.Decoder . decode! ( """
368
+ <http://example.org/#S> <http://example.org/#p> '''Long string ending with quote\\ '''' .
369
+ """ ) == Graph . new ( { EX.S , EX . p ( ) , RDF . literal ( "Long string ending with quote'" ) } )
370
+ end
371
+ end
372
+
287
373
describe "shorthand literals" do
288
374
test "boolean" do
289
375
assert Turtle.Decoder . decode! ( """
0 commit comments