jgrep 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,132 +1,137 @@
1
- #! /usr/bin/env ruby
2
-
3
1
  require File.dirname(__FILE__) + "/../spec_helper"
4
2
 
5
3
  module JGrep
6
- describe Parser do
7
- describe '#parse' do
8
- it "should parse statements seperated by '='" do
9
- parser = Parser.new("foo.bar=bar")
10
- parser.execution_stack.should == [{"statement" => "foo.bar=bar"}]
11
- end
12
-
13
- it "should parse statements seperated by '<'" do
14
- parser = Parser.new("foo.bar<1")
15
- parser.execution_stack.should == [{"statement" => "foo.bar<1"}]
16
- end
17
-
18
- it "should parse statements seperated by '>'" do
19
- parser = Parser.new("foo.bar>1")
20
- parser.execution_stack.should == [{"statement" => "foo.bar>1"}]
21
- end
22
-
23
- it "should parse statements seperated by '<='" do
24
- parser = Parser.new("foo.bar<=1")
25
- parser.execution_stack.should == [{"statement" => "foo.bar<=1"}]
26
- end
27
-
28
- it "should parse statements seperated by '>='" do
29
- parser = Parser.new("foo.bar>=1")
30
- parser.execution_stack.should == [{"statement" => "foo.bar>=1"}]
31
- end
32
-
33
- it "should parse statement sperated by '!='" do
34
- parser = Parser.new("foo.bar!=1")
35
- parser.execution_stack.should == [{"not" => "not"}, {"statement" =>"foo.bar=1"}]
36
- end
37
-
38
- it "should parse a + token" do
39
- parser = Parser.new("+foo")
40
- parser.execution_stack.should == [{"+" => "foo"}]
41
- end
42
-
43
- it "should parse a - token" do
44
- parser = Parser.new("-foo")
45
- parser.execution_stack.should == [{"-" => "foo"}]
46
- end
47
-
48
- it "should parse a correct 'and' token" do
49
- parser = Parser.new("foo.bar=123 and bar.foo=321")
50
- parser.execution_stack.should == [{"statement" => "foo.bar=123"}, {"and" => "and"}, {"statement" => "bar.foo=321"}]
51
- end
52
-
53
- it "should not parse an incorrect and token" do
54
- expect {
55
- parser = Parser.new("and foo.bar=1")
56
- }.to raise_error("Error at column 12. \n Expression cannot start with 'and'")
57
- end
58
-
59
- it "should parse a correct 'or' token" do
60
- parser = Parser.new("foo.bar=1 or bar.foo=1")
61
- parser.execution_stack.should == [{"statement" => "foo.bar=1"}, {"or" => "or"}, {"statement" => "bar.foo=1"}]
62
- end
63
-
64
- it "should not parse an incorrect and token" do
65
- expect {
66
- parser = Parser.new("or foo.bar=1")
67
- }.to raise_error("Error at column 11. \n Expression cannot start with 'or'")
68
- end
69
-
70
- it "should parse a correct 'not' token" do
71
- parser = Parser.new("! bar.foo=1")
72
- parser.execution_stack.should == [{"not" => "not"}, {"statement" => "bar.foo=1"}]
73
- parser = Parser.new("not bar.foo=1")
74
- parser.execution_stack.should == [{"not" => "not"}, {"statement" => "bar.foo=1"}]
75
- end
76
-
77
- it "should not parse an incorrect 'not' token" do
78
- expect {
79
- parser = Parser.new("foo.bar=1 !")
80
- }.to raise_error("Error at column 10. \nExpected 'and', 'or', ')'. Found 'not'")
81
- end
82
-
83
- it "should parse correct parentheses" do
84
- parser = Parser.new("(foo.bar=1)")
85
- parser.execution_stack.should == [{"(" => "("}, {"statement" => "foo.bar=1"}, {")" => ")"}]
86
- end
87
-
88
- it "should fail on incorrect parentheses" do
89
- expect {
90
- parser = Parser.new(")foo.bar=1(")
91
- }.to raise_error("Error. Missing parentheses '('.")
92
- end
93
-
94
- it "should fail on missing parentheses" do
95
- expect {
96
- parser = Parser.new("(foo.bar=1")
97
- }.to raise_error("Error. Missing parentheses ')'.")
98
- end
99
-
100
- it "should parse correctly formatted compound statements" do
101
- parser = Parser.new("(foo.bar=1 or foo.rab=1) and (bar.foo=1)")
102
- parser.execution_stack.should == [{"(" => "("}, {"statement"=>"foo.bar=1"}, {"or"=>"or"}, {"statement"=>"foo.rab=1"},
103
- {")"=>")"}, {"and"=>"and"}, {"("=>"("}, {"statement"=>"bar.foo=1"},
104
- {")"=>")"}]
105
- end
106
-
107
- it "should parse complex array statements" do
108
- parser = Parser.new("[foo.bar=1]")
109
- parser.execution_stack.should == [{"statement" => [["statement","foo.bar=1"]]}]
110
- end
111
-
112
- it "should not parse failed complex array statements" do
113
- expect{
114
- parser = Parser.new("[foo.bar=1 or]")
115
- }.to raise_error("Class name cannot be 'and', 'or', 'not'. Found 'or'")
116
-
117
- end
118
-
119
- it "should not allow nested complex array statements" do
120
- expect{
121
- parser = Parser.new("[foo.bar=1 and [foo.bar=1]]")
122
- }.to raise_error("Error at column 27\nError, cannot define '[' in a '[...]' block.")
123
-
124
- end
125
-
126
- it "should parse complex, compound array statements" do
127
- parser = Parser.new("[foo.bar=1 and foo.rab=2] and !(foo=1)")
128
- parser.execution_stack.should == [{"statement"=>[["statement", "foo.bar=1"], ["and", "and"], ["statement", "foo.rab=2"]]}, {"and"=>"and"}, {"not"=>"not"}, {"("=>"("}, {"statement"=>"foo=1"}, {")"=>")"}]
129
- end
130
- end
4
+ describe Parser do
5
+ describe "#parse" do
6
+ it "should parse statements seperated by '='" do
7
+ parser = Parser.new("foo.bar=bar")
8
+ expect(parser.execution_stack).to eq([{"statement" => "foo.bar=bar"}])
9
+ end
10
+
11
+ it "should parse statements seperated by '<'" do
12
+ parser = Parser.new("foo.bar<1")
13
+ expect(parser.execution_stack).to eq([{"statement" => "foo.bar<1"}])
14
+ end
15
+
16
+ it "should parse statements seperated by '>'" do
17
+ parser = Parser.new("foo.bar>1")
18
+ expect(parser.execution_stack).to eq([{"statement" => "foo.bar>1"}])
19
+ end
20
+
21
+ it "should parse statements seperated by '<='" do
22
+ parser = Parser.new("foo.bar<=1")
23
+ expect(parser.execution_stack).to eq([{"statement" => "foo.bar<=1"}])
24
+ end
25
+
26
+ it "should parse statements seperated by '>='" do
27
+ parser = Parser.new("foo.bar>=1")
28
+ expect(parser.execution_stack).to eq([{"statement" => "foo.bar>=1"}])
29
+ end
30
+
31
+ it "should parse statement sperated by '!='" do
32
+ parser = Parser.new("foo.bar!=1")
33
+ expect(parser.execution_stack).to eq([{"not" => "not"}, {"statement" => "foo.bar=1"}])
34
+ end
35
+
36
+ it "should parse a + token" do
37
+ parser = Parser.new("+foo")
38
+ expect(parser.execution_stack).to eq([{"+" => "foo"}])
39
+ end
40
+
41
+ it "should parse a - token" do
42
+ parser = Parser.new("-foo")
43
+ expect(parser.execution_stack).to eq([{"-" => "foo"}])
44
+ end
45
+
46
+ it "should parse a correct 'and' token" do
47
+ parser = Parser.new("foo.bar=123 and bar.foo=321")
48
+ expect(parser.execution_stack).to eq([{"statement" => "foo.bar=123"}, {"and" => "and"}, {"statement" => "bar.foo=321"}])
49
+ end
50
+
51
+ it "should not parse an incorrect and token" do
52
+ expect do
53
+ Parser.new("and foo.bar=1")
54
+ end.to raise_error("Error at column 12. \n Expression cannot start with 'and'")
55
+ end
56
+
57
+ it "should parse a correct 'or' token" do
58
+ parser = Parser.new("foo.bar=1 or bar.foo=1")
59
+ expect(parser.execution_stack).to eq([{"statement" => "foo.bar=1"}, {"or" => "or"}, {"statement" => "bar.foo=1"}])
60
+ end
61
+
62
+ it "should not parse an incorrect and token" do
63
+ expect do
64
+ Parser.new("or foo.bar=1")
65
+ end.to raise_error("Error at column 11. \n Expression cannot start with 'or'")
66
+ end
67
+
68
+ it "should parse a correct 'not' token" do
69
+ parser = Parser.new("! bar.foo=1")
70
+ expect(parser.execution_stack).to eq([{"not" => "not"}, {"statement" => "bar.foo=1"}])
71
+ parser = Parser.new("not bar.foo=1")
72
+ expect(parser.execution_stack).to eq([{"not" => "not"}, {"statement" => "bar.foo=1"}])
73
+ end
74
+
75
+ it "should not parse an incorrect 'not' token" do
76
+ expect do
77
+ Parser.new("foo.bar=1 !")
78
+ end.to raise_error("Error at column 10. \nExpected 'and', 'or', ')'. Found 'not'")
79
+ end
80
+
81
+ it "should parse correct parentheses" do
82
+ parser = Parser.new("(foo.bar=1)")
83
+ expect(parser.execution_stack).to eq([{"(" => "("}, {"statement" => "foo.bar=1"}, {")" => ")"}])
84
+ end
85
+
86
+ it "should fail on incorrect parentheses" do
87
+ expect do
88
+ Parser.new(")foo.bar=1(")
89
+ end.to raise_error("Error. Missing parentheses '('.")
90
+ end
91
+
92
+ it "should fail on missing parentheses" do
93
+ expect do
94
+ Parser.new("(foo.bar=1")
95
+ end.to raise_error("Error. Missing parentheses ')'.")
96
+ end
97
+
98
+ it "should parse correctly formatted compound statements" do
99
+ parser = Parser.new("(foo.bar=1 or foo.rab=1) and (bar.foo=1)")
100
+ expect(parser.execution_stack).to eq([{"(" => "("}, {"statement" => "foo.bar=1"}, {"or" => "or"}, {"statement" => "foo.rab=1"},
101
+ {")" => ")"}, {"and" => "and"}, {"(" => "("}, {"statement" => "bar.foo=1"},
102
+ {")" => ")"}])
103
+ end
104
+
105
+ it "should parse complex array statements" do
106
+ parser = Parser.new("[foo.bar=1]")
107
+ expect(parser.execution_stack).to eq([{"statement" => [["statement", "foo.bar=1"]]}])
108
+ end
109
+
110
+ it "should not parse failed complex array statements" do
111
+ expect do
112
+ Parser.new("[foo.bar=1 or]")
113
+ end.to raise_error("Class name cannot be 'and', 'or', 'not'. Found 'or'")
114
+ end
115
+
116
+ it "should not allow nested complex array statements" do
117
+ expect do
118
+ Parser.new("[foo.bar=1 and [foo.bar=1]]")
119
+ end.to raise_error("Error at column 27\nError, cannot define '[' in a '[...]' block.")
120
+ end
121
+
122
+ it "should parse complex, compound array statements" do
123
+ parser = Parser.new("[foo.bar=1 and foo.rab=2] and !(foo=1)")
124
+ expect(parser.execution_stack).to eq(
125
+ [
126
+ {"statement" => [["statement", "foo.bar=1"], %w[and and], ["statement", "foo.rab=2"]]},
127
+ {"and" => "and"},
128
+ {"not" => "not"},
129
+ {"(" => "("},
130
+ {"statement" => "foo=1"},
131
+ {")" => ")"}
132
+ ]
133
+ )
134
+ end
131
135
  end
