jgrep 1.3.3 → 1.4.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.
@@ -0,0 +1,132 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + "/../spec_helper"
4
+
5
+ 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
131
+ end
132
+ end
@@ -0,0 +1,91 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + "/../spec_helper"
4
+
5
+
6
+ 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
90
+ end
91
+ end
metadata CHANGED
@@ -1,85 +1,77 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jgrep
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 3
9
- - 3
10
- version: 1.3.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - P Loubser
8
+ - Dominic Cleal
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-09-26 00:00:00 +01:00
19
- default_executable: jgrep
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2015-11-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: json
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
27
18
  - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
33
21
  type: :runtime
34
- version_requirements: *id001
35
- description: Compare a list of json documents to a simple logical language and returns matches as output
36
- email:
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: Compare a list of json documents to a simple logical language and returns
29
+ matches as output
30
+ email:
37
31
  - ploubser@gmail.com
38
- executables:
32
+ - dominic@cleal.org
33
+ executables:
39
34
  - jgrep
40
35
  extensions: []
41
-
42
- extra_rdoc_files: []
43
-
44
- files:
45
- - jgrep.gemspec
36
+ extra_rdoc_files:
37
+ - CHANGELOG.markdown
38
+ - README.markdown
39
+ files:
40
+ - CHANGELOG.markdown
41
+ - COPYING
42
+ - README.markdown
43
+ - Rakefile
46
44
  - bin/jgrep
47
45
  - lib/jgrep.rb
48
- - lib/parser/scanner.rb
49
46
  - lib/parser/parser.rb
50
- has_rdoc: true
51
- homepage: https://github.com/psy1337/JSON-Grep
52
- licenses: []
53
-
47
+ - lib/parser/scanner.rb
48
+ - spec/Rakefile
49
+ - spec/spec_helper.rb
50
+ - spec/unit/jgrep_spec.rb
51
+ - spec/unit/parser_spec.rb
52
+ - spec/unit/scanner_spec.rb
53
+ homepage: https://github.com/ploubser/JSON-Grep
54
+ licenses:
55
+ - Apache-2.0
56
+ metadata: {}
54
57
  post_install_message:
55
58
  rdoc_options: []
56
-
57
- require_paths:
59
+ require_paths:
58
60
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
- requirements:
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
62
63
  - - ">="
63
- - !ruby/object:Gem::Version
64
- hash: 3
65
- segments:
66
- - 0
67
- version: "0"
68
- required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
- requirements:
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
71
68
  - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
77
71
  requirements: []
78
-
79
72
  rubyforge_project:
80
- rubygems_version: 1.3.7
73
+ rubygems_version: 2.2.1
81
74
  signing_key:
82
- specification_version: 3
83
- summary: Compare a list of json documents to a simple logical language and returns matches as output
75
+ specification_version: 4
76
+ summary: Filter JSON documents with a simple logical language
84
77
  test_files: []
85
-
@@ -1,17 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = "jgrep"
3
- s.version = "1.3.3"
4
-
5
- s.authors = ["P Loubser"]
6
- s.date = %q{2012-09-26}
7
- s.default_executable = "jgrep"
8
- s.add_dependency('json')
9
- s.description = "Compare a list of json documents to a simple logical language and returns matches as output"
10
- s.email = ["ploubser@gmail.com"]
11
- s.executables = ["jgrep"]
12
- s.files = ["jgrep.gemspec", "bin/jgrep", Dir.glob("lib/*"), Dir.glob("lib/parser/*")].flatten
13
- s.has_rdoc = true
14
- s.homepage = "https://github.com/psy1337/JSON-Grep"
15
- s.require_paths = ["lib"]
16
- s.summary = s.description
17
- end