spec/hash_spec.rb in nydp-0.0.11 vs spec/hash_spec.rb in nydp-0.0.12
- old
+ new
@@ -151,6 +151,76 @@
expect(vm.pop_arg).to eq pair_list [sym("k0"), sym("k1")]
end
end
end
+
+ describe "get/set nil" do
+ let(:ahash) { Nydp.NIL }
+
+ describe "hash set" do
+ it "does nothing, returns its value" do
+ k = Nydp::Symbol.mk "keysym", ns
+ v = Nydp::StringAtom.new "foobar"
+ args = pair_list [ahash, k, v]
+ Nydp::Builtin::HashSet.new.invoke vm, args
+
+ expect(ahash). to eq Nydp.NIL
+ expect(vm.pop_arg).to eq v
+ end
+ end
+
+ describe "hash get" do
+ it "converts ruby value to nydp value" do
+ k = Nydp::Symbol.mk "keysym", ns
+ args = [ ahash, k ]
+
+ Nydp::Builtin::HashGet.new(ns).invoke vm, pair_list(args)
+
+ expect(vm.pop_arg).to eq Nydp.NIL
+ end
+ end
+ end
+
+ describe "non-hash" do
+ let(:ahash) { Nydp::StringAtom.new "this here ain't no hash, hombre" }
+
+ describe "hash set" do
+ it "does nothing, returns its value" do
+ k = Nydp::Symbol.mk "keysym", ns
+ v = Nydp::StringAtom.new "foobar"
+ args = pair_list [ahash, k, v]
+
+ begin
+ Nydp::Builtin::HashSet.new.invoke vm, args
+ rescue Exception => e
+ error = e
+ end
+
+ expect(error.message.gsub(/at \/.*:in `builtin_invoke'/, '<error info>')).to eq "Called builtin/hash-set
+with args (\"this here ain't no hash, hombre\" keysym \"foobar\")
+raised
+ hash-set: Not a hash: Nydp::StringAtom
+<error info>"
+ end
+ end
+
+ describe "hash get" do
+ it "converts ruby value to nydp value" do
+ k = Nydp::Symbol.mk "keysym", ns
+ args = [ ahash, k ]
+
+ begin
+ Nydp::Builtin::HashGet.new(ns).invoke vm, pair_list(args)
+ rescue Exception => e
+ error = e
+ end
+
+ expect(error.message.gsub(/at \/.*:in `builtin_invoke'/, '<error info>')).to eq "Called builtin/hash-get
+with args (\"this here ain't no hash, hombre\" keysym)
+raised
+ hash-get: Not a hash: Nydp::StringAtom
+<error info>"
+ end
+ end
+ end
end