spec/date_spec.rb in nydp-0.5.1 vs spec/date_spec.rb in nydp-0.6.0

- old
+ new

@@ -1,36 +1,32 @@ require 'spec_helper' describe Nydp::Date do - let(:ns) { { } } - let(:vm) { Nydp::VM.new(ns) } it "converts ruby Date to Nydp::Date" do rd = Date.parse "2015-06-08" nd = Nydp.r2n rd - expect(nd). to be_a Nydp::Date + expect(nd). to be_a ::Date expect(nd.to_s). to eq "2015-06-08" - expect(nd.inspect).to eq "#<Date: 2015-06-08 ((2457182j,0s,0n),+0s,2299161j)>" + expect(nd._nydp_inspect).to eq "#<Date: 2015-06-08 ((2457182j,0s,0n),+0s,2299161j)>" expect(nd.to_ruby).to eq Date.parse("2015-06-08") end it "creates a new date" do df = Nydp::Builtin::Date.instance - df.invoke_4 vm, 2015, 11, 18 - nd = vm.args.pop - expect(nd).to be_a Nydp::Date - expect(nd.ruby_date).to eq Date.parse("2015-11-18") + nd = df.call 2015, 11, 18 + expect(nd).to be_a ::Date + expect(nd).to eq Date.parse("2015-11-18") end it "returns today" do df = Nydp::Builtin::Date.instance - df.invoke_1 vm - nd = vm.args.pop - expect(nd).to be_a Nydp::Date - expect(nd.ruby_date).to eq Date.today + nd = df.call + expect(nd).to be_a ::Date + expect(nd).to eq Date.today end it "returns date components" do rd = Date.parse "2015-06-08" nd = Nydp.r2n rd @@ -45,77 +41,75 @@ let(:d1) { Nydp.r2n (Date.today + 6) } it "works with builtin minus" do minus = Nydp::Builtin::Minus.instance - minus.invoke vm, pair_list([d1, d0]) - diff = vm.args.pop + diff = minus.call d1, d0 - expect(d0).to be_a Nydp::Date + expect(d0).to be_a ::Date expect(diff).to eq 6 end describe "'>" do it "works with builtin greater-than when true" do f = Nydp::Builtin::GreaterThan.instance - f.invoke vm, pair_list([d1, d0]) + a = f.call d1, d0 - expect(vm.args.pop).to eq d0 + expect(a).to eq d0 end it "compares with nil" do f = Nydp::Builtin::GreaterThan.instance - f.invoke vm, pair_list([d1, Nydp::NIL]) + a = f.call d1, nil - expect(vm.args.pop).to eq Nydp::NIL + expect(a).to eq Nydp::NIL end it "works with builtin greater-than when false" do f = Nydp::Builtin::GreaterThan.instance - f.invoke vm, pair_list([d0, d1]) + a = f.call d0, d1 - expect(vm.args.pop).to eq Nydp::NIL + expect(a).to eq Nydp::NIL end end describe "'<" do it "works with builtin less-than when true" do f = Nydp::Builtin::LessThan.instance - f.invoke vm, pair_list([d0, d1]) + a = f.call d0, d1 - expect(vm.args.pop).to eq d1 + expect(a).to eq d1 end it "works with builtin less-than when false" do f = Nydp::Builtin::LessThan.instance - f.invoke vm, pair_list([d1, d0]) + a = f.call d1, d0 - expect(vm.args.pop).to eq Nydp::NIL + expect(a).to eq Nydp::NIL end it "compares with nil" do f = Nydp::Builtin::LessThan.instance - f.invoke vm, pair_list([d1, Nydp::NIL]) + a = f.call d1, nil - expect(vm.args.pop).to eq Nydp::NIL + expect(a).to eq Nydp::NIL end end it "works with builtin plus" do plus = Nydp::Builtin::Plus.instance - plus.invoke vm, pair_list([d0, 5]) - sum = vm.args.pop + sum = plus.call d0, 5 - expect(d0) .to be_a Nydp::Date - expect(sum).to be_a Nydp::Date - expect(sum.ruby_date).to eq(Date.today + 5) + expect(d0) .to be_a ::Date + expect(sum).to be_a ::Date + expect(sum).to eq(Date.today + 5) end end it "returns relative dates by year" do rd = Date.parse "2015-06-08"