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 | })
|
36 |
|
37 | it('should parse signbox queries', () => {
|
38 | expect(parse('QS20000')).toEqual({
|
39 | query: true,
|
40 | signbox: [
|
41 | { symbol: 'S20000' }
|
42 | ]
|
43 | })
|
44 | expect(parse('QS20000500x500')).toEqual({
|
45 | query: true,
|
46 | signbox: [
|
47 | {
|
48 | symbol: 'S20000',
|
49 | coord: [500, 500]
|
50 | }
|
51 | ]
|
52 | })
|
53 | expect(parse('QR100t105')).toEqual({
|
54 | query: true,
|
55 | signbox: [
|
56 | { range: ['100', '105'] }
|
57 | ]
|
58 | })
|
59 | expect(parse('QR100t105500x500')).toEqual({
|
60 | query: true,
|
61 | signbox: [
|
62 | {
|
63 | range: ['100', '105'],
|
64 | coord: [500, 500]
|
65 | }
|
66 | ]
|
67 | })
|
68 | expect(parse('QS20000R100t105500x500')).toEqual({
|
69 | query: true,
|
70 | signbox: [
|
71 | { symbol: 'S20000' },
|
72 | {
|
73 | range: ['100', '105'],
|
74 | coord: [500, 500]
|
75 | }
|
76 | ]
|
77 | })
|
78 | })
|
79 |
|
80 | it('should parse full example', () => {
|
81 | expect(parse('QAS10000R100t204S20500TS20000R100t105500x500V5-')).toEqual({
|
82 | query: true,
|
83 | prefix: {
|
84 | required: true,
|
85 | parts: [
|
86 | 'S10000',
|
87 | ['100', '204'],
|
88 | 'S20500'
|
89 | ]
|
90 | },
|
91 | signbox: [
|
92 | { symbol: 'S20000' },
|
93 | {
|
94 | range: ['100', '105'],
|
95 | coord: [500, 500]
|
96 | }
|
97 | ],
|
98 | variance: 5,
|
99 | style: true
|
100 | })
|
101 | })
|
102 | it('should not break on invalid sign or input', () => {
|
103 | expect(parse()).toEqual({})
|
104 | expect(parse('a')).toEqual({})
|
105 | expect(parse({ 'a': 5 })).toEqual({})
|
106 | expect(parse(['a'])).toEqual({})
|
107 | })
|