1 |
|
2 | import { parse } from './fswquery-parse';
|
3 |
|
4 | it('should parse generic queries', () => {
|
5 | expect(parse('Q')).toEqual({
|
6 | query: true
|
7 | })
|
8 | expect(parse('Q-')).toEqual({
|
9 | query: true,
|
10 | style: true
|
11 | })
|
12 | })
|
13 |
|
14 | it('should parse prefix queries', () => {
|
15 | expect(parse('QT')).toEqual({
|
16 | query: true,
|
17 | prefix: { required: true }
|
18 | })
|
19 | expect(parse('QT-')).toEqual({
|
20 | query: true,
|
21 | prefix: { required: true },
|
22 | style: true
|
23 | })
|
24 | expect(parse('QAS10000R100t204S20500T')).toEqual({
|
25 | query: true,
|
26 | prefix: {
|
27 | required: true,
|
28 | parts: [
|
29 | 'S10000',
|
30 | ['100', '204'],
|
31 | 'S20500'
|
32 | ]
|
33 | }
|
34 | })
|
35 | expect(parse('QAS10000R100t204oS20500T')).toEqual({
|
36 | query: true,
|
37 | prefix: {
|
38 | required: true,
|
39 | parts: [
|
40 | 'S10000',
|
41 | [
|
42 | 'or',
|
43 | ['100', '204'],
|
44 | 'S20500'
|
45 | ]
|
46 | ]
|
47 | }
|
48 | })
|
49 | })
|
50 |
|
51 | it('should parse signbox queries', () => {
|
52 | expect(parse('QS20000')).toEqual({
|
53 | query: true,
|
54 | signbox: [
|
55 | { symbol: 'S20000' }
|
56 | ]
|
57 | })
|
58 | expect(parse('QS20000500x500')).toEqual({
|
59 | query: true,
|
60 | signbox: [
|
61 | {
|
62 | symbol: 'S20000',
|
63 | coord: [500, 500]
|
64 | }
|
65 | ]
|
66 | })
|
67 | expect(parse('QR100t105')).toEqual({
|
68 | query: true,
|
69 | signbox: [
|
70 | { range: ['100', '105'] }
|
71 | ]
|
72 | })
|
73 | expect(parse('QR100t105500x500')).toEqual({
|
74 | query: true,
|
75 | signbox: [
|
76 | {
|
77 | range: ['100', '105'],
|
78 | coord: [500, 500]
|
79 | }
|
80 | ]
|
81 | })
|
82 | expect(parse('QS20000R100t105500x500')).toEqual({
|
83 | query: true,
|
84 | signbox: [
|
85 | { symbol: 'S20000' },
|
86 | {
|
87 | range: ['100', '105'],
|
88 | coord: [500, 500]
|
89 | }
|
90 | ]
|
91 | })
|
92 | expect(parse('QS20000oR100t105500x500')).toEqual({
|
93 | query: true,
|
94 | signbox: [
|
95 | {
|
96 | or: [
|
97 | 'S20000',
|
98 | ['100', '105']
|
99 | ],
|
100 | coord: [500, 500]
|
101 | }
|
102 | ]
|
103 | })
|
104 | })
|
105 |
|
106 | it('should parse full example', () => {
|
107 | expect(parse('QAS10000R100t204S20500TS20000R100t105500x500V5-')).toEqual({
|
108 | query: true,
|
109 | prefix: {
|
110 | required: true,
|
111 | parts: [
|
112 | 'S10000',
|
113 | ['100', '204'],
|
114 | 'S20500'
|
115 | ]
|
116 | },
|
117 | signbox: [
|
118 | { symbol: 'S20000' },
|
119 | {
|
120 | range: ['100', '105'],
|
121 | coord: [500, 500]
|
122 | }
|
123 | ],
|
124 | variance: 5,
|
125 | style: true
|
126 | })
|
127 | })
|
128 | it('should not break on invalid sign or input', () => {
|
129 | expect(parse()).toEqual({})
|
130 | expect(parse('a')).toEqual({})
|
131 | expect(parse({ 'a': 5 })).toEqual({})
|
132 | expect(parse(['a'])).toEqual({})
|
133 | })
|