OSDN Git Service

fix minus bug in expression_tree
authorTomohiro Nishimura <tomohiro68@gmail.com>
Wed, 17 Mar 2010 05:20:16 +0000 (14:20 +0900)
committerTomohiro Nishimura <tomohiro68@gmail.com>
Wed, 17 Mar 2010 05:20:16 +0000 (14:20 +0900)
lib/mint/builder/expression_tree.rb
spec/builder/expression_tree_spec.rb

index cd6fe3a..fd8681e 100644 (file)
@@ -121,7 +121,7 @@ module Mint
       @value.to_s
     end
     def show(string)
-      return "-#{string}"   if minus
+      return "(-#{string})"   if minus
       return "(#{string})"  if parenthesis
       return "(-#{string})" if minus && parenthesis
       string
index d923552..fa94362 100644 (file)
@@ -157,13 +157,23 @@ module Mint
   end
 
   describe LiteralNode do
-    subject { LiteralNode.new(@number) }
-    before(:all) { @number = 5 }
-    it 'has own number' do
-      subject.value.should == @number
-    end
-    it 'shows itself as string' do
-      subject.to_s.should == "#{@number}"
+    [true, false].each do |minus|
+      [
+        'x', 'y', 'z',
+        1, 2, 3, 5, 8, 1000
+      ].each do |num|
+        context "#{num}(#{minus})" do
+          def show(num, minus)
+            return "(-#{num})" if minus
+            num.to_s
+          end
+          subject { LiteralNode.new(num) }
+          before { subject.minus = minus }
+          it { subject.value.should == num }
+          it { subject.to_s.should == show(num, minus) }
+          it { subject.to_latex.should == show(num, minus) }
+        end
+      end
     end
   end