hotdog 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hotdog/commands.rb +19 -19
- data/lib/hotdog/commands/search.rb +4 -4
- data/lib/hotdog/commands/tags.rb +4 -4
- data/lib/hotdog/expression.rb +50 -50
- data/lib/hotdog/expression/semantics.rb +97 -93
- data/lib/hotdog/expression/syntax.rb +31 -31
- data/lib/hotdog/version.rb +1 -1
- data/spec/{parser → evaluator}/glob_expression_spec.rb +19 -14
- data/spec/{parser → evaluator}/regexp_expression_spec.rb +19 -14
- data/spec/{parser → evaluator}/string_expression_spec.rb +19 -14
- data/spec/optimizer/binary_expression_spec.rb +47 -0
- data/spec/optimizer/glob_expression_spec.rb +105 -0
- data/spec/optimizer/regexp_expression_spec.rb +55 -0
- data/spec/optimizer/string_expression_spec.rb +105 -0
- data/spec/optimizer/unary_expression_spec.rb +23 -0
- data/spec/parser/parser_spec.rb +82 -82
- metadata +18 -8
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/application"
|
3
|
+
require "hotdog/commands"
|
4
|
+
require "hotdog/commands/search"
|
5
|
+
require "parslet"
|
6
|
+
|
7
|
+
describe "tag regexp expression" do
|
8
|
+
it "interprets tag regexp with host" do
|
9
|
+
expr = Hotdog::Expression::RegexpHostNode.new("foo", ":")
|
10
|
+
expect(expr.optimize.dump).to eq({
|
11
|
+
tagname_regexp: "host",
|
12
|
+
separator: ":",
|
13
|
+
tagvalue_regexp: "foo",
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
17
|
+
it "interprets tag regexp with tagname and tagvalue" do
|
18
|
+
expr = Hotdog::Expression::RegexpTagNode.new("foo", "bar", ":")
|
19
|
+
expect(expr.optimize.dump).to eq({
|
20
|
+
tagname_regexp: "foo",
|
21
|
+
separator: ":",
|
22
|
+
tagvalue_regexp: "bar",
|
23
|
+
})
|
24
|
+
end
|
25
|
+
|
26
|
+
it "interprets tag regexp with tagname with separator" do
|
27
|
+
expr = Hotdog::Expression::RegexpTagnameNode.new("foo", ":")
|
28
|
+
expect(expr.optimize.dump).to eq({
|
29
|
+
tagname_regexp: "foo",
|
30
|
+
separator: ":",
|
31
|
+
})
|
32
|
+
end
|
33
|
+
|
34
|
+
it "interprets tag regexp with tagname without separator" do
|
35
|
+
expr = Hotdog::Expression::RegexpHostOrTagNode.new("foo", nil)
|
36
|
+
expect(expr.optimize.dump).to eq({
|
37
|
+
tagname_regexp: "foo",
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
41
|
+
it "interprets tag regexp with tagvalue with separator" do
|
42
|
+
expr = Hotdog::Expression::RegexpTagvalueNode.new("foo", ":")
|
43
|
+
expect(expr.optimize.dump).to eq({
|
44
|
+
separator: ":",
|
45
|
+
tagvalue_regexp: "foo",
|
46
|
+
})
|
47
|
+
end
|
48
|
+
|
49
|
+
it "interprets tag regexp with tagvalue without separator" do
|
50
|
+
expr = Hotdog::Expression::RegexpTagvalueNode.new("foo", nil)
|
51
|
+
expect(expr.optimize.dump).to eq({
|
52
|
+
tagvalue_regexp: "foo",
|
53
|
+
})
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/application"
|
3
|
+
require "hotdog/commands"
|
4
|
+
require "hotdog/commands/search"
|
5
|
+
require "parslet"
|
6
|
+
|
7
|
+
describe "tag expression" do
|
8
|
+
it "interprets tag with host" do
|
9
|
+
expr = Hotdog::Expression::StringHostNode.new("foo", ":")
|
10
|
+
expect(expr.optimize.dump).to eq({
|
11
|
+
tagname: "host",
|
12
|
+
separator: ":",
|
13
|
+
tagvalue: "foo",
|
14
|
+
fallback: {
|
15
|
+
query: [
|
16
|
+
"SELECT hosts.id AS host_id FROM hosts",
|
17
|
+
"WHERE LOWER(hosts.name) GLOB LOWER(?);",
|
18
|
+
].join(" "),
|
19
|
+
values: ["*foo*"],
|
20
|
+
},
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
it "interprets tag with tagname and tagvalue" do
|
25
|
+
expr = Hotdog::Expression::StringTagNode.new("foo", "bar", ":")
|
26
|
+
expect(expr.optimize.dump).to eq({
|
27
|
+
tagname: "foo",
|
28
|
+
separator: ":",
|
29
|
+
tagvalue: "bar",
|
30
|
+
fallback: {
|
31
|
+
query: [
|
32
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
33
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
34
|
+
"WHERE LOWER(tags.name) GLOB LOWER(?) AND LOWER(tags.value) GLOB LOWER(?);",
|
35
|
+
].join(" "),
|
36
|
+
values: ["*foo*", "*bar*"],
|
37
|
+
},
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
41
|
+
it "interprets tag with tagname with separator" do
|
42
|
+
expr = Hotdog::Expression::StringTagnameNode.new("foo", ":")
|
43
|
+
expect(expr.optimize.dump).to eq({
|
44
|
+
tagname: "foo",
|
45
|
+
separator: ":",
|
46
|
+
fallback: {
|
47
|
+
query: [
|
48
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
49
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
50
|
+
"WHERE LOWER(tags.name) GLOB LOWER(?);",
|
51
|
+
].join(" "),
|
52
|
+
values: ["*foo*"],
|
53
|
+
}
|
54
|
+
})
|
55
|
+
end
|
56
|
+
|
57
|
+
it "interprets tag with tagname without separator" do
|
58
|
+
expr = Hotdog::Expression::StringHostOrTagNode.new("foo", nil)
|
59
|
+
expect(expr.optimize.dump).to eq({
|
60
|
+
tagname: "foo",
|
61
|
+
fallback: {
|
62
|
+
query: [
|
63
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
64
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
65
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
66
|
+
"WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
|
67
|
+
].join(" "),
|
68
|
+
values: ["*foo*", "*foo*", "*foo*"],
|
69
|
+
},
|
70
|
+
})
|
71
|
+
end
|
72
|
+
|
73
|
+
it "interprets tag with tagvalue with separator" do
|
74
|
+
expr = Hotdog::Expression::StringTagvalueNode.new("foo", ":")
|
75
|
+
expect(expr.optimize.dump).to eq({
|
76
|
+
tagvalue: "foo",
|
77
|
+
separator: ":",
|
78
|
+
fallback: {
|
79
|
+
query: [
|
80
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
81
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
82
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
83
|
+
"WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
|
84
|
+
].join(" "),
|
85
|
+
values: ["*foo*", "*foo*"],
|
86
|
+
},
|
87
|
+
})
|
88
|
+
end
|
89
|
+
|
90
|
+
it "interprets tag with tagvalue without separator" do
|
91
|
+
expr = Hotdog::Expression::StringTagvalueNode.new("foo", nil)
|
92
|
+
expect(expr.optimize.dump).to eq({
|
93
|
+
tagvalue: "foo",
|
94
|
+
fallback: {
|
95
|
+
query: [
|
96
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
97
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
98
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
99
|
+
"WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
|
100
|
+
].join(" "),
|
101
|
+
values: ["*foo*", "*foo*"],
|
102
|
+
},
|
103
|
+
})
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/application"
|
3
|
+
require "hotdog/commands"
|
4
|
+
require "hotdog/commands/search"
|
5
|
+
require "parslet"
|
6
|
+
|
7
|
+
describe "unary expression" do
|
8
|
+
it "should be everything" do
|
9
|
+
expr = Hotdog::Expression::UnaryExpressionNode.new("NOT", Hotdog::Expression::NothingNode.new())
|
10
|
+
expect(expr.optimize.dump).to eq({
|
11
|
+
query: "SELECT id AS host_id FROM hosts;",
|
12
|
+
values: [],
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be nothing" do
|
17
|
+
expr = Hotdog::Expression::UnaryExpressionNode.new("NOT", Hotdog::Expression::EverythingNode.new())
|
18
|
+
expect(expr.optimize.dump).to eq({
|
19
|
+
query: "SELECT NULL AS host_id WHERE host_id NOT NULL;",
|
20
|
+
values: [],
|
21
|
+
})
|
22
|
+
end
|
23
|
+
end
|
data/spec/parser/parser_spec.rb
CHANGED
@@ -15,287 +15,287 @@ describe "parser" do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "parses ':foo'" do
|
18
|
-
expect(cmd.parse(":foo")).to eq({separator: ":",
|
18
|
+
expect(cmd.parse(":foo")).to eq({separator: ":", tagvalue: "foo"})
|
19
19
|
end
|
20
20
|
|
21
21
|
it "parses ':foo*'" do
|
22
|
-
expect(cmd.parse(":foo*")).to eq({separator: ":",
|
22
|
+
expect(cmd.parse(":foo*")).to eq({separator: ":", tagvalue_glob: "foo*"})
|
23
23
|
end
|
24
24
|
|
25
25
|
it "parses ':/foo/'" do
|
26
|
-
expect(cmd.parse(":/foo/")).to eq({separator: ":",
|
26
|
+
expect(cmd.parse(":/foo/")).to eq({separator: ":", tagvalue_regexp: "/foo/"})
|
27
27
|
end
|
28
28
|
|
29
29
|
it "parses 'foo'" do
|
30
|
-
expect(cmd.parse("foo")).to eq({
|
30
|
+
expect(cmd.parse("foo")).to eq({tagname: "foo"})
|
31
31
|
end
|
32
32
|
|
33
33
|
it "parses 'foo:bar'" do
|
34
|
-
expect(cmd.parse("foo:bar")).to eq({
|
34
|
+
expect(cmd.parse("foo:bar")).to eq({tagname: "foo", separator: ":", tagvalue: "bar"})
|
35
35
|
end
|
36
36
|
|
37
37
|
it "parses 'foo: bar'" do
|
38
|
-
expect(cmd.parse("foo:bar")).to eq({
|
38
|
+
expect(cmd.parse("foo:bar")).to eq({tagname: "foo", separator: ":", tagvalue: "bar"})
|
39
39
|
end
|
40
40
|
|
41
41
|
it "parses 'foo :bar'" do
|
42
|
-
expect(cmd.parse("foo:bar")).to eq({
|
42
|
+
expect(cmd.parse("foo:bar")).to eq({tagname: "foo", separator: ":", tagvalue: "bar"})
|
43
43
|
end
|
44
44
|
|
45
45
|
it "parses 'foo : bar'" do
|
46
|
-
expect(cmd.parse("foo:bar")).to eq({
|
46
|
+
expect(cmd.parse("foo:bar")).to eq({tagname: "foo", separator: ":", tagvalue: "bar"})
|
47
47
|
end
|
48
48
|
|
49
49
|
it "parses 'foo:bar*'" do
|
50
|
-
expect(cmd.parse("foo:bar*")).to eq({
|
50
|
+
expect(cmd.parse("foo:bar*")).to eq({tagname: "foo", separator: ":", tagvalue_glob: "bar*"})
|
51
51
|
end
|
52
52
|
|
53
53
|
it "parses 'foo*'" do
|
54
|
-
expect(cmd.parse("foo*")).to eq({
|
54
|
+
expect(cmd.parse("foo*")).to eq({tagname_glob: "foo*"})
|
55
55
|
end
|
56
56
|
|
57
57
|
it "parses 'foo*:bar'" do
|
58
|
-
expect(cmd.parse("foo*:bar")).to eq({
|
58
|
+
expect(cmd.parse("foo*:bar")).to eq({tagname_glob: "foo*", separator: ":", tagvalue: "bar"})
|
59
59
|
end
|
60
60
|
|
61
61
|
it "parses 'foo*:bar*'" do
|
62
|
-
expect(cmd.parse("foo*:bar*")).to eq({
|
62
|
+
expect(cmd.parse("foo*:bar*")).to eq({tagname_glob: "foo*", separator: ":", tagvalue_glob: "bar*"})
|
63
63
|
end
|
64
64
|
|
65
65
|
it "parses '/foo/'" do
|
66
|
-
expect(cmd.parse("/foo/")).to eq({
|
66
|
+
expect(cmd.parse("/foo/")).to eq({tagname_regexp: "/foo/"})
|
67
67
|
end
|
68
68
|
|
69
69
|
it "parses '/foo/:/bar/'" do
|
70
|
-
expect(cmd.parse("/foo/:/bar/")).to eq({
|
70
|
+
expect(cmd.parse("/foo/:/bar/")).to eq({tagname_regexp: "/foo/", separator: ":", tagvalue_regexp: "/bar/"})
|
71
71
|
end
|
72
72
|
|
73
73
|
it "parses '(foo)'" do
|
74
|
-
expect(cmd.parse("(foo)")).to eq({
|
74
|
+
expect(cmd.parse("(foo)")).to eq({tagname: "foo"})
|
75
75
|
end
|
76
76
|
|
77
77
|
it "parses '( foo )'" do
|
78
|
-
expect(cmd.parse("( foo )")).to eq({
|
78
|
+
expect(cmd.parse("( foo )")).to eq({tagname: "foo"})
|
79
79
|
end
|
80
80
|
|
81
81
|
it "parses ' ( foo ) '" do
|
82
|
-
expect(cmd.parse(" ( foo ) ")).to eq({
|
82
|
+
expect(cmd.parse(" ( foo ) ")).to eq({tagname: "foo"})
|
83
83
|
end
|
84
84
|
|
85
85
|
it "parses '((foo))'" do
|
86
|
-
expect(cmd.parse("((foo))")).to eq({
|
86
|
+
expect(cmd.parse("((foo))")).to eq({tagname: "foo"})
|
87
87
|
end
|
88
88
|
|
89
89
|
it "parses '(( foo ))'" do
|
90
|
-
expect(cmd.parse("(( foo ))")).to eq({
|
90
|
+
expect(cmd.parse("(( foo ))")).to eq({tagname: "foo"})
|
91
91
|
end
|
92
92
|
|
93
93
|
it "parses ' ( ( foo ) ) '" do
|
94
|
-
expect(cmd.parse("( ( foo ) )")).to eq({
|
94
|
+
expect(cmd.parse("( ( foo ) )")).to eq({tagname: "foo"})
|
95
95
|
end
|
96
96
|
|
97
|
-
it "parses '
|
98
|
-
expect(cmd.parse("android")).to eq({
|
97
|
+
it "parses 'tagname with prefix and'" do
|
98
|
+
expect(cmd.parse("android")).to eq({tagname: "android"})
|
99
99
|
end
|
100
100
|
|
101
|
-
it "parses '
|
102
|
-
expect(cmd.parse("islander")).to eq({
|
101
|
+
it "parses 'tagname with infix and'" do
|
102
|
+
expect(cmd.parse("islander")).to eq({tagname: "islander"})
|
103
103
|
end
|
104
104
|
|
105
|
-
it "parses '
|
106
|
-
expect(cmd.parse("mainland")).to eq({
|
105
|
+
it "parses 'tagname with suffix and'" do
|
106
|
+
expect(cmd.parse("mainland")).to eq({tagname: "mainland"})
|
107
107
|
end
|
108
108
|
|
109
|
-
it "parses '
|
110
|
-
expect(cmd.parse("oreo")).to eq({
|
109
|
+
it "parses 'tagname with prefix or'" do
|
110
|
+
expect(cmd.parse("oreo")).to eq({tagname: "oreo"})
|
111
111
|
end
|
112
112
|
|
113
|
-
it "parses '
|
114
|
-
expect(cmd.parse("category")).to eq({
|
113
|
+
it "parses 'tagname with infix or'" do
|
114
|
+
expect(cmd.parse("category")).to eq({tagname: "category"})
|
115
115
|
end
|
116
116
|
|
117
|
-
it "parses '
|
118
|
-
expect(cmd.parse("imperator")).to eq({
|
117
|
+
it "parses 'tagname with suffix or'" do
|
118
|
+
expect(cmd.parse("imperator")).to eq({tagname: "imperator"})
|
119
119
|
end
|
120
120
|
|
121
|
-
it "parses '
|
122
|
-
expect(cmd.parse("nothing")).to eq({
|
121
|
+
it "parses 'tagname with prefix not'" do
|
122
|
+
expect(cmd.parse("nothing")).to eq({tagname: "nothing"})
|
123
123
|
end
|
124
124
|
|
125
|
-
it "parses '
|
126
|
-
expect(cmd.parse("annotation")).to eq({
|
125
|
+
it "parses 'tagname with infix not'" do
|
126
|
+
expect(cmd.parse("annotation")).to eq({tagname: "annotation"})
|
127
127
|
end
|
128
128
|
|
129
|
-
it "parses '
|
130
|
-
expect(cmd.parse("forgetmenot")).to eq({
|
129
|
+
it "parses 'tagname with suffix not'" do
|
130
|
+
expect(cmd.parse("forgetmenot")).to eq({tagname: "forgetmenot"})
|
131
131
|
end
|
132
132
|
|
133
133
|
it "parses 'foo bar'" do
|
134
|
-
expect(cmd.parse("foo bar")).to eq({left: {
|
134
|
+
expect(cmd.parse("foo bar")).to eq({left: {tagname: "foo"}, binary_op: nil, right: {tagname: "bar"}})
|
135
135
|
end
|
136
136
|
|
137
137
|
it "parses 'foo bar baz'" do
|
138
|
-
expect(cmd.parse("foo bar baz")).to eq({left: {
|
138
|
+
expect(cmd.parse("foo bar baz")).to eq({left: {tagname: "foo"}, binary_op: nil, right: {left: {tagname: "bar"}, binary_op: nil, right: {tagname: "baz"}}})
|
139
139
|
end
|
140
140
|
|
141
141
|
it "parses 'not foo'" do
|
142
|
-
expect(cmd.parse("not foo")).to eq({unary_op: "not", expression: {
|
142
|
+
expect(cmd.parse("not foo")).to eq({unary_op: "not", expression: {tagname: "foo"}})
|
143
143
|
end
|
144
144
|
|
145
145
|
it "parses '! foo'" do
|
146
|
-
expect(cmd.parse("! foo")).to eq({unary_op: "!", expression: {
|
146
|
+
expect(cmd.parse("! foo")).to eq({unary_op: "!", expression: {tagname: "foo"}})
|
147
147
|
end
|
148
148
|
|
149
149
|
it "parses '~ foo'" do
|
150
|
-
expect(cmd.parse("~ foo")).to eq({unary_op: "~", expression: {
|
150
|
+
expect(cmd.parse("~ foo")).to eq({unary_op: "~", expression: {tagname: "foo"}})
|
151
151
|
end
|
152
152
|
|
153
153
|
it "parses 'not(not foo)'" do
|
154
|
-
expect(cmd.parse("not(not foo)")).to eq({unary_op: "not", expression: {unary_op: "not", expression: {
|
154
|
+
expect(cmd.parse("not(not foo)")).to eq({unary_op: "not", expression: {unary_op: "not", expression: {tagname: "foo"}}})
|
155
155
|
end
|
156
156
|
|
157
157
|
it "parses '!(!foo)'" do
|
158
|
-
expect(cmd.parse("!(!foo)")).to eq({unary_op: "!", expression: {unary_op: "!", expression: {
|
158
|
+
expect(cmd.parse("!(!foo)")).to eq({unary_op: "!", expression: {unary_op: "!", expression: {tagname: "foo"}}})
|
159
159
|
end
|
160
160
|
|
161
161
|
it "parses '~(~foo)'" do
|
162
|
-
expect(cmd.parse("~(~foo)")).to eq({unary_op: "~", expression: {unary_op: "~", expression: {
|
162
|
+
expect(cmd.parse("~(~foo)")).to eq({unary_op: "~", expression: {unary_op: "~", expression: {tagname: "foo"}}})
|
163
163
|
end
|
164
164
|
|
165
165
|
it "parses 'not not foo'" do
|
166
|
-
expect(cmd.parse("not not foo")).to eq({unary_op: "not", expression: {unary_op: "not", expression: {
|
166
|
+
expect(cmd.parse("not not foo")).to eq({unary_op: "not", expression: {unary_op: "not", expression: {tagname: "foo"}}})
|
167
167
|
end
|
168
168
|
|
169
169
|
it "parses '!!foo'" do
|
170
|
-
expect(cmd.parse("!! foo")).to eq({unary_op: "!", expression: {unary_op: "!", expression: {
|
170
|
+
expect(cmd.parse("!! foo")).to eq({unary_op: "!", expression: {unary_op: "!", expression: {tagname: "foo"}}})
|
171
171
|
end
|
172
172
|
|
173
173
|
it "parses '! ! foo'" do
|
174
|
-
expect(cmd.parse("!! foo")).to eq({unary_op: "!", expression: {unary_op: "!", expression: {
|
174
|
+
expect(cmd.parse("!! foo")).to eq({unary_op: "!", expression: {unary_op: "!", expression: {tagname: "foo"}}})
|
175
175
|
end
|
176
176
|
|
177
177
|
it "parses '~~foo'" do
|
178
|
-
expect(cmd.parse("~~ foo")).to eq({unary_op: "~", expression: {unary_op: "~", expression: {
|
178
|
+
expect(cmd.parse("~~ foo")).to eq({unary_op: "~", expression: {unary_op: "~", expression: {tagname: "foo"}}})
|
179
179
|
end
|
180
180
|
|
181
181
|
it "parses '~ ~ foo'" do
|
182
|
-
expect(cmd.parse("~~ foo")).to eq({unary_op: "~", expression: {unary_op: "~", expression: {
|
182
|
+
expect(cmd.parse("~~ foo")).to eq({unary_op: "~", expression: {unary_op: "~", expression: {tagname: "foo"}}})
|
183
183
|
end
|
184
184
|
|
185
185
|
it "parses 'foo and bar'" do
|
186
|
-
expect(cmd.parse("foo and bar")).to eq({left: {
|
186
|
+
expect(cmd.parse("foo and bar")).to eq({left: {tagname: "foo"}, binary_op: "and", right: {tagname: "bar"}})
|
187
187
|
end
|
188
188
|
|
189
189
|
it "parses 'foo and bar and baz'" do
|
190
|
-
expect(cmd.parse("foo and bar and baz")).to eq({left: {
|
190
|
+
expect(cmd.parse("foo and bar and baz")).to eq({left: {tagname: "foo"}, binary_op: "and", right: {left: {tagname: "bar"}, binary_op: "and", right: {tagname: "baz"}}})
|
191
191
|
end
|
192
192
|
|
193
193
|
it "parses 'foo&bar'" do
|
194
|
-
expect(cmd.parse("foo&bar")).to eq({left: {
|
194
|
+
expect(cmd.parse("foo&bar")).to eq({left: {tagname: "foo"}, binary_op: "&", right: {tagname: "bar"}})
|
195
195
|
end
|
196
196
|
|
197
197
|
it "parses 'foo & bar'" do
|
198
|
-
expect(cmd.parse("foo & bar")).to eq({left: {
|
198
|
+
expect(cmd.parse("foo & bar")).to eq({left: {tagname: "foo"}, binary_op: "&", right: {tagname: "bar"}})
|
199
199
|
end
|
200
200
|
|
201
201
|
it "parses 'foo&bar&baz'" do
|
202
|
-
expect(cmd.parse("foo & bar & baz")).to eq({left: {
|
202
|
+
expect(cmd.parse("foo & bar & baz")).to eq({left: {tagname: "foo"}, binary_op: "&", right: {left: {tagname: "bar"}, binary_op: "&", right: {tagname: "baz"}}})
|
203
203
|
end
|
204
204
|
|
205
205
|
it "parses 'foo & bar & baz'" do
|
206
|
-
expect(cmd.parse("foo & bar & baz")).to eq({left: {
|
206
|
+
expect(cmd.parse("foo & bar & baz")).to eq({left: {tagname: "foo"}, binary_op: "&", right: {left: {tagname: "bar"}, binary_op: "&", right: {tagname: "baz"}}})
|
207
207
|
end
|
208
208
|
|
209
209
|
it "parses 'foo&&bar'" do
|
210
|
-
expect(cmd.parse("foo&&bar")).to eq({left: {
|
210
|
+
expect(cmd.parse("foo&&bar")).to eq({left: {tagname: "foo"}, binary_op: "&&", right: {tagname: "bar"}})
|
211
211
|
end
|
212
212
|
|
213
213
|
it "parses 'foo && bar'" do
|
214
|
-
expect(cmd.parse("foo && bar")).to eq({left: {
|
214
|
+
expect(cmd.parse("foo && bar")).to eq({left: {tagname: "foo"}, binary_op: "&&", right: {tagname: "bar"}})
|
215
215
|
end
|
216
216
|
|
217
217
|
it "parses 'foo&&bar&&baz'" do
|
218
|
-
expect(cmd.parse("foo&&bar&&baz")).to eq({left: {
|
218
|
+
expect(cmd.parse("foo&&bar&&baz")).to eq({left: {tagname: "foo"}, binary_op: "&&", right: {left: {tagname: "bar"}, binary_op: "&&", right: {tagname: "baz"}}})
|
219
219
|
end
|
220
220
|
|
221
221
|
it "parses 'foo && bar && baz'" do
|
222
|
-
expect(cmd.parse("foo && bar && baz")).to eq({left: {
|
222
|
+
expect(cmd.parse("foo && bar && baz")).to eq({left: {tagname: "foo"}, binary_op: "&&", right: {left: {tagname: "bar"}, binary_op: "&&", right: {tagname: "baz"}}})
|
223
223
|
end
|
224
224
|
|
225
225
|
it "parses 'foo or bar'" do
|
226
|
-
expect(cmd.parse("foo or bar")).to eq({left: {
|
226
|
+
expect(cmd.parse("foo or bar")).to eq({left: {tagname: "foo"}, binary_op: "or", right: {tagname: "bar"}})
|
227
227
|
end
|
228
228
|
|
229
229
|
it "parses 'foo or bar or baz'" do
|
230
|
-
expect(cmd.parse("foo or bar or baz")).to eq({left: {
|
230
|
+
expect(cmd.parse("foo or bar or baz")).to eq({left: {tagname: "foo"}, binary_op: "or", right: {left: {tagname: "bar"}, binary_op: "or", right: {tagname: "baz"}}})
|
231
231
|
end
|
232
232
|
|
233
233
|
it "parses 'foo|bar'" do
|
234
|
-
expect(cmd.parse("foo|bar")).to eq({left: {
|
234
|
+
expect(cmd.parse("foo|bar")).to eq({left: {tagname: "foo"}, binary_op: "|", right: {tagname: "bar"}})
|
235
235
|
end
|
236
236
|
|
237
237
|
it "parses 'foo | bar'" do
|
238
|
-
expect(cmd.parse("foo | bar")).to eq({left: {
|
238
|
+
expect(cmd.parse("foo | bar")).to eq({left: {tagname: "foo"}, binary_op: "|", right: {tagname: "bar"}})
|
239
239
|
end
|
240
240
|
|
241
241
|
it "parses 'foo|bar|baz'" do
|
242
|
-
expect(cmd.parse("foo|bar|baz")).to eq({left: {
|
242
|
+
expect(cmd.parse("foo|bar|baz")).to eq({left: {tagname: "foo"}, binary_op: "|", right: {left: {tagname: "bar"}, binary_op: "|", right: {tagname: "baz"}}})
|
243
243
|
end
|
244
244
|
|
245
245
|
it "parses 'foo | bar | baz'" do
|
246
|
-
expect(cmd.parse("foo | bar | baz")).to eq({left: {
|
246
|
+
expect(cmd.parse("foo | bar | baz")).to eq({left: {tagname: "foo"}, binary_op: "|", right: {left: {tagname: "bar"}, binary_op: "|", right: {tagname: "baz"}}})
|
247
247
|
end
|
248
248
|
|
249
249
|
it "parses 'foo||bar'" do
|
250
|
-
expect(cmd.parse("foo||bar")).to eq({left: {
|
250
|
+
expect(cmd.parse("foo||bar")).to eq({left: {tagname: "foo"}, binary_op: "||", right: {tagname: "bar"}})
|
251
251
|
end
|
252
252
|
|
253
253
|
it "parses 'foo || bar'" do
|
254
|
-
expect(cmd.parse("foo || bar")).to eq({left: {
|
254
|
+
expect(cmd.parse("foo || bar")).to eq({left: {tagname: "foo"}, binary_op: "||", right: {tagname: "bar"}})
|
255
255
|
end
|
256
256
|
|
257
257
|
it "parses 'foo||bar||baz'" do
|
258
|
-
expect(cmd.parse("foo||bar||baz")).to eq({left: {
|
258
|
+
expect(cmd.parse("foo||bar||baz")).to eq({left: {tagname: "foo"}, binary_op: "||", right: {left: {tagname: "bar"}, binary_op: "||", right: {tagname: "baz"}}})
|
259
259
|
end
|
260
260
|
|
261
261
|
it "parses 'foo || bar || baz'" do
|
262
|
-
expect(cmd.parse("foo || bar || baz")).to eq({left: {
|
262
|
+
expect(cmd.parse("foo || bar || baz")).to eq({left: {tagname: "foo"}, binary_op: "||", right: {left: {tagname: "bar"}, binary_op: "||", right: {tagname: "baz"}}})
|
263
263
|
end
|
264
264
|
|
265
265
|
it "parses '(foo and bar) or baz'" do
|
266
|
-
expect(cmd.parse("(foo and bar) or baz")).to eq({left: {left: {
|
266
|
+
expect(cmd.parse("(foo and bar) or baz")).to eq({left: {left: {tagname: "foo"}, binary_op: "and", right: {tagname: "bar"}}, binary_op: "or", right: {tagname: "baz"}})
|
267
267
|
end
|
268
268
|
|
269
269
|
it "parses 'foo and (bar or baz)'" do
|
270
|
-
expect(cmd.parse("foo and (bar or baz)")).to eq({left: {
|
270
|
+
expect(cmd.parse("foo and (bar or baz)")).to eq({left: {tagname: "foo"}, binary_op: "and", right: {left: {tagname: "bar"}, binary_op: "or", right: {tagname: "baz"}}})
|
271
271
|
end
|
272
272
|
|
273
273
|
it "parses 'not foo and bar'" do
|
274
|
-
expect(cmd.parse("not foo and bar")).to eq({unary_op: "not", expression: {left: {
|
274
|
+
expect(cmd.parse("not foo and bar")).to eq({unary_op: "not", expression: {left: {tagname: "foo"}, binary_op: "and", right: {tagname: "bar"}}})
|
275
275
|
end
|
276
276
|
|
277
277
|
it "parses '! foo and bar'" do
|
278
|
-
expect(cmd.parse("! foo and bar")).to eq({left: {unary_op: "!", expression: {
|
278
|
+
expect(cmd.parse("! foo and bar")).to eq({left: {unary_op: "!", expression: {tagname: "foo"}}, binary_op: "and", right: {tagname: "bar"}})
|
279
279
|
end
|
280
280
|
|
281
281
|
it "parses 'not foo && bar'" do
|
282
|
-
expect(cmd.parse("not foo && bar")).to eq({unary_op: "not", expression: {left: {
|
282
|
+
expect(cmd.parse("not foo && bar")).to eq({unary_op: "not", expression: {left: {tagname: "foo"}, binary_op: "&&", right: {tagname: "bar"}}})
|
283
283
|
end
|
284
284
|
|
285
285
|
it "parses '! foo && bar'" do
|
286
|
-
expect(cmd.parse("! foo && bar")).to eq({left: {unary_op: "!", expression: {
|
286
|
+
expect(cmd.parse("! foo && bar")).to eq({left: {unary_op: "!", expression: {tagname: "foo"}}, binary_op: "&&", right: {tagname: "bar"}})
|
287
287
|
end
|
288
288
|
|
289
289
|
it "parses 'f(x)'" do
|
290
|
-
expect(cmd.parse("f(x)")).to eq({funcall: "f", funcall_args: {funcall_args_head: {
|
290
|
+
expect(cmd.parse("f(x)")).to eq({funcall: "f", funcall_args: {funcall_args_head: {tagname: "x"}}})
|
291
291
|
end
|
292
292
|
|
293
293
|
it "parses 'f(x, \"y\")'" do
|
294
|
-
expect(cmd.parse("f(x, \"y\")")).to eq({funcall: "f", funcall_args: {funcall_args_head: {
|
294
|
+
expect(cmd.parse("f(x, \"y\")")).to eq({funcall: "f", funcall_args: {funcall_args_head: {tagname: "x"}, funcall_args_tail: {funcall_args_head: {string: "\"y\""}}}})
|
295
295
|
end
|
296
296
|
|
297
297
|
it "parses 'f(x, \"y\", /z/)'" do
|
298
|
-
expect(cmd.parse("f(x, \"y\", /z/)")).to eq({funcall: "f", funcall_args: {funcall_args_head: {
|
298
|
+
expect(cmd.parse("f(x, \"y\", /z/)")).to eq({funcall: "f", funcall_args: {funcall_args_head: {tagname: "x"}, funcall_args_tail: {funcall_args_head: {string: "\"y\""}, funcall_args_tail: {funcall_args_head: {regexp: "/z/"}}}}})
|
299
299
|
end
|
300
300
|
|
301
301
|
it "parses 'g ( 12345 )'" do
|
@@ -315,11 +315,11 @@ describe "parser" do
|
|
315
315
|
end
|
316
316
|
|
317
317
|
it "parses 'foo and bar(y)'" do
|
318
|
-
expect(cmd.parse("foo and bar(y)")).to eq({binary_op: "and", left: {
|
318
|
+
expect(cmd.parse("foo and bar(y)")).to eq({binary_op: "and", left: {tagname: "foo"}, right: {funcall: "bar", funcall_args: {funcall_args_head: {tagname: "y"}}}})
|
319
319
|
end
|
320
320
|
|
321
321
|
it "parses 'foo(x) and bar(y)'" do
|
322
|
-
expect(cmd.parse("foo(x) and bar(y)")).to eq({binary_op: "and", left: {funcall: "foo", funcall_args: {funcall_args_head: {
|
322
|
+
expect(cmd.parse("foo(x) and bar(y)")).to eq({binary_op: "and", left: {funcall: "foo", funcall_args: {funcall_args_head: {tagname: "x"}}}, right: {funcall: "bar", funcall_args: {funcall_args_head: {tagname: "y"}}}})
|
323
323
|
end
|
324
324
|
|
325
325
|
it "is unable to parse ' '" do
|