| 1 |
import { Variable, Term } from '../src/'; |
| 2 |
|
| 3 |
describe('Variable', () => { |
| 4 |
describe('The Variable module', () => { |
| 5 |
it('should be a function', () => { |
| 6 |
Variable.should.be.a('function'); |
| 7 |
}); |
| 8 |
|
| 9 |
it('should be a Variable constructor', () => { |
| 10 |
new Variable().should.be.an.instanceof(Variable); |
| 11 |
}); |
| 12 |
|
| 13 |
it('should be a Term constructor', () => { |
| 14 |
new Variable().should.be.an.instanceof(Term); |
| 15 |
}); |
| 16 |
}); |
| 17 |
|
| 18 |
describe('A Variable instance created from a name', () => { |
| 19 |
let variable; |
| 20 |
before(() => { variable = new Variable('v1'); }); |
| 21 |
|
| 22 |
it('should be a Variable', () => { |
| 23 |
variable.should.be.an.instanceof(Variable); |
| 24 |
}); |
| 25 |
|
| 26 |
it('should be a Term', () => { |
| 27 |
variable.should.be.an.instanceof(Term); |
| 28 |
}); |
| 29 |
|
| 30 |
it('should have term type "Variable"', () => { |
| 31 |
variable.termType.should.equal('Variable'); |
| 32 |
}); |
| 33 |
|
| 34 |
it('should have the name as value', () => { |
| 35 |
variable.should.have.property('value', 'v1'); |
| 36 |
}); |
| 37 |
|
| 38 |
it('should have "?name" as id value', () => { |
| 39 |
variable.should.have.property('id', '?v1'); |
| 40 |
}); |
| 41 |
|
| 42 |
it('should equal a Variable instance with the same name', () => { |
| 43 |
variable.equals(new Variable('v1')).should.be.true; |
| 44 |
}); |
| 45 |
|
| 46 |
it('should equal an object with the same term type and value', () => { |
| 47 |
variable.equals({ |
| 48 |
termType: 'Variable', |
| 49 |
value: 'v1', |
| 50 |
}).should.be.true; |
| 51 |
}); |
| 52 |
|
| 53 |
it('should not equal a falsy object', () => { |
| 54 |
variable.equals(null).should.be.false; |
| 55 |
}); |
| 56 |
|
| 57 |
it('should not equal a Variable instance with another name', () => { |
| 58 |
variable.equals(new Variable('v2')).should.be.false; |
| 59 |
}); |
| 60 |
|
| 61 |
it('should not equal an object with the same term type but a different value', () => { |
| 62 |
variable.equals({ |
| 63 |
termType: 'Variable', |
| 64 |
value: 'v2', |
| 65 |
}).should.be.false; |
| 66 |
}); |
| 67 |
|
| 68 |
it('should not equal an object with a different term type but the same value', () => { |
| 69 |
variable.equals({ |
| 70 |
termType: 'NamedNode', |
| 71 |
value: 'v1', |
| 72 |
}).should.be.false; |
| 73 |
}); |
| 74 |
|
| 75 |
it('should provide a JSON representation', () => { |
| 76 |
variable.toJSON().should.deep.equal({ |
| 77 |
termType: 'Variable', |
| 78 |
value: 'v1', |
| 79 |
}); |
| 80 |
}); |
| 81 |
}); |
| 82 |
}); |