spec/node_spec.rb in SgfParser-1.0.0 vs spec/node_spec.rb in SgfParser-2.0.0

- old
+ new

@@ -1,8 +1,8 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') -describe "SgfParser::Node" do +describe "SGF::Node" do before :each do @node = SGF::Node.new end @@ -38,11 +38,11 @@ child3 = SGF::Node.new @node.add_children child1, child2, child3 @node.children.each { |child| child.parent.should == @node } end - it "should allow properties to be added to" do + it "should allow concatenation of properties" do @node.add_properties "TC" => "Hello," @node.add_properties "TC" => " world!" @node.properties["TC"].should == "Hello, world!" end @@ -57,8 +57,34 @@ @node.add_properties "RE" => "This is made up" @node.properties["RE"] = "This is also made up" @node.re.should == "This is also made up" @node.re = "And that too" @node.re.should == "And that too" + end + + it "should implement [] as a shortcut to read properties" do + @node.add_properties "PB" => "Dosaku" + @node["PB"].should == "Dosaku" + @node[:PB].should == "Dosaku" + end + + it "should give you a relatively useful inspect" do + @node.inspect.should match /#{@node.object_id}/ + @node.inspect.should match /SGF::Node/ + + @node.add_properties({"C" => "Oh hi", "PB" => "Dosaku", "AE" => "[dd][gh]"}) + @node.inspect.should match /3 Properties/ + + @node.add_children SGF::Node.new, SGF::Node.new + @node.inspect.should match /2 Children/ + + @node.inspect.should match /Has no parent/ + @node.parent = SGF::Node.new + @node.inspect.should match /Has a parent/ + end + + it "should properly show a string version of the node" do + @node.add_properties({"C" => "Oh hi]", "PB" => "Dosaku"}) + @node.to_str.should == ";C[Oh hi\\]]\nPB[Dosaku]" end end \ No newline at end of file