|
1
|
|
|
var assert = require('chai').assert, |
|
2
|
|
|
GedcomX = require('../'); |
|
3
|
|
|
|
|
4
|
|
|
describe('Identifiers', function(){ |
|
5
|
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
|
7
|
|
|
var newIdent = new GedcomX.Identifiers(), |
|
8
|
|
|
ident = GedcomX.Identifiers(); |
|
9
|
|
|
assert.instanceOf(newIdent, GedcomX.Identifiers, 'An instance of Identifiers is not returned when calling the constructor with new.'); |
|
10
|
|
|
assert.instanceOf(ident, GedcomX.Identifiers, 'An instance of Identifiers is not returned when calling the constructor without new.'); |
|
11
|
|
|
}); |
|
12
|
|
|
|
|
13
|
|
|
it('Create with JSON', function(){ |
|
14
|
|
|
var ident = GedcomX.Identifiers({ |
|
15
|
|
|
$: [ 'value_with_no_type' ], |
|
16
|
|
|
list: [ 'one', 'two' ], |
|
17
|
|
|
collapse: 'single_value' |
|
18
|
|
|
}); |
|
19
|
|
|
assert.deepEqual(ident.getValues(), [ 'value_with_no_type' ]); |
|
20
|
|
|
assert.deepEqual(ident.getValues('list'), [ 'one', 'two' ]); |
|
21
|
|
|
assert.deepEqual(ident.getValues('collapse'), [ 'single_value' ]); |
|
22
|
|
|
}); |
|
23
|
|
|
|
|
24
|
|
|
it('Build', function(){ |
|
25
|
|
|
var ident = GedcomX.Identifiers(); |
|
26
|
|
|
ident.addValue('value_with_no_type'); |
|
27
|
|
|
ident.addValue('one', 'list'); |
|
28
|
|
|
ident.addValue('two', 'list'); |
|
29
|
|
|
ident.addValue('single_value', 'collapse'); |
|
30
|
|
|
assert.deepEqual(ident.getValues(), [ 'value_with_no_type' ]); |
|
31
|
|
|
assert.deepEqual(ident.getValues('list'), [ 'one', 'two' ]); |
|
32
|
|
|
assert.deepEqual(ident.getValues('collapse'), [ 'single_value' ]); |
|
33
|
|
|
}); |
|
34
|
|
|
|
|
35
|
|
|
it('toJSON() and single string collapsing', function(){ |
|
36
|
|
|
var ident = GedcomX.Identifiers({ |
|
37
|
|
|
$: [ 'value_with_no_type' ], |
|
38
|
|
|
list: [ 'one', 'two' ], |
|
39
|
|
|
collapse: 'single_value' |
|
40
|
|
|
}); |
|
41
|
|
|
assert.deepEqual(ident.toJSON(), { |
|
42
|
|
|
$: [ 'value_with_no_type' ], |
|
43
|
|
|
list: [ 'one', 'two' ], |
|
44
|
|
|
collapse: [ 'single_value' ] |
|
45
|
|
|
}); |
|
46
|
|
|
}); |
|
47
|
|
|
|
|
48
|
|
|
it('constructor does not copy instances', function(){ |
|
49
|
|
|
var obj1 = GedcomX.Identifiers(); |
|
50
|
|
|
var obj2 = GedcomX.Identifiers(obj1); |
|
51
|
|
|
assert.strictEqual(obj1, obj2); |
|
52
|
|
|
}); |
|
53
|
|
|
|
|
54
|
|
|
}); |