forked from legastero/stanza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchildAlternateLanguageText.ts
64 lines (56 loc) · 2.03 KB
/
childAlternateLanguageText.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
import expect from 'expect';
import { childAlternateLanguageText, LanguageSet, parse, Registry } from '../../../src/jxt';
interface Example {
foo?: LanguageSet<string>;
}
const registry = new Registry();
registry.define({
element: 'x',
fields: {
foo: childAlternateLanguageText(null, 'foo')
},
namespace: '',
path: 'example'
});
test('[Type: childAlternateLanguageText] Basic import', () => {
const xml = parse(`
<x xml:lang="sv">
<foo xml:lang="no">Hallo verden</foo>
<foo xml:lang="en-US">Hello world, from the US</foo>
<foo xml:lang="en">Hello world</foo>
<foo xml:lang="en-CA">Hello world, from Canada</foo>
<foo>Hej världen</foo>
<foo xml:lang="es">Hola mundo</foo>
<foo xml:lang="de">Hallo Welt</foo>
</x>`);
const ex = registry.import(xml) as Example;
expect(ex).toBeTruthy();
expect(ex).toEqual({
foo: [
{ lang: 'no', value: 'Hallo verden' },
{ lang: 'en-us', value: 'Hello world, from the US' },
{ lang: 'en', value: 'Hello world' },
{ lang: 'en-ca', value: 'Hello world, from Canada' },
{ lang: 'sv', value: 'Hej världen' },
{ lang: 'es', value: 'Hola mundo' },
{ lang: 'de', value: 'Hallo Welt' }
]
});
});
test('[Type: childAlternateLanguageText] Basic export', () => {
const data: Example = {
foo: [
{ lang: 'no', value: 'Hallo verden' },
{ lang: 'en-us', value: 'Hello world, from the US' },
{ lang: 'en', value: 'Hello world' },
{ lang: 'en-ca', value: 'Hello world, from Canada' },
{ lang: 'sv', value: 'Hej världen' },
{ lang: 'es', value: 'Hola mundo' },
{ lang: 'de', value: 'Hallo Welt' }
]
};
const ex = registry.export('example', data);
expect(ex).toBeTruthy();
const reimported = registry.import(ex!) as Example;
expect(data).toEqual(reimported);
});