/
externals.tXml.js
62 lines (49 loc) · 2.85 KB
/
externals.tXml.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
import {expect} from 'chai';
import {translateEntitiesAndCharacterReferences, XML_ENTITIES} from '../../externals/tXml.js'
describe('tXml', () => {
describe('translateEntitiesAndCharacterReferences', () => {
it('should not change string without XML entities', () => {
expect(translateEntitiesAndCharacterReferences(XML_ENTITIES, 'PT634')).to.be.equal('PT634')
})
it('should translate general entity amp', () => {
expect(translateEntitiesAndCharacterReferences(XML_ENTITIES, 'PT634&')).to.be.equal('PT634&')
})
it('should translate general entity lt', () => {
expect(translateEntitiesAndCharacterReferences(XML_ENTITIES, 'PT634<')).to.be.equal('PT634<')
})
it('should translate general entity gt', () => {
expect(translateEntitiesAndCharacterReferences(XML_ENTITIES, 'PT634>')).to.be.equal('PT634>')
})
it('should translate general entity apos', () => {
expect(translateEntitiesAndCharacterReferences(XML_ENTITIES, 'PT634'')).to.be.equal('PT634\'')
})
it('should translate general entity quot', () => {
expect(translateEntitiesAndCharacterReferences(XML_ENTITIES, 'PT634"')).to.be.equal('PT634"')
})
it('should translate all general entities', () => {
const input = '& > < " '';
const expectedOutput = '& > < " \'';
expect(translateEntitiesAndCharacterReferences(XML_ENTITIES, input)).to.be.equal(expectedOutput)
})
it('should correctly translate decimal character references', () => {
const input = 'A B C';
const expectedOutput = 'A B C';
expect(translateEntitiesAndCharacterReferences(XML_ENTITIES, input)).to.be.equal(expectedOutput)
})
it('should correctly translate hexadecimal character references', () => {
const input = 'A B C';
const expectedOutput = 'A B C';
expect(translateEntitiesAndCharacterReferences(XML_ENTITIES, input)).to.be.equal(expectedOutput)
})
it('should correctly translate character references mixed with other text', () => {
const input = 'This is a test: A B C';
const expectedOutput = 'This is a test: A B C';
expect(translateEntitiesAndCharacterReferences(XML_ENTITIES, input)).to.be.equal(expectedOutput)
})
it('should correctly translate character references mixed with general entities and other text', () => {
const input = 'This is a test: A B C & > < " '';
const expectedOutput = 'This is a test: A B C & > < " \'';
expect(translateEntitiesAndCharacterReferences(XML_ENTITIES, input)).to.be.equal(expectedOutput)
})
})
})