-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontext_test.ts
100 lines (90 loc) · 3.46 KB
/
context_test.ts
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
// Copyright 2020 Masataka Kurihara. All rights reserved. MIT license.
import {
assertEquals,
} from './dev_deps.ts';
import {
Attribute,
AttributeInfo,
Element,
ElementInfo,
XMLParseContext,
} from './context.ts';
Deno.test('Attribute xmlns', () => {
const attribute = new Attribute('xmlns');
attribute.value = 'https://xmlp.test/xmlns';
assertEquals(attribute.qName, 'xmlns');
assertEquals(attribute.prefix, 'xmlns');
assertEquals(attribute.localPart, '');
assertEquals(attribute.value, 'https://xmlp.test/xmlns');
});
Deno.test('Element QName', () => {
const element = new Element('a:b');
assertEquals(element.qName, 'a:b');
assertEquals(element.prefix, 'a');
assertEquals(element.localPart, 'b');
});
Deno.test('Element newAttribute & peekAttribute & attributes & prefixMappings', () => {
const element = new Element('a');
element.newAttribute('b');
element.newAttribute('xmlns');
element.peekAttribute()!.value = 'https://xmlp.test/xmlns';
element.newAttribute('xmlns:a');
element.peekAttribute()!.value = 'https://xmlp.test/xmlns/a';
const attributes = element.attributes;
assertEquals(attributes[0].qName, 'b');
assertEquals(attributes[1].qName, 'xmlns');
assertEquals(attributes[2].qName, 'xmlns:a');
assertEquals(
element.prefixMappings,
[{ ns: '', uri: 'https://xmlp.test/xmlns' }, { ns: 'a', uri: 'https://xmlp.test/xmlns/a' }],
);
});
Deno.test('AttributeInfo', () => {
const attribute = new Attribute('xmlns');
attribute.uri = 'https://xmlp.test/xmlns';
attribute.value = 'https://xmlp.test/xmlns';
const attributeInfo = new AttributeInfo(attribute);
assertEquals(attributeInfo.qName, 'xmlns');
assertEquals(attributeInfo.prefix, 'xmlns');
assertEquals(attributeInfo.localPart, '');
assertEquals(attributeInfo.uri, 'https://xmlp.test/xmlns');
assertEquals(attributeInfo.value, 'https://xmlp.test/xmlns');
});
Deno.test('ElementInfo', () => {
const parent = new Element('parent');
const element = new Element('a:b', parent);
element.newAttribute('c');
element.uri = 'https://xmlp.test/xmlns/a';
element.emptyElement = true;
const elementInfo = new ElementInfo(element);
assertEquals(elementInfo.qName, 'a:b');
assertEquals(elementInfo.prefix, 'a');
assertEquals(elementInfo.localPart, 'b');
assertEquals(elementInfo.uri, 'https://xmlp.test/xmlns/a');
assertEquals(elementInfo.parent!.qName, 'parent');
assertEquals(elementInfo.attributes[0].qName, 'c');
assertEquals(elementInfo.emptyElement, true);
});
Deno.test('XMLParseContext memento & appendMemento & clearMemento', () => {
const cx = new XMLParseContext();
cx.appendMemento('a');
cx.appendMemento('b');
assertEquals(cx.memento, 'ab');
cx.clearMemento();
assertEquals(cx.memento, '');
});
Deno.test('XMLParseContext newElement & peekElement & popElement & elementLength', () => {
const cx = new XMLParseContext();
cx.newElement('a');
assertEquals(cx.peekElement()!.qName, 'a');
assertEquals(cx.elementLength, 1);
cx.newElement('b');
assertEquals(cx.elementLength, 2);
assertEquals(cx.popElement()!.qName, 'b');
assertEquals(cx.elementLength, 1);
});
Deno.test('XMLParseContext registerNamespace & getNamespaceURI', () => {
const cx = new XMLParseContext();
cx.registerNamespace('a', 'https://xmlp.test/xmlns/a');
assertEquals(cx.getNamespaceURI('a'), 'https://xmlp.test/xmlns/a');
});