spec/edn/transform_spec.rb in edn-0.9.4 vs spec/edn/transform_spec.rb in edn-1.0.0

- old
+ new

@@ -113,25 +113,25 @@ :value=>{:integer=>"4", :precision => nil}}]} subject.apply(map_tree).should == {:a => 1, :b => 2, {:c => 3} => 4} end end - context "tagged value" do + context "tagged element" do it "should emit a EDN::Type::Unknown if the tag is not registered" do - subject.apply({:tag => {:symbol => 'uri'}, :value => {:string => 'http://google.com'}}).should == EDN::Type::Unknown.new("uri", "http://google.com") + subject.apply({:tag => {:symbol => 'uri'}, :element => {:string => 'http://google.com'}}).should == EDN::Type::Unknown.new("uri", "http://google.com") end - it "should emit the transformed value if the tag is registered" do + it "should emit the transformed element if the tag is registered" do EDN.register("uri", lambda { |uri| URI(uri) }) - subject.apply({:tag => {:symbol => 'uri'}, :value => {:string => 'http://google.com'}}).should == URI("http://google.com") + subject.apply({:tag => {:symbol => 'uri'}, :element => {:string => 'http://google.com'}}).should == URI("http://google.com") EDN.unregister("uri") # cleanup end - it "should work with nested values" do + it "should work with nested elements" do tree = { :tag=>{:symbol=>"cnd/awesome"}, - :value=> + :element=> {:vector=> [{:keyword=>{:symbol=>"a"}}, {:list=> [{:integer=>"1", :precision=>nil}, {:list=> @@ -149,8 +149,24 @@ {:integer=>"42", :precision=>nil}]}]}]}} expected = EDN::Type::Unknown.new('cnd/awesome', [:a, [1, [2, 3]], :b, :c, Set.new([1, 2, 3]), [[[42], 42]]]) subject.apply(tree).should == expected + end + end + + context "element with metadata" do + it "should tag the element with metadata" do + tree = { + :metadata => + [:map => + [ + {:key=>{:keyword=>{:symbol=>"a"}}, :value=>{:integer=>"1", :precision => nil}}, + {:key=>{:keyword=>{:symbol=>"b"}}, :value=>{:integer=>"2", :precision => nil}}]], + :element => {:vector => [{:integer => "1", :precision => nil}, {:string => "abc"}]}} + + element = subject.apply(tree) + element.should == [1, "abc"] + element.metadata.should == {:a => 1, :b => 2} end end end