-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
153 lines (100 loc) · 3.97 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import {xmlion} from './dist/xmlion';
import test from 'ava';
test('empty elements', (assert) => {
let actual = xmlion('lion').value();
assert.is(actual, '<lion/>', 'xmlion must make empty elements');
});
test('attributed elements', (assert) => {
let actual = xmlion('lion', {attr: 'test'}).value();
assert.is(actual, '<lion attr="test"/>', 'xmlion must make attributed elements');
});
test('elements with undefined attributes', (assert) => {
let actual = xmlion('lion', {attr: undefined}).value();
assert.is(actual, '<lion attr/>', 'xmlion must make attributed elements');
});
test('elements with null attributes', (assert) => {
let actual = xmlion('lion', {attr: null}).value();
assert.is(actual, '<lion attr/>', 'xmlion must make attributed elements');
});
test('attributed elements with content', (assert) => {
let actual = xmlion('lion', {attr: 'test'}, ['test']).value();
assert.is(actual, '<lion attr="test">test</lion>', 'xmlion must make attributed elements with content');
});
test('attributed elements with two cubs', (assert) => {
let actual = xmlion('lion', {attr: 'test'}, ['test', xmlion('lion', {attr: 'test'}, ['test'])]).value();
assert.is(actual, '<lion attr="test">test<lion attr="test">test</lion></lion>', 'xmlion must make complex attributed elements with content');
});
test('attributed elements with empty values', (assert) => {
let actual = xmlion('lion', {attr: 'test'}, [null, undefined, NaN, 0]).value();
assert.is(actual, '<lion attr="test">NaN0</lion>', 'xmlion must make complex attributed elements with content');
});
const lion = xmlion('lion', {}, []);
test('add attribute', (assert) => {
lion.addAttribute('attr', 'add');
let actual = lion.value();
assert.is(actual, '<lion attr="add"/>', 'xmlion must add attribute');
});
test('remove attribute', (assert) => {
lion.removeAttribute('attr');
let actual = lion.value();
assert.is(actual, '<lion/>', 'xmlion must remove attribute');
});
test('add many attributes', (assert) => {
lion.addAttributes({
'attr1': 'yup',
'attr2': 'yo'
});
let actual = lion.value();
assert.is(actual, '<lion attr1="yup" attr2="yo"/>', 'xmlion must add multiple attributes');
});
const cub = xmlion('cub');
test('add cub', (assert) => {
lion.addCub(cub);
let actual = lion.value();
assert.is(actual, '<lion attr1="yup" attr2="yo"><cub/></lion>', 'xmlion must add a cub');
});
test('remove cub', (assert) => {
lion.removeCub(cub);
let actual = lion.value();
assert.is(actual, '<lion attr1="yup" attr2="yo"/>', 'xmlion must remove a cub');
});
test('add cubs', (assert) => {
lion.addCubs([cub, xmlion('cub', null, ['meow'])]);
let actual = lion.value();
assert.is(actual, '<lion attr1="yup" attr2="yo"><cub/><cub>meow</cub></lion>', 'xmlion must add many cubs');
});
test('remove all cubs', (assert) => {
lion.removeAllCubs();
let actual = lion.value();
assert.is(actual, '<lion attr1="yup" attr2="yo"/>', 'xmlion must add a cub');
});
test('set new cubs', (assert) => {
lion.cubs = ['cub1', ' ', 'cub2'];
let actual = lion.value();
assert.is(actual, '<lion attr1="yup" attr2="yo">cub1 cub2</lion>', 'xmlion must set new cubs');
});
test('fail a set new cubs', (assert) => {
let block = () => {
lion.cubs = 'cub3';
};
let err = 'Lion wants cub[]';
assert.throws(block, err, 'Fail to set cubs that is not Array');
});
test('get cubs', (assert) => {
let cubs = ['cub1', 'cub7'];
lion.cubs = cubs;
assert.is(lion.cubs[1], cubs[1], 'last cub should be the same');
assert.not(lion.cubs, cubs, 'variable is not the same');
});
test('setCubs', (assert) => {
lion.setCubs(['cub3', 'cub5']);
assert.is(lion.cubs[1], 'cub5', 'last cub should be cub5');
});
test('getCubs', (assert) => {
assert.is(lion.getCubs()[0], 'cub3', 'first cub should be cub3');
});
test('setAttributes', (assert) => {
const lion = xmlion('lion');
lion.setAttributes({prideful: true});
assert.is(lion.value(), '<lion prideful="true"/>', 'expected prideful lion');
});