Skip to content

Commit

Permalink
Fixed a bug with ternary op missing parenthesis.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Sep 28, 2012
1 parent 8dfa685 commit 0a9c8b7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions History.txt
@@ -1,3 +1,8 @@
== 0.8.8 2012-09-28

* Minor enhancements
* Fixed a bug with ternary op missing parenthesis.

== 0.8.7 2012-09-24

* Minor enhancements
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_less/info.rb
@@ -1,3 +1,3 @@
module RubyLess
VERSION = '0.8.7'
VERSION = '0.8.8'
end
2 changes: 1 addition & 1 deletion lib/ruby_less/processor.rb
Expand Up @@ -107,7 +107,7 @@ def process_if(exp)
opts = {}
opts[:nil] = true_res.nil? || true_res.could_be_nil? || false_res.nil? || false_res.could_be_nil?
opts[:class] = true_res ? true_res.klass : false_res.klass
t "#{cond} ? #{true_res || 'nil'} : #{false_res || 'nil'}", opts
t "(#{cond} ? #{true_res || 'nil'} : #{false_res || 'nil'})", opts
end

def process_call(exp)
Expand Down
4 changes: 2 additions & 2 deletions rubyless.gemspec
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = %q{rubyless}
s.version = "0.8.7"
s.version = "0.8.8"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Gaspard Bucher"]
s.date = %q{2012-09-24}
s.date = %q{2012-09-28}
s.description = %q{RubyLess is an interpreter for "safe ruby". The idea is to transform some "unsafe" ruby code into safe, type checked ruby, eventually rewriting some variables or methods.}
s.email = %q{gaspard@teti.ch}
s.extra_rdoc_files = [
Expand Down
14 changes: 9 additions & 5 deletions test/RubyLess/basic.yml
Expand Up @@ -53,27 +53,31 @@ nil_greater_then:

nil_ternary_op:
src: "spouse ? 'foo' : 'bar'"
tem: "node.spouse ? \"foo\" : \"bar\""
tem: "(node.spouse ? \"foo\" : \"bar\")"
res: 'bar'

nested_ternary_op:
src: "spouse.name == 'Adam' ? 'man' : 'not a man'"
tem: "(node.spouse ? (node.spouse.name==\"Adam\") : nil) ? \"man\" : \"not a man\""
tem: "((node.spouse ? (node.spouse.name==\"Adam\") : nil) ? \"man\" : \"not a man\")"
res: "not a man"

one_minus_ternary_op:
src: "1 - (node.id == 0 ? 5 : node.id)"
tem: "(1-((node.zip==0) ? 5 : node.zip))"

method_on_method:
src: "project.name.to_s"
tem: "node.project.name.to_s"
res: 'project'

comp_ternary_op:
src: "1 > 2 ? 'foo' : 'bar'"
tem: "(1>2) ? \"foo\" : \"bar\""
tem: "((1>2) ? \"foo\" : \"bar\")"
res: "bar"

method_ternary_op:
src: "id > 2 ? 'foo' : 'bar'"
tem: "(node.zip>2) ? \"foo\" : \"bar\""
tem: "((node.zip>2) ? \"foo\" : \"bar\")"
res: "foo"

method_argument_can_be_nil:
Expand Down Expand Up @@ -273,5 +277,5 @@ nil:

nil_in_op:
src: '(dictionary[:foo] == "something" ? "foo" : nil)'
tem: '(get_dict[:foo]=="something") ? "foo" : nil'
tem: '((get_dict[:foo]=="something") ? "foo" : nil)'
res: ''

0 comments on commit 0a9c8b7

Please sign in to comment.