Skip to content

Commit

Permalink
Merge pull request #10 from mrcsparker/blank_strings
Browse files Browse the repository at this point in the history
Test fix for issue #9
  • Loading branch information
mrcsparker authored Jul 8, 2016
2 parents 6dcbb13 + 52e5468 commit 4513f09
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
28 changes: 14 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
kalc (1.1.2)
kalc (1.2.0)
parslet (~> 1.7)

GEM
Expand All @@ -11,20 +11,20 @@ GEM
diff-lcs (1.2.5)
parslet (1.7.1)
blankslate (>= 2.0, <= 4.0)
rake (10.4.2)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
rake (11.2.2)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.0)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.2)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)

PLATFORMS
java
Expand All @@ -36,4 +36,4 @@ DEPENDENCIES
rspec

BUNDLED WITH
1.10.6
1.12.5
5 changes: 5 additions & 0 deletions lib/kalc/transform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class Transform < Parslet::Transform
Ast::StringValue.new(string)
}

rule(:string => sequence(:string)) {
string = '' if string == nil
Ast::StringValue.new(string)
}

rule(:boolean => simple(:boolean)) {
Ast::BooleanValue.new(boolean)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/kalc/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Kalc
VERSION = '1.1.2'
VERSION = '1.2.0'
end
8 changes: 8 additions & 0 deletions spec/interpreter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@
it { expect(evaluate('ROUND(233.256,-2)')).to eq(200) }
end

# https://github.com/mrcsparker/kalc/issues/9
# https://github.com/kschiess/parslet/issues/126
context 'empty strings' do
it { expect(evaluate('""')).to eq('') }
it { expect(evaluate('var1 := 1; var2 := 2; IF(var1=var2,"","ERROR")')).to eq('ERROR') }
it { expect(evaluate('var1 := 1; var2 := 1; IF(var1=var2,"","ERROR")')).to eq('') }
end

private
def evaluate(expression)
g = @grammar.parse(expression)
Expand Down

0 comments on commit 4513f09

Please sign in to comment.