| 1 |
import { Quad, Triple, DefaultGraph, termFromId, Term } from '../src/'; |
| 2 |
|
| 3 |
describe('Quad', () => { |
| 4 |
describe('The Quad module', () => { |
| 5 |
it('should be a function', () => { |
| 6 |
Quad.should.be.a('function'); |
| 7 |
}); |
| 8 |
|
| 9 |
it('should be a Quad constructor', () => { |
| 10 |
new Quad().should.be.an.instanceof(Quad); |
| 11 |
}); |
| 12 |
|
| 13 |
it('should equal Triple', () => { |
| 14 |
Quad.should.equal(Triple); |
| 15 |
}); |
| 16 |
}); |
| 17 |
|
| 18 |
describe('A Quad instance created with subject/predicate/object', () => { |
| 19 |
let quad, subject, predicate, object; |
| 20 |
before(() => { |
| 21 |
quad = new Quad( |
| 22 |
subject = termFromId('s'), |
| 23 |
predicate = termFromId('p'), |
| 24 |
object = termFromId('o') |
| 25 |
); |
| 26 |
}); |
| 27 |
|
| 28 |
it('should be a Quad', () => { |
| 29 |
quad.should.be.an.instanceof(Quad); |
| 30 |
}); |
| 31 |
|
| 32 |
it('should be a Term', () => { |
| 33 |
quad.should.be.an.instanceof(Term); |
| 34 |
}); |
| 35 |
|
| 36 |
it('should have the correct termType', () => { |
| 37 |
quad.termType.should.equal('Quad'); |
| 38 |
}); |
| 39 |
|
| 40 |
it('should have the correct subject', () => { |
| 41 |
quad.subject.should.equal(subject); |
| 42 |
}); |
| 43 |
|
| 44 |
it('should have the correct predicate', () => { |
| 45 |
quad.predicate.should.equal(predicate); |
| 46 |
}); |
| 47 |
|
| 48 |
it('should have the correct object', () => { |
| 49 |
quad.object.should.equal(object); |
| 50 |
}); |
| 51 |
|
| 52 |
it('should have the default graph', () => { |
| 53 |
quad.graph.should.equal(new DefaultGraph()); |
| 54 |
}); |
| 55 |
|
| 56 |
it('should equal a quad with the same components', () => { |
| 57 |
quad.equals({ |
| 58 |
subject: subject, |
| 59 |
predicate: predicate, |
| 60 |
object: object, |
| 61 |
graph: new DefaultGraph(), |
| 62 |
}).should.be.true; |
| 63 |
}); |
| 64 |
|
| 65 |
it('should not equal a quad with a different subject', () => { |
| 66 |
quad.equals({ |
| 67 |
subject: termFromId('x'), |
| 68 |
predicate: predicate, |
| 69 |
object: object, |
| 70 |
graph: new DefaultGraph(), |
| 71 |
}).should.be.false; |
| 72 |
}); |
| 73 |
|
| 74 |
it('should not equal a quad with a different predicate', () => { |
| 75 |
quad.equals({ |
| 76 |
subject: subject, |
| 77 |
predicate: termFromId('x'), |
| 78 |
object: object, |
| 79 |
graph: new DefaultGraph(), |
| 80 |
}).should.be.false; |
| 81 |
}); |
| 82 |
|
| 83 |
it('should not equal a quad with a different object', () => { |
| 84 |
quad.equals({ |
| 85 |
subject: subject, |
| 86 |
predicate: predicate, |
| 87 |
object: termFromId('x'), |
| 88 |
graph: new DefaultGraph(), |
| 89 |
}).should.be.false; |
| 90 |
}); |
| 91 |
|
| 92 |
it('should not equal a quad with a different graph', () => { |
| 93 |
quad.equals({ |
| 94 |
subject: subject, |
| 95 |
predicate: predicate, |
| 96 |
object: object, |
| 97 |
graph: termFromId('x'), |
| 98 |
}).should.be.false; |
| 99 |
}); |
| 100 |
|
| 101 |
it('should provide a JSON representation', () => { |
| 102 |
quad.toJSON().should.deep.equal({ |
| 103 |
termType: 'Quad', |
| 104 |
subject: { termType: 'NamedNode', value: 's' }, |
| 105 |
predicate: { termType: 'NamedNode', value: 'p' }, |
| 106 |
object: { termType: 'NamedNode', value: 'o' }, |
| 107 |
graph: { termType: 'DefaultGraph', value: '' }, |
| 108 |
}); |
| 109 |
}); |
| 110 |
}); |
| 111 |
|
| 112 |
describe('A Quad instance created with subject/predicate/object/graph', () => { |
| 113 |
let quad, subject, predicate, object, graph; |
| 114 |
before(() => { |
| 115 |
quad = new Quad( |
| 116 |
subject = termFromId('s'), |
| 117 |
predicate = termFromId('p'), |
| 118 |
object = termFromId('o'), |
| 119 |
graph = termFromId('g') |
| 120 |
); |
| 121 |
}); |
| 122 |
|
| 123 |
it('should be a Quad', () => { |
| 124 |
quad.should.be.an.instanceof(Quad); |
| 125 |
}); |
| 126 |
|
| 127 |
it('should be a Term', () => { |
| 128 |
quad.should.be.an.instanceof(Term); |
| 129 |
}); |
| 130 |
|
| 131 |
it('should have the correct termType', () => { |
| 132 |
quad.termType.should.equal('Quad'); |
| 133 |
}); |
| 134 |
|
| 135 |
it('should have the correct subject', () => { |
| 136 |
quad.subject.should.equal(subject); |
| 137 |
}); |
| 138 |
|
| 139 |
it('should have the correct predicate', () => { |
| 140 |
quad.predicate.should.equal(predicate); |
| 141 |
}); |
| 142 |
|
| 143 |
it('should have the correct object', () => { |
| 144 |
quad.object.should.equal(object); |
| 145 |
}); |
| 146 |
|
| 147 |
it('should have the default graph', () => { |
| 148 |
quad.graph.should.equal(graph); |
| 149 |
}); |
| 150 |
|
| 151 |
it('should equal a quad with the same components', () => { |
| 152 |
quad.equals({ |
| 153 |
subject: subject, |
| 154 |
predicate: predicate, |
| 155 |
object: object, |
| 156 |
graph: graph, |
| 157 |
}).should.be.true; |
| 158 |
}); |
| 159 |
|
| 160 |
it('should not equal a quad with a different subject', () => { |
| 161 |
quad.equals({ |
| 162 |
subject: termFromId('x'), |
| 163 |
predicate: predicate, |
| 164 |
object: object, |
| 165 |
graph: graph, |
| 166 |
}).should.be.false; |
| 167 |
}); |
| 168 |
|
| 169 |
it('should not equal a quad with a different predicate', () => { |
| 170 |
quad.equals({ |
| 171 |
subject: subject, |
| 172 |
predicate: termFromId('x'), |
| 173 |
object: object, |
| 174 |
graph: graph, |
| 175 |
}).should.be.false; |
| 176 |
}); |
| 177 |
|
| 178 |
it('should not equal a quad with a different object', () => { |
| 179 |
quad.equals({ |
| 180 |
subject: subject, |
| 181 |
predicate: predicate, |
| 182 |
object: termFromId('x'), |
| 183 |
graph: graph, |
| 184 |
}).should.be.false; |
| 185 |
}); |
| 186 |
|
| 187 |
it('should not equal a quad with a different graph', () => { |
| 188 |
quad.equals({ |
| 189 |
subject: subject, |
| 190 |
predicate: predicate, |
| 191 |
object: object, |
| 192 |
graph: termFromId('x'), |
| 193 |
}).should.be.false; |
| 194 |
}); |
| 195 |
|
| 196 |
it('should provide a JSON representation', () => { |
| 197 |
quad.toJSON().should.deep.equal({ |
| 198 |
termType: 'Quad', |
| 199 |
subject: { termType: 'NamedNode', value: 's' }, |
| 200 |
predicate: { termType: 'NamedNode', value: 'p' }, |
| 201 |
object: { termType: 'NamedNode', value: 'o' }, |
| 202 |
graph: { termType: 'NamedNode', value: 'g' }, |
| 203 |
}); |
| 204 |
}); |
| 205 |
}); |
| 206 |
|
| 207 |
describe('A Quad instance with nested quads', () => { |
| 208 |
let quad, subject, predicate, object; |
| 209 |
before(() => { |
| 210 |
quad = new Quad( |
| 211 |
subject = termFromId('<<_:n3-123 ?var-a ?var-b _:n3-000>>'), |
| 212 |
predicate = termFromId('p'), |
| 213 |
object = termFromId('<<http://ex.org/a http://ex.org/b http://ex.org/c>>') |
| 214 |
); |
| 215 |
}); |
| 216 |
|
| 217 |
it('should be a Quad', () => { |
| 218 |
quad.should.be.an.instanceof(Quad); |
| 219 |
}); |
| 220 |
|
| 221 |
it('should be a Term', () => { |
| 222 |
quad.should.be.an.instanceof(Term); |
| 223 |
}); |
| 224 |
|
| 225 |
it('should have the correct termType', () => { |
| 226 |
quad.termType.should.equal('Quad'); |
| 227 |
}); |
| 228 |
|
| 229 |
it('should have the correct subject', () => { |
| 230 |
quad.subject.should.equal(subject); |
| 231 |
}); |
| 232 |
|
| 233 |
it('should have the correct predicate', () => { |
| 234 |
quad.predicate.should.equal(predicate); |
| 235 |
}); |
| 236 |
|
| 237 |
it('should have the correct object', () => { |
| 238 |
quad.object.should.equal(object); |
| 239 |
}); |
| 240 |
|
| 241 |
it('should have the default graph', () => { |
| 242 |
quad.graph.should.equal(new DefaultGraph()); |
| 243 |
}); |
| 244 |
|
| 245 |
it('should equal a quad with the same components', () => { |
| 246 |
quad.equals({ |
| 247 |
subject: subject, |
| 248 |
predicate: predicate, |
| 249 |
object: object, |
| 250 |
graph: new DefaultGraph(), |
| 251 |
}).should.be.true; |
| 252 |
}); |
| 253 |
|
| 254 |
it('should not equal a quad with a different subject', () => { |
| 255 |
quad.equals({ |
| 256 |
termType: 'Quad', |
| 257 |
value: '', |
| 258 |
subject: termFromId('x'), |
| 259 |
predicate: predicate, |
| 260 |
object: object, |
| 261 |
graph: new DefaultGraph(), |
| 262 |
}).should.be.false; |
| 263 |
}); |
| 264 |
|
| 265 |
it('should not equal a quad with a different predicate', () => { |
| 266 |
quad.equals({ |
| 267 |
termType: 'Quad', |
| 268 |
value: '', |
| 269 |
subject: subject, |
| 270 |
predicate: termFromId('x'), |
| 271 |
object: object, |
| 272 |
graph: new DefaultGraph(), |
| 273 |
}).should.be.false; |
| 274 |
}); |
| 275 |
|
| 276 |
it('should not equal a quad with a different object', () => { |
| 277 |
quad.equals({ |
| 278 |
termType: 'Quad', |
| 279 |
value: '', |
| 280 |
subject: subject, |
| 281 |
predicate: predicate, |
| 282 |
object: termFromId('x'), |
| 283 |
graph: new DefaultGraph(), |
| 284 |
}).should.be.false; |
| 285 |
}); |
| 286 |
|
| 287 |
it('should not equal a quad with a different graph', () => { |
| 288 |
quad.equals({ |
| 289 |
termType: 'Quad', |
| 290 |
value: '', |
| 291 |
subject: subject, |
| 292 |
predicate: predicate, |
| 293 |
object: object, |
| 294 |
graph: termFromId('x'), |
| 295 |
}).should.be.false; |
| 296 |
}); |
| 297 |
|
| 298 |
it('should provide a JSON representation', () => { |
| 299 |
quad.toJSON().should.deep.equal({ |
| 300 |
termType: 'Quad', |
| 301 |
subject: termFromId('<<_:n3-123 ?var-a ?var-b _:n3-000>>').toJSON(), |
| 302 |
predicate: { termType: 'NamedNode', value: 'p' }, |
| 303 |
object: termFromId('<<http://ex.org/a http://ex.org/b http://ex.org/c>>').toJSON(), |
| 304 |
graph: { termType: 'DefaultGraph', value: '' }, |
| 305 |
}); |
| 306 |
}); |
| 307 |
}); |
| 308 |
}); |