1 |
|
2 | import { encode, decode, pair, parse } from './swu-parse';
|
3 |
|
4 | it('should parse a symbol', () => {
|
5 | expect(parse.symbol('ń')).toEqual({ symbol: 'ń' })
|
6 | })
|
7 |
|
8 | it('should parse a symbol with coordinate', () => {
|
9 | expect(parse.symbol('ńđ€đ€')).toEqual({ symbol: 'ń', coord: [500, 500] })
|
10 | })
|
11 |
|
12 | it('should parse a symbol with style', () => {
|
13 | expect(parse.symbol('ń-C')).toEqual({ symbol: 'ń', style: '-C' })
|
14 | })
|
15 |
|
16 | it('should not break on invalid symbol key or input', () => {
|
17 | expect(parse.symbol()).toEqual({})
|
18 | expect(parse.symbol('a')).toEqual({})
|
19 | expect(parse.symbol({ 'a': 5 })).toEqual({})
|
20 | expect(parse.symbol(['a'])).toEqual({})
|
21 | })
|
22 |
|
23 | it('should parse an empty signbox', () => {
|
24 | expect(parse.sign('đ đ€đ€')).toEqual({
|
25 | box: 'đ ',
|
26 | max: [500, 500]
|
27 | })
|
28 | })
|
29 |
|
30 | it('should parse a plain signbox', () => {
|
31 | expect(parse.sign('đ đ€đ€©ń©đŁ”đ€ńđ€đŁ€ń„đ€đ€ńđŁźđŁ')).toEqual({
|
32 | box: 'đ ',
|
33 | max: [525, 535],
|
34 | spatials: [
|
35 | {
|
36 | symbol: 'ń©',
|
37 | coord: [483, 510]
|
38 | },
|
39 |
|
40 | {
|
41 | symbol: 'ń',
|
42 | coord: [501, 466]
|
43 | },
|
44 |
|
45 | {
|
46 | symbol: 'ń„',
|
47 | coord: [510, 500]
|
48 | },
|
49 |
|
50 | {
|
51 | symbol: 'ń',
|
52 | coord: [476, 475]
|
53 | }
|
54 | ]
|
55 | })
|
56 | })
|
57 |
|
58 |
|
59 | it('should parse a prefixed signbox', () => {
|
60 | expect(parse.sign('đ ńńń„ń©đ đ€đ€©ń©đŁ”đ€ńđ€đŁ€ń„đ€đ€ńđŁźđŁ')).toEqual({
|
61 | sequence: ['ń', 'ń', 'ń„', 'ń©'],
|
62 | box: 'đ ',
|
63 | max: [525, 535],
|
64 | spatials: [
|
65 | {
|
66 | symbol: 'ń©',
|
67 | coord: [483, 510]
|
68 | },
|
69 |
|
70 | {
|
71 | symbol: 'ń',
|
72 | coord: [501, 466]
|
73 | },
|
74 |
|
75 | {
|
76 | symbol: 'ń„',
|
77 | coord: [510, 500]
|
78 | },
|
79 |
|
80 | {
|
81 | symbol: 'ń',
|
82 | coord: [476, 475]
|
83 | }
|
84 | ]
|
85 | })
|
86 | })
|
87 |
|
88 | it('should parse a prefixed signbox with style', () => {
|
89 | expect(parse.sign('đ ńńń„ń©đ đ€đ€©ń©đŁ”đ€ńđ€đŁ€ń„đ€đ€ńđŁźđŁ-C')).toEqual({
|
90 | sequence: ['ń', 'ń', 'ń„', 'ń©'],
|
91 | box: 'đ ',
|
92 | max: [525, 535],
|
93 | spatials: [
|
94 | {
|
95 | symbol: 'ń©',
|
96 | coord: [483, 510]
|
97 | },
|
98 |
|
99 | {
|
100 | symbol: 'ń',
|
101 | coord: [501, 466]
|
102 | },
|
103 |
|
104 | {
|
105 | symbol: 'ń„',
|
106 | coord: [510, 500]
|
107 | },
|
108 |
|
109 | {
|
110 | symbol: 'ń',
|
111 | coord: [476, 475]
|
112 | }
|
113 | ],
|
114 | style: '-C'
|
115 | })
|
116 | })
|
117 |
|
118 | it('should not break on invalid sign or input', () => {
|
119 | expect(parse.sign()).toEqual({})
|
120 | expect(parse.sign('a')).toEqual({})
|
121 | expect(parse.sign({ 'a': 5 })).toEqual({})
|
122 | expect(parse.sign(['a'])).toEqual({})
|
123 | })
|
124 |
|
125 | it('should parse a text', () => {
|
126 | expect(parse.text('đ ńČĄń©§đ đ€đ€ŁńČĄđŁłđŁ©ń©§đ€đŁ» đ ńąń«ńńĄđ đ€đ€§ń«đŁ»đ€ńąđŁŽđŁŒńĄđ€đ€ńđ€đŁŠ ńđŁąđ€')).toEqual([
|
127 | 'đ ńČĄń©§đ đ€đ€ŁńČĄđŁłđŁ©ń©§đ€đŁ»',
|
128 | 'đ ńąń«ńńĄđ đ€đ€§ń«đŁ»đ€ńąđŁŽđŁŒńĄđ€đ€ńđ€đŁŠ',
|
129 | 'ńđŁąđ€'
|
130 | ])
|
131 | })
|
132 |
|
133 | it('should parse a text with style', () => {
|
134 | expect(parse.text('đ ńČĄń©§đ đ€đ€ŁńČĄđŁłđŁ©ń©§đ€đŁ»-C đ ńąń«ńńĄđ đ€đ€§ń«đŁ»đ€ńąđŁŽđŁŒńĄđ€đ€ńđ€đŁŠ ńđŁąđ€-Z2')).toEqual([
|
135 | 'đ ńČĄń©§đ đ€đ€ŁńČĄđŁłđŁ©ń©§đ€đŁ»-C',
|
136 | 'đ ńąń«ńńĄđ đ€đ€§ń«đŁ»đ€ńąđŁŽđŁŒńĄđ€đ€ńđ€đŁŠ',
|
137 | 'ńđŁąđ€-Z2'
|
138 | ])
|
139 | })
|
140 |
|
141 | it('should not break on invalid text or input', () => {
|
142 | expect(parse.text()).toEqual([])
|
143 | expect(parse.text('a')).toEqual([])
|
144 | expect(parse.text({ 'a': 5 })).toEqual([])
|
145 | expect(parse.text(['a'])).toEqual([])
|
146 | })
|
147 |
|
148 | it('should encode swu characters', () => {
|
149 | expect(encode('ńđ€đ€')).toBe('\\uD8C0\\uDC01\\uD836\\uDD06\\uD836\\uDD06');
|
150 | })
|
151 |
|
152 | it('should decode swu characters', () => {
|
153 | expect(decode('\\uD8C0\\uDC01\\uD836\\uDD06\\uD836\\uDD06')).toBe('ńđ€đ€');
|
154 | })
|
155 |
|
156 | it('should return the utf-16 pair for a swu char', () => {
|
157 | expect(pair('ń')).toEqual(['D8C0', 'DC01']);
|
158 | })
|