Debian Codegraph @

test/Literal-test.js

raw
1 import { Literal, NamedNode, Term } from '../src/';
2
3 describe('Literal', () => {
4 describe('The Literal module', () => {
5 it('should be a function', () => {
6 Literal.should.be.a('function');
7 });
8
9 it('should be a Literal constructor', () => {
10 new Literal().should.be.an.instanceof(Literal);
11 });
12
13 it('should be a Term constructor', () => {
14 new Literal().should.be.an.instanceof(Term);
15 });
16 });
17
18 describe('A Literal instance created from the empty string without language or datatype', () => {
19 let literal;
20 before(() => { literal = new Literal('""'); });
21
22 it('should be a Literal', () => {
23 literal.should.be.an.instanceof(Literal);
24 });
25
26 it('should be a Term', () => {
27 literal.should.be.an.instanceof(Term);
28 });
29
30 it('should have term type "Literal"', () => {
31 literal.termType.should.equal('Literal');
32 });
33
34 it('should have the empty string as value', () => {
35 literal.should.have.property('value', '');
36 });
37
38 it('should have the empty string as language', () => {
39 literal.should.have.property('language', '');
40 });
41
42 it('should have xsd:string as datatype', () => {
43 literal.should.have.property('datatype');
44 literal.datatype.should.be.an.instanceof(NamedNode);
45 literal.datatype.value.should.equal('http://www.w3.org/2001/XMLSchema#string');
46 });
47
48 it('should have the quoted empty string as id', () => {
49 literal.should.have.property('id', '""');
50 });
51
52 it('should equal a Literal instance with the same value', () => {
53 literal.equals(new Literal('""')).should.be.true;
54 });
55
56 it('should equal an object with the same term type, value, language, and datatype', () => {
57 literal.equals({
58 termType: 'Literal',
59 value: '',
60 language: '',
61 datatype: { value: 'http://www.w3.org/2001/XMLSchema#string', termType: 'NamedNode' },
62 }).should.be.true;
63 });
64
65 it('should not equal a falsy object', () => {
66 literal.equals(null).should.be.false;
67 });
68
69 it('should not equal a Literal instance with a non-empty value', () => {
70 literal.equals(new Literal('"x"')).should.be.false;
71 });
72
73 it('should not equal an object with the same term type but a different value', () => {
74 literal.equals({
75 termType: 'Literal',
76 value: 'x',
77 language: '',
78 datatype: { value: 'http://www.w3.org/2001/XMLSchema#string', termType: 'NamedNode' },
79 }).should.be.false;
80 });
81
82 it('should not equal an object with the same term type but a different language', () => {
83 literal.equals({
84 termType: 'Literal',
85 value: '',
86 language: 'en',
87 datatype: { value: 'http://www.w3.org/2001/XMLSchema#string', termType: 'NamedNode' },
88 }).should.be.false;
89 });
90
91 it('should not equal an object with the same term type but a different datatype', () => {
92 literal.equals({
93 termType: 'Literal',
94 value: '',
95 language: '',
96 datatype: { value: 'other', termType: 'NamedNode' },
97 }).should.be.false;
98 });
99
100 it('should not equal an object with a different term type', () => {
101 literal.equals({
102 termType: 'NamedNode',
103 value: '',
104 language: '',
105 datatype: { value: 'http://www.w3.org/2001/XMLSchema#string', termType: 'NamedNode' },
106 }).should.be.false;
107 });
108
109 it('should provide a JSON representation', () => {
110 literal.toJSON().should.deep.equal({
111 termType: 'Literal',
112 value: '',
113 language: '',
114 datatype: {
115 termType: 'NamedNode',
116 value: 'http://www.w3.org/2001/XMLSchema#string',
117 },
118 });
119 });
120 });
121
122 describe('A Literal instance created from a string without language or datatype', () => {
123 let literal;
124 before(() => { literal = new Literal('"my @^^ string"'); });
125
126 it('should be a Literal', () => {
127 literal.should.be.an.instanceof(Literal);
128 });
129
130 it('should be a Term', () => {
131 literal.should.be.an.instanceof(Term);
132 });
133
134 it('should have term type "Literal"', () => {
135 literal.termType.should.equal('Literal');
136 });
137
138 it('should have the text value as value', () => {
139 literal.should.have.property('value', 'my @^^ string');
140 });
141
142 it('should have the empty string as language', () => {
143 literal.should.have.property('language', '');
144 });
145
146 it('should have xsd:string as datatype', () => {
147 literal.should.have.property('datatype');
148 literal.datatype.should.be.an.instanceof(NamedNode);
149 literal.datatype.value.should.equal('http://www.w3.org/2001/XMLSchema#string');
150 });
151
152 it('should have the quoted string as id', () => {
153 literal.should.have.property('id', '"my @^^ string"');
154 });
155
156 it('should equal a Literal instance with the same value', () => {
157 literal.equals(new Literal('"my @^^ string"')).should.be.true;
158 });
159
160 it('should equal an object with the same term type, value, language, and datatype', () => {
161 literal.equals({
162 termType: 'Literal',
163 value: 'my @^^ string',
164 language: '',
165 datatype: { value: 'http://www.w3.org/2001/XMLSchema#string', termType: 'NamedNode' },
166 }).should.be.true;
167 });
168
169 it('should not equal a falsy object', () => {
170 literal.equals(null).should.be.false;
171 });
172
173 it('should not equal a Literal instance with another value', () => {
174 literal.equals(new Literal('"other string"')).should.be.false;
175 });
176
177 it('should not equal an object with the same term type but a different value', () => {
178 literal.equals({
179 termType: 'Literal',
180 value: 'other string',
181 language: '',
182 datatype: { value: 'http://www.w3.org/2001/XMLSchema#string', termType: 'NamedNode' },
183 }).should.be.false;
184 });
185
186 it('should not equal an object with the same term type but a different language', () => {
187 literal.equals({
188 termType: 'Literal',
189 value: 'my @^^ string',
190 language: 'en',
191 datatype: { value: 'http://www.w3.org/2001/XMLSchema#string', termType: 'NamedNode' },
192 }).should.be.false;
193 });
194
195 it('should not equal an object with the same term type but a different datatype', () => {
196 literal.equals({
197 termType: 'Literal',
198 value: 'my @^^ string',
199 language: '',
200 datatype: { value: 'other', termType: 'NamedNode' },
201 }).should.be.false;
202 });
203
204 it('should not equal an object with a different term type', () => {
205 literal.equals({
206 termType: 'NamedNode',
207 value: 'my @^^ string',
208 language: '',
209 datatype: { value: 'http://www.w3.org/2001/XMLSchema#string', termType: 'NamedNode' },
210 }).should.be.false;
211 });
212
213 it('should provide a JSON representation', () => {
214 literal.toJSON().should.deep.equal({
215 termType: 'Literal',
216 value: 'my @^^ string',
217 language: '',
218 datatype: {
219 termType: 'NamedNode',
220 value: 'http://www.w3.org/2001/XMLSchema#string',
221 },
222 });
223 });
224 });
225
226 describe('A Literal instance created from the empty string with a language', () => {
227 let literal;
228 before(() => { literal = new Literal('""@en-us'); });
229
230 it('should be a Literal', () => {
231 literal.should.be.an.instanceof(Literal);
232 });
233
234 it('should be a Term', () => {
235 literal.should.be.an.instanceof(Term);
236 });
237
238 it('should have term type "Literal"', () => {
239 literal.termType.should.equal('Literal');
240 });
241
242 it('should have the empty string as value', () => {
243 literal.should.have.property('value', '');
244 });
245
246 it('should have the language tag as language', () => {
247 literal.should.have.property('language', 'en-us');
248 });
249
250 it('should have rdf:langString as datatype', () => {
251 literal.should.have.property('datatype');
252 literal.datatype.should.be.an.instanceof(NamedNode);
253 literal.datatype.value.should.equal('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString');
254 });
255
256 it('should have the quoted empty string as id', () => {
257 literal.should.have.property('id', '""@en-us');
258 });
259
260 it('should equal a Literal instance with the same value', () => {
261 literal.equals(new Literal('""@en-us')).should.be.true;
262 });
263
264 it('should equal an object with the same term type, value, language, and datatype', () => {
265 literal.equals({
266 termType: 'Literal',
267 value: '',
268 language: 'en-us',
269 datatype: { value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString', termType: 'NamedNode' },
270 }).should.be.true;
271 });
272
273 it('should not equal a falsy object', () => {
274 literal.equals(null).should.be.false;
275 });
276
277 it('should not equal a Literal instance with a non-empty value', () => {
278 literal.equals(new Literal('"x"')).should.be.false;
279 });
280
281 it('should not equal an object with the same term type but a different value', () => {
282 literal.equals({
283 termType: 'Literal',
284 value: 'x',
285 language: 'en-us',
286 datatype: { value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString', termType: 'NamedNode' },
287 }).should.be.false;
288 });
289
290 it('should not equal an object with the same term type but a different language', () => {
291 literal.equals({
292 termType: 'Literal',
293 value: '',
294 language: '',
295 datatype: { value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString', termType: 'NamedNode' },
296 }).should.be.false;
297 });
298
299 it('should not equal an object with the same term type but a different datatype', () => {
300 literal.equals({
301 termType: 'Literal',
302 value: '',
303 language: 'en-us',
304 datatype: { value: 'other', termType: 'NamedNode' },
305 }).should.be.false;
306 });
307
308 it('should not equal an object with a different term type', () => {
309 literal.equals({
310 termType: 'NamedNode',
311 value: '',
312 language: 'en-us',
313 datatype: { value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString', termType: 'NamedNode' },
314 }).should.be.false;
315 });
316
317 it('should provide a JSON representation', () => {
318 literal.toJSON().should.deep.equal({
319 termType: 'Literal',
320 value: '',
321 language: 'en-us',
322 datatype: {
323 termType: 'NamedNode',
324 value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString',
325 },
326 });
327 });
328 });
329
330 describe('A Literal instance created from a string without language or datatype', () => {
331 let literal;
332 before(() => { literal = new Literal('"my @^^ string"@en-us'); });
333
334 it('should be a Literal', () => {
335 literal.should.be.an.instanceof(Literal);
336 });
337
338 it('should be a Term', () => {
339 literal.should.be.an.instanceof(Term);
340 });
341
342 it('should have term type "Literal"', () => {
343 literal.termType.should.equal('Literal');
344 });
345
346 it('should have the text value as value', () => {
347 literal.should.have.property('value', 'my @^^ string');
348 });
349
350 it('should have the language tag as language', () => {
351 literal.should.have.property('language', 'en-us');
352 });
353
354 it('should have rdf:langString as datatype', () => {
355 literal.should.have.property('datatype');
356 literal.datatype.should.be.an.instanceof(NamedNode);
357 literal.datatype.value.should.equal('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString');
358 });
359
360 it('should have the quoted string as id', () => {
361 literal.should.have.property('id', '"my @^^ string"@en-us');
362 });
363
364 it('should equal a Literal instance with the same value', () => {
365 literal.equals(new Literal('"my @^^ string"@en-us')).should.be.true;
366 });
367
368 it('should equal an object with the same term type, value, language, and datatype', () => {
369 literal.equals({
370 termType: 'Literal',
371 value: 'my @^^ string',
372 language: 'en-us',
373 datatype: { value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString', termType: 'NamedNode' },
374 }).should.be.true;
375 });
376
377 it('should not equal a falsy object', () => {
378 literal.equals(null).should.be.false;
379 });
380
381 it('should not equal a Literal instance with another value', () => {
382 literal.equals(new Literal('"other string"')).should.be.false;
383 });
384
385 it('should not equal an object with the same term type but a different value', () => {
386 literal.equals({
387 termType: 'Literal',
388 value: 'other string',
389 language: 'en-us',
390 datatype: { value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString', termType: 'NamedNode' },
391 }).should.be.false;
392 });
393
394 it('should not equal an object with the same term type but a different language', () => {
395 literal.equals({
396 termType: 'Literal',
397 value: 'my @^^ string',
398 language: 'fr',
399 datatype: { value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString', termType: 'NamedNode' },
400 }).should.be.false;
401 });
402
403 it('should not equal an object with the same term type but a different datatype', () => {
404 literal.equals({
405 termType: 'Literal',
406 value: 'my @^^ string',
407 language: 'en-us',
408 datatype: { value: 'other', termType: 'NamedNode' },
409 }).should.be.false;
410 });
411
412 it('should not equal an object with a different term type', () => {
413 literal.equals({
414 termType: 'NamedNode',
415 value: 'my @^^ string',
416 language: 'en-us',
417 datatype: { value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString', termType: 'NamedNode' },
418 }).should.be.false;
419 });
420
421 it('should provide a JSON representation', () => {
422 literal.toJSON().should.deep.equal({
423 termType: 'Literal',
424 value: 'my @^^ string',
425 language: 'en-us',
426 datatype: {
427 termType: 'NamedNode',
428 value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#langString',
429 },
430 });
431 });
432 });
433
434 describe('A Literal instance created from the empty string with a datatype', () => {
435 let literal;
436 before(() => { literal = new Literal('""^^http://example.org/types#type'); });
437
438 it('should be a Literal', () => {
439 literal.should.be.an.instanceof(Literal);
440 });
441
442 it('should be a Term', () => {
443 literal.should.be.an.instanceof(Term);
444 });
445
446 it('should have term type "Literal"', () => {
447 literal.termType.should.equal('Literal');
448 });
449
450 it('should have the empty string as value', () => {
451 literal.should.have.property('value', '');
452 });
453
454 it('should have the empty string as language', () => {
455 literal.should.have.property('language', '');
456 });
457
458 it('should have the datatype', () => {
459 literal.should.have.property('datatype');
460 literal.datatype.should.be.an.instanceof(NamedNode);
461 literal.datatype.value.should.equal('http://example.org/types#type');
462 });
463
464 it('should have the quoted empty string as id', () => {
465 literal.should.have.property('id', '""^^http://example.org/types#type');
466 });
467
468 it('should equal a Literal instance with the same value', () => {
469 literal.equals(new Literal('""^^http://example.org/types#type')).should.be.true;
470 });
471
472 it('should equal an object with the same term type, value, language, and datatype', () => {
473 literal.equals({
474 termType: 'Literal',
475 value: '',
476 language: '',
477 datatype: { value: 'http://example.org/types#type', termType: 'NamedNode' },
478 }).should.be.true;
479 });
480
481 it('should not equal a falsy object', () => {
482 literal.equals(null).should.be.false;
483 });
484
485 it('should not equal a Literal instance with a non-empty value', () => {
486 literal.equals(new Literal('"x"^^http://example.org/types#type')).should.be.false;
487 });
488
489 it('should not equal an object with the same term type but a different value', () => {
490 literal.equals({
491 termType: 'Literal',
492 value: 'x',
493 language: '',
494 datatype: { value: 'http://example.org/types#type', termType: 'NamedNode' },
495 }).should.be.false;
496 });
497
498 it('should not equal an object with the same term type but a different language', () => {
499 literal.equals({
500 termType: 'Literal',
501 value: '',
502 language: 'en',
503 datatype: { value: 'http://example.org/types#type', termType: 'NamedNode' },
504 }).should.be.false;
505 });
506
507 it('should not equal an object with the same term type but a different datatype', () => {
508 literal.equals({
509 termType: 'Literal',
510 value: '',
511 language: '',
512 datatype: { value: 'other', termType: 'NamedNode' },
513 }).should.be.false;
514 });
515
516 it('should not equal an object with a different term type', () => {
517 literal.equals({
518 termType: 'NamedNode',
519 value: '',
520 language: '',
521 datatype: { value: 'http://example.org/types#type', termType: 'NamedNode' },
522 }).should.be.false;
523 });
524
525 it('should provide a JSON representation', () => {
526 literal.toJSON().should.deep.equal({
527 termType: 'Literal',
528 value: '',
529 language: '',
530 datatype: {
531 termType: 'NamedNode',
532 value: 'http://example.org/types#type',
533 },
534 });
535 });
536 });
537
538 describe('A Literal instance created from a string with a datatype', () => {
539 let literal;
540 before(() => { literal = new Literal('"my @^^ string"^^http://example.org/types#type'); });
541
542 it('should be a Literal', () => {
543 literal.should.be.an.instanceof(Literal);
544 });
545
546 it('should be a Term', () => {
547 literal.should.be.an.instanceof(Term);
548 });
549
550 it('should have term type "Literal"', () => {
551 literal.termType.should.equal('Literal');
552 });
553
554 it('should have the text value as value', () => {
555 literal.should.have.property('value', 'my @^^ string');
556 });
557
558 it('should have the empty string as language', () => {
559 literal.should.have.property('language', '');
560 });
561
562 it('should have the datatype', () => {
563 literal.should.have.property('datatype');
564 literal.datatype.should.be.an.instanceof(NamedNode);
565 literal.datatype.value.should.equal('http://example.org/types#type');
566 });
567
568 it('should have the quoted string as id', () => {
569 literal.should.have.property('id', '"my @^^ string"^^http://example.org/types#type');
570 });
571
572 it('should equal a Literal instance with the same value', () => {
573 literal.equals(new Literal('"my @^^ string"^^http://example.org/types#type')).should.be.true;
574 });
575
576 it('should equal an object with the same term type, value, language, and datatype', () => {
577 literal.equals({
578 termType: 'Literal',
579 value: 'my @^^ string',
580 language: '',
581 datatype: { value: 'http://example.org/types#type', termType: 'NamedNode' },
582 }).should.be.true;
583 });
584
585 it('should not equal a falsy object', () => {
586 literal.equals(null).should.be.false;
587 });
588
589 it('should not equal a Literal instance with another value', () => {
590 literal.equals(new Literal('"other string"^^http://example.org/types#type')).should.be.false;
591 });
592
593 it('should not equal an object with the same term type but a different value', () => {
594 literal.equals({
595 termType: 'Literal',
596 value: 'other string',
597 language: '',
598 datatype: { value: 'http://example.org/types#type', termType: 'NamedNode' },
599 }).should.be.false;
600 });
601
602 it('should not equal an object with the same term type but a different language', () => {
603 literal.equals({
604 termType: 'Literal',
605 value: 'my @^^ string',
606 language: 'en',
607 datatype: { value: 'http://example.org/types#type', termType: 'NamedNode' },
608 }).should.be.false;
609 });
610
611 it('should not equal an object with the same term type but a different datatype', () => {
612 literal.equals({
613 termType: 'Literal',
614 value: 'my @^^ string',
615 language: '',
616 datatype: { value: 'other', termType: 'NamedNode' },
617 }).should.be.false;
618 });
619
620 it('should not equal an object with a different term type', () => {
621 literal.equals({
622 termType: 'NamedNode',
623 value: 'my @^^ string',
624 language: '',
625 datatype: { value: 'http://example.org/types#type', termType: 'NamedNode' },
626 }).should.be.false;
627 });
628
629 it('should provide a JSON representation', () => {
630 literal.toJSON().should.deep.equal({
631 termType: 'Literal',
632 value: 'my @^^ string',
633 language: '',
634 datatype: {
635 termType: 'NamedNode',
636 value: 'http://example.org/types#type',
637 },
638 });
639 });
640 });
641 });