OSDN Git Service

fix minus with parenthesis bug
authorTomohiro Nishimura <tomohiro68@gmail.com>
Wed, 17 Mar 2010 02:35:36 +0000 (11:35 +0900)
committerTomohiro Nishimura <tomohiro68@gmail.com>
Wed, 17 Mar 2010 02:35:36 +0000 (11:35 +0900)
lib/mint/builder/expression_tree.rb
spec/builder/expression_tree_spec.rb

index da5fe25..cd6fe3a 100644 (file)
@@ -63,7 +63,9 @@ module Mint
     def to_latex_local
       # FIXME: too dirty
       if right.instance_of?(LiteralNode) ||
-        right.instance_of?(RootNode)
+         right.instance_of?(RootNode)    ||
+         right.instance_of?(FactorialNode)
+
         unless right.to_s.match(/\A[-\.\d]+\z/)
           return "#{left.to_latex}#{right.to_latex}"
         end
index 5a0e053..d923552 100644 (file)
@@ -124,9 +124,21 @@ module Mint
   end
 
   describe MultipleNode do
-    subject { MultipleNode.new(1, 2) }
-    it 'operator is :*' do
-      subject.operator.should == :*
+    context 'general' do
+      subject { MultipleNode.new(1, 2) }
+      it 'operator is :*' do
+        subject.operator.should == :*
+      end
+    end
+    [
+      LiteralNode.new('x'),
+      RootNode.new('2'),
+      FactorialNode.new(LiteralNode.new('x'), LiteralNode.new('2')),
+    ].each do |right|
+      context "with #{right.to_s}" do
+        subject { MultipleNode.new(LiteralNode.new(2), right) }
+        it { subject.to_latex.should match(/\A2#{Regexp.escape(right.to_latex)}\z/) }
+      end
     end
   end