test/test_anvl.rb in anvl-0.1.1 vs test/test_anvl.rb in anvl-0.1.2

- old
+ new

@@ -1,33 +1,66 @@ require 'helper' class TestAnvl < Test::Unit::TestCase def test_parse_empty h = ANVL.parse '' - assert_equal(h.entries.length, 0) + assert_equal(0, h.entries.length) end def test_parse_comment h = ANVL.parse '#' - assert_equal(h.entries.length, 0) + assert_equal(0, h.entries.length) end def test_first_draft h = ANVL.parse 'entry: # first draft who: Gilbert, W.S. | Sullivan, Arthur what: The Yeomen of the Guard when/created: 1888' - assert_equal(h[:entry], "") - assert_equal(h[:who], 'Gilbert, W.S. | Sullivan, Arthur') - assert_equal(h[:what], "The Yeomen of the Guard") - assert_equal(h[:"when/created"], "1888") + assert_equal("", h[:entry]) + assert_equal('Gilbert, W.S. | Sullivan, Arthur', h[:who]) + assert_equal("The Yeomen of the Guard", h[:what]) + assert_equal("1888", h[:"when/created"]) end + def test_multiple_values + h = ANVL::Document.parse 'entry: +a: 1 +a: 2' + assert_equal({:a => ["1","2"], :entry => ""}, h.to_h) + end + + def test_key_access + h = ANVL::Document.new + assert_equal([], h[:a]) + h[:a] = 'a' + assert_equal({:a => 'a' }, h.to_h) + h[:a] = ['a', 'b'] + assert_equal({:a => ['a', 'b'] }, h.to_h) + h[:a] << 'c' + assert_equal({:a => ['a', 'b', 'c'] }, h.to_h) + assert_equal(['a', 'b', 'c'], h[:a]) + + h[:b] + assert_equal({:a => ['a', 'b', 'c'] }, h.to_h) + + h << { :a => 'd' } + assert_equal({:a => ['a', 'b', 'c', 'd'] }, h.to_h) + + h << { :c => 1 } + assert_equal(1, h[:c]) + + h << { :c => 2 } + assert_equal([1, 2], h[:c]) + + assert_equal("a: a\na: b\na: c\na: d\nc: 1\nc: 2", h.to_s) + end + def test_fmt_empty str = ANVL.to_anvl({}) - assert_equal(str, '') + assert_equal('', str) end def test_fmt_first_draft str = ANVL.to_anvl({:entry => [""], :who => ['Gilbert, W.S. | Sullivan, Arthur'], :what => ["The Yeomen of the Guard"], :"when/created" => [1888]}) assert_match(/entry:/, str)