esi_attribute_language 0.0.3

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,106 @@
1
+ require 'set'
2
+ require 'spec/spec_helper'
3
+
4
+ describe "esi attribute" do
5
+
6
+ it "should recognize a simple number" do
7
+ EsiAttributeLanguage::Grammar.parse("1").execute(nil).should == 1
8
+ end
9
+
10
+ it "should recognize a simple addition" do
11
+ EsiAttributeLanguage::Grammar.parse("2+3").execute(nil).should == 5
12
+ end
13
+
14
+ it "should ignore wacky whitespace" do
15
+ EsiAttributeLanguage::Grammar.parse("2 * 3").execute(nil).should == 6
16
+ end
17
+
18
+ it "should recognize a simple multiplication" do
19
+ EsiAttributeLanguage::Grammar.parse("2*3").execute(nil).should == 6
20
+ end
21
+
22
+ it "should do a simple lookup" do
23
+ EsiAttributeLanguage::Grammar.parse("$(TEST_HASH)").execute({:TEST_HASH => 'value'}).should == 'value'
24
+ end
25
+
26
+ it "should do a hash lookup" do
27
+ EsiAttributeLanguage::Grammar.parse("$(TEST_HASH{'key'})").execute({:TEST_HASH => {'key' => 'value'}}).should == 'value'
28
+ EsiAttributeLanguage::Grammar.parse("$(TEST_HASH{key})").execute({:TEST_HASH => {'key' => 'value'}}).should == 'value'
29
+ end
30
+
31
+ it "should do a set lookup" do
32
+ EsiAttributeLanguage::Grammar.parse("$(TEST_SET{'value'})").execute({:TEST_SET => Set.new(['value'])}).should == true
33
+ end
34
+
35
+ it "should do a string literal" do
36
+ EsiAttributeLanguage::Grammar.parse("$('testing')").execute(nil).should == 'testing'
37
+ end
38
+
39
+ it "should do a string with a space in it" do
40
+ EsiAttributeLanguage::Grammar.parse("$('testing one more')").execute(nil).should == 'testing one more'
41
+ end
42
+
43
+ it "should do a string with an escaped quote in it" do
44
+ EsiAttributeLanguage::Grammar.parse("$('testing \\'one\\' more')").execute(nil).should == 'testing \'one\' more'
45
+ end
46
+
47
+ it "should do a default lookup depending on the success of the first lookup" do
48
+ EsiAttributeLanguage::Grammar.parse("$(TEST_HASH|'testing')").execute({:TEST_HASH => 'value'}).should == 'value'
49
+ EsiAttributeLanguage::Grammar.parse("$(TEST_HASH|'testing')").execute({:TEST_HASH2 => 'value'}).should == 'testing'
50
+ end
51
+
52
+ it "should support ==" do
53
+ EsiAttributeLanguage::Grammar.parse("'test' == 'test'").execute(nil).should == true
54
+ EsiAttributeLanguage::Grammar.parse("5 == 5").execute(nil).should == true
55
+ end
56
+
57
+ it "should support !=" do
58
+ EsiAttributeLanguage::Grammar.parse("'test' != 'test2'").execute(nil).should == true
59
+ EsiAttributeLanguage::Grammar.parse("'test' != 'test'").execute(nil).should == false
60
+ end
61
+
62
+ it "should support <=" do
63
+ EsiAttributeLanguage::Grammar.parse("5 <= 7").execute(nil).should == true
64
+ EsiAttributeLanguage::Grammar.parse("6 <= 5").execute(nil).should == false
65
+ EsiAttributeLanguage::Grammar.parse("6 <= 6").execute(nil).should == true
66
+ end
67
+
68
+ it "should support >=" do
69
+ EsiAttributeLanguage::Grammar.parse("50 >= 47").execute(nil).should == true
70
+ EsiAttributeLanguage::Grammar.parse("600 >= 5000").execute(nil).should == false
71
+ EsiAttributeLanguage::Grammar.parse("6000 >= 6000").execute(nil).should == true
72
+ end
73
+
74
+ it "should support <" do
75
+ EsiAttributeLanguage::Grammar.parse("5 < 7").execute(nil).should == true
76
+ EsiAttributeLanguage::Grammar.parse("6 < 5").execute(nil).should == false
77
+ EsiAttributeLanguage::Grammar.parse("6 < 6").execute(nil).should == false
78
+ end
79
+
80
+ it "should support >" do
81
+ EsiAttributeLanguage::Grammar.parse("50 > 47").execute(nil).should == true
82
+ EsiAttributeLanguage::Grammar.parse("600 > 5000").execute(nil).should == false
83
+ EsiAttributeLanguage::Grammar.parse("6000 > 6000").execute(nil).should == false
84
+ end
85
+
86
+ it "should support !" do
87
+ EsiAttributeLanguage::Grammar.parse("!(5 < 7)").execute(nil).should == false
88
+ EsiAttributeLanguage::Grammar.parse("!(6 == 5)").execute(nil).should == true
89
+ EsiAttributeLanguage::Grammar.parse("!(6 < 6)").execute(nil).should == true
90
+ end
91
+
92
+ it "should support &" do
93
+ EsiAttributeLanguage::Grammar.parse("(5 < 7) & (1 ==1)").execute(nil).should == true
94
+ EsiAttributeLanguage::Grammar.parse("(5 > 7) & (1 ==1)").execute(nil).should == false
95
+ EsiAttributeLanguage::Grammar.parse("(5 < 7) & (1 !=1)").execute(nil).should == false
96
+ EsiAttributeLanguage::Grammar.parse("(5 > 7) & (1 !=1)").execute(nil).should == false
97
+ end
98
+
99
+ it "should support |" do
100
+ EsiAttributeLanguage::Grammar.parse("(5 < 7) | (1 ==1)").execute(nil).should == true
101
+ EsiAttributeLanguage::Grammar.parse("(5 > 7) | (1 ==1)").execute(nil).should == true
102
+ EsiAttributeLanguage::Grammar.parse("(5 < 7) | (1 !=1)").execute(nil).should == true
103
+ EsiAttributeLanguage::Grammar.parse("(5 > 7) | (1 !=1)").execute(nil).should == false
104
+ end
105
+
106
+ end
@@ -0,0 +1,34 @@
1
+ require 'set'
2
+ require 'spec/spec_helper'
3
+
4
+ describe "simple esi attribute" do
5
+
6
+ it "should do nothing" do
7
+ EsiAttributeLanguage::SimpleGrammar.parse("my test string").execute(nil).should == 'my test string'
8
+ end
9
+
10
+ it "should interpolate a variable" do
11
+ EsiAttributeLanguage::SimpleGrammar.parse("$(TESTING)").execute({:TESTING => 'hey you'}).should == 'hey you'
12
+ end
13
+
14
+ it "should interpolate a variable on the left" do
15
+ EsiAttributeLanguage::SimpleGrammar.parse("$(TESTING) my test string").execute({:TESTING => 'hey you'}).should == 'hey you my test string'
16
+ end
17
+
18
+ it "should interpolate a variable on the right" do
19
+ EsiAttributeLanguage::SimpleGrammar.parse("my test string $(TESTING)").execute({:TESTING => 'hey you'}).should == 'my test string hey you'
20
+ end
21
+
22
+ it "should interpolate several variables" do
23
+ EsiAttributeLanguage::SimpleGrammar.parse("my test string $(TESTING) and one more $(TESTING2) and thats it").execute({:TESTING => 'hey you', :TESTING2 => 'why bother'}).should == 'my test string hey you and one more why bother and thats it'
24
+ end
25
+
26
+ it "should do a hash lookup (with quotes)" do
27
+ EsiAttributeLanguage::SimpleGrammar.parse("my test string $(TESTING{'testing'}) and one more").execute({:TESTING => {'testing' => 'hey'}}).should == 'my test string hey and one more'
28
+ end
29
+
30
+ it "should do a hash lookup (without quotes)" do
31
+ EsiAttributeLanguage::SimpleGrammar.parse("my test string $(TESTING{testing}) and one more").execute({:TESTING => {'testing' => 'hey'}}).should == 'my test string hey and one more'
32
+ end
33
+
34
+ end
@@ -0,0 +1,7 @@
1
+ --colour
2
+ --format
3
+ specdoc
4
+ --loadby
5
+ mtime
6
+ --reverse
7
+ --backtrace
@@ -0,0 +1,2 @@
1
+ require 'racc'
2
+ require 'lib/esi_attribute_language'
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: esi_attribute_language
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Hull
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-25 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ESI Attribute Language
17
+ email: joshbuddy@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - Rakefile
26
+ - VERSION
27
+ - lib/esi_attribute_language.rb
28
+ - lib/esi_attribute_language/grammar.rb
29
+ - lib/esi_attribute_language/grammar/grammar.rex
30
+ - lib/esi_attribute_language/grammar/grammar.rex.rb
31
+ - lib/esi_attribute_language/grammar/grammar.y
32
+ - lib/esi_attribute_language/grammar/grammar.y.rb
33
+ - lib/esi_attribute_language/grammar/lexer.rb
34
+ - lib/esi_attribute_language/grammar/parser.rb
35
+ - lib/esi_attribute_language/grammar/simple.rex
36
+ - lib/esi_attribute_language/grammar/simple.rex.rb
37
+ - lib/esi_attribute_language/grammar/simple.y
38
+ - lib/esi_attribute_language/grammar/simple.y.rb
39
+ - spec/attr_spec.rb
40
+ - spec/simple_spec.rb
41
+ - spec/spec.opts
42
+ - spec/spec_helper.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/joshbuddy/esi_attribute_language
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: ESI Attribute Language
71
+ test_files:
72
+ - spec/attr_spec.rb
73
+ - spec/simple_spec.rb
74
+ - spec/spec_helper.rb