trxl 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe "The formula grammar with a prefilled environment" do
4
+
5
+ include Trxl::SpecHelper
6
+
7
+ before :each do
8
+ @parser = Trxl::Calculator.new
9
+ end
10
+
11
+ it "should raise an error if an undefined variable is referenced" do
12
+ lambda { eval("a") }.should raise_error(Trxl::MissingVariableException)
13
+ end
14
+
15
+ it "should resolve one letter variables" do
16
+ eval("a / b", { :a => 4, :b => 2 }).should == 4 / 2
17
+ end
18
+
19
+ it "should resolve multi letter variables" do
20
+ eval("foo / bar", { :foo => 4, :bar => 2 }).should == 4 / 2
21
+ end
22
+
23
+ it "should only resolve variables starting with a letter" do
24
+ lambda { parse("foo / 1bar") }.should raise_error(Trxl::FatalParseError)
25
+ lambda {
26
+ eval("foo / 1bar", { :foo => 4, "1bar".to_sym => 2 })
27
+ }.should raise_error(Trxl::FatalParseError)
28
+ end
29
+
30
+ it "should resolve variables starting with a letter and ending with a number" do
31
+ env = { :foo => 4, "bar1".to_sym => 2 }
32
+ eval("foo / bar1", env).should == 4 / 2
33
+ end
34
+
35
+ it "should resolve variables starting with a letter followed by an arbitrary number of letters or digits" do
36
+ env = { :foo => 4, "bar123asd234".to_sym => 2 }
37
+ eval("foo / bar123asd234", env).should == 4 / 2
38
+ end
39
+
40
+ it "should bind variable declarations in the current environment" do
41
+ eval("a = 1; a;").should == 1
42
+ eval("bar1 = 1; bar1;").should == 1
43
+ end
44
+
45
+ end
@@ -0,0 +1,90 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{trxl}
8
+ s.version = "0.1.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Martin Gamsjaeger (snusnu)", "Michael Aufreiter"]
12
+ s.date = %q{2010-01-13}
13
+ s.description = %q{A specced little language written with ruby and treetop. It has lambdas, recursion, conditionals, arrays, hashes, ranges, strings, arithmetics and some other stuff. It even has a small code import facility.}
14
+ s.email = %q{gamsnjaga [at] gmail [dot] com}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "lib/trxl.rb",
24
+ "lib/trxl/trxl.rb",
25
+ "lib/trxl/trxl_grammar.rb",
26
+ "lib/trxl/trxl_grammar.treetop",
27
+ "spec/spec.opts",
28
+ "spec/spec_helper.rb",
29
+ "spec/trxl/arithmetics_spec.rb",
30
+ "spec/trxl/arrays_spec.rb",
31
+ "spec/trxl/booleans_spec.rb",
32
+ "spec/trxl/builtins_spec.rb",
33
+ "spec/trxl/closures_spec.rb",
34
+ "spec/trxl/comments_spec.rb",
35
+ "spec/trxl/common_spec.rb",
36
+ "spec/trxl/conditionals_spec.rb",
37
+ "spec/trxl/constants_spec.rb",
38
+ "spec/trxl/environment_spec.rb",
39
+ "spec/trxl/hashes_spec.rb",
40
+ "spec/trxl/numbers_spec.rb",
41
+ "spec/trxl/ranges_spec.rb",
42
+ "spec/trxl/require_spec.rb",
43
+ "spec/trxl/stdlib_spec.rb",
44
+ "spec/trxl/strings_spec.rb",
45
+ "spec/trxl/variables_spec.rb",
46
+ "trxl.gemspec"
47
+ ]
48
+ s.homepage = %q{http://github.com/snusnu/trxl}
49
+ s.rdoc_options = ["--charset=UTF-8"]
50
+ s.require_paths = ["lib"]
51
+ s.rubygems_version = %q{1.3.5}
52
+ s.summary = %q{A specced little language written with ruby and treetop.}
53
+ s.test_files = [
54
+ "spec/spec_helper.rb",
55
+ "spec/trxl/arithmetics_spec.rb",
56
+ "spec/trxl/arrays_spec.rb",
57
+ "spec/trxl/booleans_spec.rb",
58
+ "spec/trxl/builtins_spec.rb",
59
+ "spec/trxl/closures_spec.rb",
60
+ "spec/trxl/comments_spec.rb",
61
+ "spec/trxl/common_spec.rb",
62
+ "spec/trxl/conditionals_spec.rb",
63
+ "spec/trxl/constants_spec.rb",
64
+ "spec/trxl/environment_spec.rb",
65
+ "spec/trxl/hashes_spec.rb",
66
+ "spec/trxl/numbers_spec.rb",
67
+ "spec/trxl/ranges_spec.rb",
68
+ "spec/trxl/require_spec.rb",
69
+ "spec/trxl/stdlib_spec.rb",
70
+ "spec/trxl/strings_spec.rb",
71
+ "spec/trxl/variables_spec.rb"
72
+ ]
73
+
74
+ if s.respond_to? :specification_version then
75
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
76
+ s.specification_version = 3
77
+
78
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
79
+ s.add_runtime_dependency(%q<treetop>, [">= 1.4"])
80
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
81
+ else
82
+ s.add_dependency(%q<treetop>, [">= 1.4"])
83
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
84
+ end
85
+ else
86
+ s.add_dependency(%q<treetop>, [">= 1.4"])
87
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
88
+ end
89
+ end
90
+
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trxl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Martin Gamsjaeger (snusnu)
8
+ - Michael Aufreiter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-01-13 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: treetop
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "1.4"
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ type: :development
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.2.9
35
+ version:
36
+ description: A specced little language written with ruby and treetop. It has lambdas, recursion, conditionals, arrays, hashes, ranges, strings, arithmetics and some other stuff. It even has a small code import facility.
37
+ email: gamsnjaga [at] gmail [dot] com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README
44
+ files:
45
+ - .gitignore
46
+ - README
47
+ - Rakefile
48
+ - VERSION
49
+ - lib/trxl.rb
50
+ - lib/trxl/trxl.rb
51
+ - lib/trxl/trxl_grammar.rb
52
+ - lib/trxl/trxl_grammar.treetop
53
+ - spec/spec.opts
54
+ - spec/spec_helper.rb
55
+ - spec/trxl/arithmetics_spec.rb
56
+ - spec/trxl/arrays_spec.rb
57
+ - spec/trxl/booleans_spec.rb
58
+ - spec/trxl/builtins_spec.rb
59
+ - spec/trxl/closures_spec.rb
60
+ - spec/trxl/comments_spec.rb
61
+ - spec/trxl/common_spec.rb
62
+ - spec/trxl/conditionals_spec.rb
63
+ - spec/trxl/constants_spec.rb
64
+ - spec/trxl/environment_spec.rb
65
+ - spec/trxl/hashes_spec.rb
66
+ - spec/trxl/numbers_spec.rb
67
+ - spec/trxl/ranges_spec.rb
68
+ - spec/trxl/require_spec.rb
69
+ - spec/trxl/stdlib_spec.rb
70
+ - spec/trxl/strings_spec.rb
71
+ - spec/trxl/variables_spec.rb
72
+ - trxl.gemspec
73
+ has_rdoc: true
74
+ homepage: http://github.com/snusnu/trxl
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.5
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: A specced little language written with ruby and treetop.
101
+ test_files:
102
+ - spec/spec_helper.rb
103
+ - spec/trxl/arithmetics_spec.rb
104
+ - spec/trxl/arrays_spec.rb
105
+ - spec/trxl/booleans_spec.rb
106
+ - spec/trxl/builtins_spec.rb
107
+ - spec/trxl/closures_spec.rb
108
+ - spec/trxl/comments_spec.rb
109
+ - spec/trxl/common_spec.rb
110
+ - spec/trxl/conditionals_spec.rb
111
+ - spec/trxl/constants_spec.rb
112
+ - spec/trxl/environment_spec.rb
113
+ - spec/trxl/hashes_spec.rb
114
+ - spec/trxl/numbers_spec.rb
115
+ - spec/trxl/ranges_spec.rb
116
+ - spec/trxl/require_spec.rb
117
+ - spec/trxl/stdlib_spec.rb
118
+ - spec/trxl/strings_spec.rb
119
+ - spec/trxl/variables_spec.rb