136
+ end
132
137
  end
@@ -1,91 +1,87 @@
1
- #! /usr/bin/env ruby
2
-
3
1
  require File.dirname(__FILE__) + "/../spec_helper"
4
2
 
5
-
6
3
  module JGrep
7
- describe Scanner do
8
- describe '#get_token' do
9
- it "should identify a '(' token" do
10
- scanner = Scanner.new("(")
11
- token = scanner.get_token
12
- token.should == ["(", "("]
13
- end
14
-
15
- it "should identify a ')' token" do
16
- scanner = Scanner.new(")")
17
- token = scanner.get_token
18
- token.should == [")", ")"]
19
- end
20
-
21
- it "should identify an 'and' token" do
22
- scanner = Scanner.new("and ")
23
- token = scanner.get_token
24
- token.should == ["and", "and"]
25
- end
26
-
27
- it "should identify a '&&' token" do
28
- scanner = Scanner.new("&& ")
29
- token = scanner.get_token
30
- token.should == ["and", "and"]
31
- end
32
-
33
- it "should identify an 'or' token" do
34
- scanner = Scanner.new("or ")
35
- token = scanner.get_token
36
- token.should == ["or", "or"]
37
- end
38
-
39
- it "should identify a "||" token" do
40
- scanner = Scanner.new("|| ")
41
- token = scanner.get_token
42
- token.should == ["or", "or"]
43
-
44
- end
45
-
46
- it "should identify an 'not' token" do
47
- scanner = Scanner.new("not ")
48
- token = scanner.get_token
49
- token.should == ["not", "not"]
50
- end
51
-
52
- it "should identify an '!' token" do
53
- scanner = Scanner.new("!")
54
- token = scanner.get_token
55
- token.should == ["not", "not"]
56
- end
57
-
58
- it "should identify a statement token" do
59
- scanner = Scanner.new("foo.bar=bar")
60
- token = scanner.get_token
61
- token.should == ["statement", "foo.bar=bar"]
62
- end
63
-
64
- it "should identify a complex array statement" do
65
- scanner = Scanner.new("[foo=bar and bar=foo]")
66
- token = scanner.get_token
67
- token.should == ["statement", [["statement", "foo=bar"], ["and", "and"], ["statement", "bar=foo"]]]
68
- end
69
-
70
- it "should fail if expression terminates with 'and'" do
71
- scanner = Scanner.new("and")
72
-
73
- expect {
74
- token = scanner.get_token
75
- }.to raise_error("Class name cannot be 'and', 'or', 'not'. Found 'and'")
76
- end
77
-
78
- it "should identify a '+' token" do
79
- scanner = Scanner.new("+foo")
80
- token = scanner.get_token
81
- token.should == ["+","foo"]
82
- end
83
-
84
- it "should identify a '-' token" do
85
- scanner = Scanner.new("-foo")
86
- token = scanner.get_token
87
- token.should == ["-", "foo"]
88
- end
89
- end
4
+ describe Scanner do
5
+ describe "#get_token" do
6
+ it "should identify a '(' token" do
7
+ scanner = Scanner.new("(")
8
+ token = scanner.get_token
9
+ expect(token).to eq(["(", "("])
10
+ end
11
+
12
+ it "should identify a ')' token" do
13
+ scanner = Scanner.new(")")
14
+ token = scanner.get_token
15
+ expect(token).to eq([")", ")"])
16
+ end
17
+
18
+ it "should identify an 'and' token" do
19
+ scanner = Scanner.new("and ")
20
+ token = scanner.get_token
21
+ expect(token).to eq(%w[and and])
22
+ end
23
+
24
+ it "should identify a '&&' token" do
25
+ scanner = Scanner.new("&& ")
26
+ token = scanner.get_token
27
+ expect(token).to eq(%w[and and])
28
+ end
29
+
30
+ it "should identify an 'or' token" do
31
+ scanner = Scanner.new("or ")
32
+ token = scanner.get_token
33
+ expect(token).to eq(%w[or or])
34
+ end
35
+
36
+ it "should identify a " || " token" do
37
+ scanner = Scanner.new("|| ")
38
+ token = scanner.get_token
39
+ expect(token).to eq(%w[or or])
40
+ end
41
+
42
+ it "should identify an 'not' token" do
43
+ scanner = Scanner.new("not ")
44
+ token = scanner.get_token
45
+ expect(token).to eq(%w[not not])
46
+ end
47
+
48
+ it "should identify an '!' token" do
49
+ scanner = Scanner.new("!")
50
+ token = scanner.get_token
51
+ expect(token).to eq(%w[not not])
52
+ end
53
+
54
+ it "should identify a statement token" do
55
+ scanner = Scanner.new("foo.bar=bar")
56
+ token = scanner.get_token
57
+ expect(token).to eq(["statement", "foo.bar=bar"])
58
+ end
59
+
60
+ it "should identify a complex array statement" do
61
+ scanner = Scanner.new("[foo=bar and bar=foo]")
62
+ token = scanner.get_token
63
+ expect(token).to eq(["statement", [["statement", "foo=bar"], %w[and and], ["statement", "bar=foo"]]])
64
+ end
65
+
66
+ it "should fail if expression terminates with 'and'" do
67
+ scanner = Scanner.new("and")
68
+
69
+ expect do
70
+ scanner.get_token
71
+ end.to raise_error("Class name cannot be 'and', 'or', 'not'. Found 'and'")
72
+ end
73
+
74
+ it "should identify a '+' token" do
75
+ scanner = Scanner.new("+foo")
76
+ token = scanner.get_token
77
+ expect(token).to eq(["+", "foo"])
78
+ end
79
+
80
+ it "should identify a '-' token" do
81
+ scanner = Scanner.new("-foo")
82
+ token = scanner.get_token
83
+ expect(token).to eq(["-", "foo"])
84
+ end
90
85
  end
86
+ end
91
87
  end
metadata CHANGED
@@ -1,35 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jgrep
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - P Loubser
8
8
  - Dominic Cleal
9
+ - R.I. Pienaar
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2016-05-17 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: json
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
13
+ date: 2017-08-09 00:00:00.000000000 Z
14
+ dependencies: []
28
15
  description: Compare a list of json documents to a simple logical language and returns
29
16
  matches as output
30
17
  email:
31
18
  - ploubser@gmail.com
32
19
  - dominic@cleal.org
20
+ - rip@devco.net
33
21
  executables:
34
22
  - jgrep
35
23
  extensions: []
@@ -70,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
58
  version: '0'
71
59
  requirements: []
72
60
  rubyforge_project:
73
- rubygems_version: 2.2.1
61
+ rubygems_version: 2.5.1
74
62
  signing_key:
75
63
  specification_version: 4
76
64
  summary: Filter JSON documents with a simple logical language