| 1 |
import { |
| 2 |
DataFactory, |
| 3 |
NamedNode, |
| 4 |
Literal, |
| 5 |
BlankNode, |
| 6 |
Variable, |
| 7 |
DefaultGraph, |
| 8 |
Quad, |
| 9 |
} from '../src/'; |
| 10 |
|
| 11 |
describe('DataFactory', () => { |
| 12 |
describe('namedNode', () => { |
| 13 |
it('converts a plain IRI', () => { |
| 14 |
DataFactory.namedNode('http://ex.org/foo#bar').should.deep.equal(new NamedNode('http://ex.org/foo#bar')); |
| 15 |
}); |
| 16 |
}); |
| 17 |
|
| 18 |
describe('blankNode', () => { |
| 19 |
it('converts a label', () => { |
| 20 |
DataFactory.blankNode('abc').should.deep.equal(new BlankNode('abc')); |
| 21 |
}); |
| 22 |
|
| 23 |
it('creates an anonymous blank node', () => { |
| 24 |
DataFactory.blankNode().should.deep.equal(new BlankNode('n3-0')); |
| 25 |
DataFactory.blankNode().should.deep.equal(new BlankNode('n3-1')); |
| 26 |
}); |
| 27 |
|
| 28 |
it('does not create two equal anonymous blank nodes', () => { |
| 29 |
DataFactory.blankNode().should.not.deep.equal(DataFactory.blankNode()); |
| 30 |
}); |
| 31 |
}); |
| 32 |
|
| 33 |
describe('literal', () => { |
| 34 |
it('converts the empty string', () => { |
| 35 |
DataFactory.literal('').should.deep.equal(new Literal('""')); |
| 36 |
}); |
| 37 |
|
| 38 |
it('converts the empty string with a language', () => { |
| 39 |
DataFactory.literal('', 'en-GB').should.deep.equal(new Literal('""@en-gb')); |
| 40 |
}); |
| 41 |
|
| 42 |
it('converts the empty string with a named node type', () => { |
| 43 |
DataFactory.literal('', new NamedNode('http://ex.org/type')).should.deep.equal(new Literal('""^^http://ex.org/type')); |
| 44 |
}); |
| 45 |
|
| 46 |
it('converts a non-empty string', () => { |
| 47 |
DataFactory.literal('abc').should.deep.equal(new Literal('"abc"')); |
| 48 |
}); |
| 49 |
|
| 50 |
it('converts a non-empty string with a language', () => { |
| 51 |
DataFactory.literal('abc', 'en-GB').should.deep.equal(new Literal('"abc"@en-gb')); |
| 52 |
}); |
| 53 |
|
| 54 |
it('converts a non-empty string with a named node type', () => { |
| 55 |
DataFactory.literal('abc', new NamedNode('http://ex.org/type')).should.deep.equal(new Literal('"abc"^^http://ex.org/type')); |
| 56 |
}); |
| 57 |
|
| 58 |
it('converts a non-empty string with an xsd:string type', () => { |
| 59 |
DataFactory.literal('abc', new NamedNode('http://www.w3.org/2001/XMLSchema#string')).should.deep.equal(new Literal('"abc"')); |
| 60 |
}); |
| 61 |
|
| 62 |
it('converts an integer', () => { |
| 63 |
DataFactory.literal(123).should.deep.equal(new Literal('"123"^^http://www.w3.org/2001/XMLSchema#integer')); |
| 64 |
}); |
| 65 |
|
| 66 |
it('converts a double', () => { |
| 67 |
DataFactory.literal(2.3).should.deep.equal(new Literal('"2.3"^^http://www.w3.org/2001/XMLSchema#double')); |
| 68 |
}); |
| 69 |
|
| 70 |
it('converts Infinity', () => { |
| 71 |
DataFactory.literal(Infinity).should.deep.equal(new Literal('"INF"^^http://www.w3.org/2001/XMLSchema#double')); |
| 72 |
}); |
| 73 |
|
| 74 |
it('converts -Infinity', () => { |
| 75 |
DataFactory.literal(-Infinity).should.deep.equal(new Literal('"-INF"^^http://www.w3.org/2001/XMLSchema#double')); |
| 76 |
}); |
| 77 |
|
| 78 |
it('converts NaN', () => { |
| 79 |
DataFactory.literal(NaN).should.deep.equal(new Literal('"NaN"^^http://www.w3.org/2001/XMLSchema#double')); |
| 80 |
}); |
| 81 |
|
| 82 |
it('converts false', () => { |
| 83 |
DataFactory.literal(false).should.deep.equal(new Literal('"false"^^http://www.w3.org/2001/XMLSchema#boolean')); |
| 84 |
}); |
| 85 |
|
| 86 |
it('converts true', () => { |
| 87 |
DataFactory.literal(true).should.deep.equal(new Literal('"true"^^http://www.w3.org/2001/XMLSchema#boolean')); |
| 88 |
}); |
| 89 |
}); |
| 90 |
|
| 91 |
describe('variable', () => { |
| 92 |
it('converts a label', () => { |
| 93 |
DataFactory.variable('abc').should.deep.equal(new Variable('abc')); |
| 94 |
}); |
| 95 |
}); |
| 96 |
|
| 97 |
describe('defaultGraph', () => { |
| 98 |
it('returns the default graph', () => { |
| 99 |
DataFactory.defaultGraph().should.deep.equal(new DefaultGraph()); |
| 100 |
}); |
| 101 |
}); |
| 102 |
|
| 103 |
describe('triple', () => { |
| 104 |
it('returns a quad in the default graph', () => { |
| 105 |
DataFactory.triple( |
| 106 |
new NamedNode('http://ex.org/a'), |
| 107 |
new NamedNode('http://ex.org/b'), |
| 108 |
new Literal('abc') |
| 109 |
).should.deep.equal(new Quad( |
| 110 |
new NamedNode('http://ex.org/a'), |
| 111 |
new NamedNode('http://ex.org/b'), |
| 112 |
new Literal('abc'), |
| 113 |
new DefaultGraph() |
| 114 |
)); |
| 115 |
}); |
| 116 |
}); |
| 117 |
|
| 118 |
describe('quad', () => { |
| 119 |
it('returns a quad', () => { |
| 120 |
DataFactory.quad( |
| 121 |
new NamedNode('http://ex.org/a'), |
| 122 |
new NamedNode('http://ex.org/b'), |
| 123 |
new Literal('abc'), |
| 124 |
new NamedNode('http://ex.org/d') |
| 125 |
).should.deep.equal(new Quad( |
| 126 |
new NamedNode('http://ex.org/a'), |
| 127 |
new NamedNode('http://ex.org/b'), |
| 128 |
new Literal('abc'), |
| 129 |
new NamedNode('http://ex.org/d') |
| 130 |
)); |
| 131 |
}); |
| 132 |
|
| 133 |
it('should return a nested quad', () => { |
| 134 |
DataFactory.quad( |
| 135 |
new Quad( |
| 136 |
new NamedNode('http://ex.org/a'), |
| 137 |
new NamedNode('http://ex.org/b'), |
| 138 |
new Literal('abc'), |
| 139 |
new NamedNode('http://ex.org/d') |
| 140 |
), |
| 141 |
new NamedNode('http://ex.org/b'), |
| 142 |
new Literal('abc'), |
| 143 |
new NamedNode('http://ex.org/d') |
| 144 |
).should.deep.equal(new Quad( |
| 145 |
new Quad( |
| 146 |
new NamedNode('http://ex.org/a'), |
| 147 |
new NamedNode('http://ex.org/b'), |
| 148 |
new Literal('abc'), |
| 149 |
new NamedNode('http://ex.org/d') |
| 150 |
), |
| 151 |
new NamedNode('http://ex.org/b'), |
| 152 |
new Literal('abc'), |
| 153 |
new NamedNode('http://ex.org/d') |
| 154 |
)); |
| 155 |
}); |
| 156 |
|
| 157 |
it('should return a nested quad', () => { |
| 158 |
DataFactory.quad( |
| 159 |
new NamedNode('http://ex.org/a'), |
| 160 |
new NamedNode('http://ex.org/b'), |
| 161 |
new Literal('abc'), |
| 162 |
new Quad( |
| 163 |
new NamedNode('http://ex.org/a'), |
| 164 |
new NamedNode('http://ex.org/b'), |
| 165 |
new Literal('abc'), |
| 166 |
new NamedNode('http://ex.org/d') |
| 167 |
) |
| 168 |
).should.deep.equal(new Quad( |
| 169 |
new NamedNode('http://ex.org/a'), |
| 170 |
new NamedNode('http://ex.org/b'), |
| 171 |
new Literal('abc'), |
| 172 |
new Quad( |
| 173 |
new NamedNode('http://ex.org/a'), |
| 174 |
new NamedNode('http://ex.org/b'), |
| 175 |
new Literal('abc'), |
| 176 |
new NamedNode('http://ex.org/d') |
| 177 |
) |
| 178 |
)); |
| 179 |
}); |
| 180 |
|
| 181 |
it('without graph parameter returns a quad in the default graph', () => { |
| 182 |
DataFactory.quad( |
| 183 |
new NamedNode('http://ex.org/a'), |
| 184 |
new NamedNode('http://ex.org/b'), |
| 185 |
new Literal('abc') |
| 186 |
).should.deep.equal(new Quad( |
| 187 |
new NamedNode('http://ex.org/a'), |
| 188 |
new NamedNode('http://ex.org/b'), |
| 189 |
new Literal('abc'), |
| 190 |
new DefaultGraph() |
| 191 |
)); |
| 192 |
}); |
| 193 |
}); |
| 194 |
}); |