-
Notifications
You must be signed in to change notification settings - Fork 3
/
scpiParser_test.go
171 lines (154 loc) · 4.83 KB
/
scpiParser_test.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package main
import (
"strings"
"testing"
)
func BenchmarkVxgScpi(b *testing.B) {
for i := 0; i < b.N; i++ {
head := scpiNode{}
lines, _ := readLinesFromPath("benchmark_SCPI.txt")
commands := splitScpiCommands(lines)
for _, command := range commands {
createScpiTreeBranch(command, &head)
}
}
}
func TestScpiParserTwoOptionals(t *testing.T) {
lines := []string{":DIAGnostic[:CPU]:BLOCk:ABUS:LIST[:SINGle]"}
commands := splitScpiCommands(lines)
if len(commands) != 8 {
t.Error(":DIAGnostic[:CPU]:BLOCk:ABUS:LIST[:SINGle] not parsed properly:", commands)
return
}
}
func TestScpiParserThreeOptionals(t *testing.T) {
lines := []string{"[:SOURce]:AMPLitude[:LEVel]:STEP[:INCRement]"}
commands := splitScpiCommands(lines)
if len(commands) != 16 {
t.Error("[:SOURce]:AMPLitude[:LEVel]:STEP[:INCRement] not parsed properly:", commands)
return
}
}
func TestScpiParserFourOptionals(t *testing.T) {
lines := []string{"[:SOURce]:FREQuency[:CW][:FIXed][:FIXed]"}
commands := splitScpiCommands(lines)
if len(commands) != 32 {
t.Error("[:SOURce]:FREQuency[:CW][:FIXed][:FIXed] not parsed properly:", commands)
return
}
}
func TestScpiParserFirstOptional(t *testing.T) {
lines := []string{"[:SOURce]:FREQuency:SPAN"}
commands := splitScpiCommands(lines)
if len(commands) != 4 {
t.Error("[:SOURce]:FREQuency:SPAN not parsed properly:", commands)
return
}
}
func TestScpiParserNoQuery(t *testing.T) {
lines := []string{":ABORt/nquery/"}
commands := splitScpiCommands(lines)
if len(commands) != 1 {
t.Error(":ABORt/nquery/ not parsed properly:", commands[0])
return
}
if len(commands[0]) != 1 {
t.Error(":ABORt/nquery/ not parsed properly:", commands[0])
}
}
func TestScpiParserOptionalsNoQuery(t *testing.T) {
lines := []string{":ABORt[:SWEep]/nquery/"}
commands := splitScpiCommands(lines)
if len(commands) != 2 {
t.Error(":ABORt[:SWEep]/nquery/ not parsed properly:", commands)
return
}
if len(commands[0]) != 2 {
t.Error(":ABORt[:SWEep]/nquery/ not parsed properly:", commands[0])
}
if len(commands[1]) != 1 {
t.Error(":ABORt[:SWEep]/nquery/ not parsed properly:", commands[1])
}
}
func TestScpiParserOptionals(t *testing.T) {
lines := []string{":ABORt[:SWEep]"}
commands := splitScpiCommands(lines)
if len(commands) != 4 {
t.Error(":ABORt[:SWEep] not parsed properly:", commands)
return
}
if len(commands[0]) != 2 {
t.Error(":ABORt[:SWEep] not parsed properly:", commands[0])
}
if len(commands[2]) != 1 {
t.Error(":ABORt[:SWEep] not parsed properly:", commands[2])
}
}
func TestScpiParserBasic(t *testing.T) {
lines := []string{":CALibration:BBG:CHANnel:OFFSet"}
commands := splitScpiCommands(lines)
if len(commands) != 2 {
t.Error(":CALibration:BBG:CHANnel:OFFSet not parsed properly:", commands)
return
}
if len(commands[0]) != 4 {
t.Error(":CALibration:BBG:CHANnel:OFFSet not parsed properly:", commands[0])
}
if len(commands[1]) != 4 {
t.Error(":CALibration:BBG:CHANnel:OFFSet not parsed properly:", commands[1])
}
}
func TestScpiParserOneBar(t *testing.T) {
lines := []string{"Hello|Goodbye:My:Friend/nquery/"}
commands := splitScpiCommands(lines)
if len(commands) != 2 {
t.Error(":Hello|Goodbye:My:Friend/nquery not parsed properly")
}
if len(commands[0]) != 3 {
t.Error(":Hello|Goodbye:My:Friend/nquery not parsed properly")
}
}
func TestScpiParserMultipleBarsNoQuery(t *testing.T) {
lines := []string{"Hello|Goodbye:My:Friend|Love/nquery/"}
commands := splitScpiCommands(lines)
if len(commands) != 4 {
t.Error(":Hello|Goodbye:My:Friend|Love/nquery not parsed properly")
}
if len(commands[0]) != 3 {
t.Error(":Hello|Goodbye:My:Friend|Love/nquery not parsed properly")
}
}
func TestScpiParserMultipleBarsCommandAndQuery(t *testing.T) {
lines := []string{"Hello|Goodbye:My:Friend|Love"}
commands := splitScpiCommands(lines)
if len(commands) != 8 {
t.Error(":Hello|Goodbye:My:Friend|Love not parsed properly")
}
if len(commands[0]) != 3 {
t.Error(":Hello|Goodbye:My:Friend|Love not parsed properly")
}
if !strings.HasSuffix(commands[7][len(commands[2])-1].Text, "?") {
t.Error(":Hello|Goodbye:My:Friend|Love corner case failed, ? not transferred to both options")
}
if !strings.HasSuffix(commands[6][len(commands[2])-1].Text, "?") {
t.Error(":Hello|Goodbye:My:Friend|Love corner case failed, ? not transferred to both options")
}
}
func TestScpiParserSuffix(t *testing.T) {
line := ":SOURce:RADio{1:1}:ALL:OFF/nquery/"
command := reformatSuffixes(line)
if !strings.Contains(command, "@") {
t.Error(line, " Not parsed properly")
}
}
func TestScpiParserIrregularSuffix(t *testing.T) {
line := ":SOURce1:RADio1:ALL:OFF/nquery/"
command := reformatIrregularSuffixes(line)
if !strings.Contains(command, "@") {
t.Error(line, " Not parsed properly")
}
}
func TestGenerateTree(t *testing.T) {
lines, _ := readLinesFromPath("SCPI.txt")
parseScpi(lines) //TODO: Generate real tests
}