kalc 0.5.7.1 → 0.5.8

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.
@@ -122,7 +122,7 @@ class Kalc::Grammar < Parslet::Parser
122
122
 
123
123
  # Should look like 'Name'
124
124
  rule(:variable) {
125
- identifier | (str("'") >> identifier >> str("'")) >> spaces?
125
+ identifier | (str("'") >> spaces? >> identifier.repeat >> str("'")) >> spaces?
126
126
  }
127
127
 
128
128
  # Does not self-evaluate
@@ -1,3 +1,3 @@
1
1
  module Kalc
2
- VERSION = "0.5.7.1"
2
+ VERSION = "0.5.8"
3
3
  end
@@ -25,6 +25,22 @@ describe Kalc::Interpreter do
25
25
 
26
26
  it { evaluate("10 >= 10").should == true }
27
27
 
28
+ it "should be able to load variables" do
29
+ evaluate("a = 1; 1 + a").should == 2
30
+ evaluate("a = 1; b = 2; 1 + b").should == 3
31
+ end
32
+
33
+ it "should be able to load single quoted variables" do
34
+ evaluate("'a' = 1; 1 + 'a'").should == 2
35
+ evaluate("'a' = 1; 'b' = 2; 'b' + 'a'").should == 3
36
+
37
+ evaluate("'a b' = 1; 'a b' + 1").should == 2
38
+ end
39
+
40
+ it { evaluate("((75.0)*(25.0))+((125.0)*(25.0))+((150.0)*(25.0))+((250.0)*(25.0))").should == 15000 }
41
+
42
+ it { evaluate("(((40.0)/1000*(4380.0)*(200.0))-((40.0)/1000*(4380.0)*((((75.0)*(25.0))+((125.0)*(25.0))+((150.0)*(25.0))+((250.0)*(25.0)))/(10.0)/(40.0)/(0.8))))*(0.05)").should == 1341.375 }
43
+
28
44
  private
29
45
  def evaluate(expression)
30
46
  g = @grammar.parse(expression)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kalc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7.1
4
+ version: 0.5.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-14 00:00:00.000000000 Z
12
+ date: 2012-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake