# _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # # for lib/facets/more/xoxo.rb # # Extracted Tue Jul 25 10:07:15 EDT 2006 # Unit Tools Reap Test Extractor # require 'facets/more/xoxo.rb' require 'test/unit' class TCXOXO < Test::Unit::TestCase def test_simple_list l = ['1', '2', '3'] html = XOXO.dump(l) assert_equal '
  1. 1
  2. 2
  3. 3
', html end def test_nested_list l = ['1', ['2', '3']] assert_equal '
  1. 1
    1. 2
    2. 3
', XOXO.dump(l) end def test_hash h = {'test' => '1', 'name' => 'Kevin'} # Changed since Ruby sorts the hash differently. assert_equal '
  1. name
    Kevin
    test
    1
', XOXO.dump(h) end def test_single_item l = 'test' assert_equal '
  1. test
', XOXO.dump(l) end def test_wrap_differs l = 'test' html = XOXO.dump(l) html_wrap = XOXO.dump(l, :html_wrap => true) assert_not_equal html, html_wrap end def test_wrap_single_item l = 'test' html = XOXO.dump(l, :html_wrap => true) assert_equal <
  1. test
EOF end def test_wrap_item_with_css l = 'test' html = XOXO.dump(l, :html_wrap => true, :css => 'reaptest.css') assert_equal <
  1. test
EOF end def test_hash_roundtrip h = {'test' => '1', 'name' => 'Kevin'} assert_equal h, XOXO.load(XOXO.dump(h)) end def test_hash_with_url_roundtrip h = {'url' => 'http://example.com', 'name' => 'Kevin'} assert_equal h, XOXO.load(XOXO.dump(h)) end def test_nested_hash_roundtrip h = {'test' => '1', 'inner' => {'name' => 'Kevin'}} assert_equal h, XOXO.load(XOXO.dump(h)) end def test_nested_hash_with_url_roundtrip h = {'url' => 'http://example.com', 'inner' => { 'url' => 'http://slashdot.org', 'name' => 'Kevin'}} assert_equal h, XOXO.load(XOXO.dump(h)) end def test_list_round_trip l = ['3', '2', '1'] assert_equal l, XOXO.load(XOXO.dump(l)) end def test_list_of_hashes_round_trip l = ['3', {'a' => '2'}, {'b' => '1', 'c' => '4'}] assert_equal l, XOXO.load(XOXO.dump(l)) end def test_list_of_lists_round_trip l = ['3', ['a', '2'], ['b', ['1', ['c', '4']]]] assert_equal l, XOXO.load(XOXO.dump(l)) end def test_hashes_of_lists_roundtrip h = { 'test' => ['1', '2'], 'name' => 'Kevin', 'nestlist' => ['a', ['b', 'c']], 'nestdict' => {'e' => '6', 'f' => '7'} } assert_equal h, XOXO.load(XOXO.dump(h)) end def test_xoxo_junk_in_containers h = XOXO.load '
    bad
  1. worse
    good
    buy
    now
' assert_equal({'good' => 'buy'}, h) end def test_xoxo_junk_in_elements l = XOXO.load '
  1. bad
    good
    buy
    worse
  2. bag
    1. OK
    fish
' assert_equal([{'good' => 'buy'}, ['OK']], l) end def test_xoxo_with_spaces_and_newlines xoxo_sample = <
  • text
    item 1
    description
    This item represents the main point we're trying to make.
    url
    http://example.com/more.xoxo
    title
    title of item 1
    type
    text/xml
    rel
    help
  • EOF h = XOXO.load xoxo_sample h2 = { 'text' => 'item 1', 'description' => " This item represents the main point we're trying to make.", 'url' => 'http://example.com/more.xoxo', 'title' => 'title of item 1', 'type' => 'text/xml', 'rel' => 'help' } assert_equal h2, XOXO.load(xoxo_sample) end def test_special_attribute_decoding xoxo_sample = <
  • text
    item 1
    url
    http://example.com/more.xoxo
    title
    title of item 1
    type
    text/xml
    rel
    help
  • EOF smart_xoxo_sample = <
  • item 1
  • EOF assert_equal XOXO.load(xoxo_sample), XOXO.load(smart_xoxo_sample) end def test_special_attribute_and_dl_decoding xoxo_sample = <
  • text
    item 1
    description
    This item represents the main point we're trying to make.
    url
    http://example.com/more.xoxo
    title
    title of item 1
    type
    text/xml
    rel
    help
  • EOF smart_xoxo_sample = <
  • item 1
    description
    This item represents the main point we're trying to make.
  • EOF assert_equal XOXO.load(xoxo_sample), XOXO.load(smart_xoxo_sample) end def test_special_attribute_encode h = { 'url' => 'http://example.com/more.xoxo', 'title' => 'sample url', 'type' => "text/xml", 'rel' => 'help', 'text' => 'an example' } assert_equal '
    1. an example
    ', XOXO.dump(h) end def test_special_attribute_roundtrip_full h = { 'url' => 'http://example.com/more.xoxo', 'title' => 'sample url', 'type' => "text/xml", 'rel' => 'help', 'text' => 'an example' } assert_equal h, XOXO.load(XOXO.dump(h)) end def test_special_attribute_roundtrip_no_text h = { 'url' => 'http://example.com/more.xoxo', 'title' => 'sample url', 'type' => "text/xml", 'rel' => 'help' } assert_equal h, XOXO.load(XOXO.dump(h)) end def test_special_attribute_roundtrip_no_text_or_title h = {'url' => 'http://example.com/more.xoxo'} assert_equal h, XOXO.load(XOXO.dump(h)) end def test_attention_roundtrip kmattn = <
  • Boing Boing Blog
    alturls
    1. xmlurl
    description
    Boing Boing Blog
  • Financial Cryptography
    alturls
    1. xmlurl
    description
    Financial Cryptography
  • HubLog
    alturls
    1. xmlurl
    2. foafurl
    description
    HubLog
  • EOF assert_equal kmattn, XOXO.dump(XOXO.load(kmattn)) assert_equal XOXO.load(kmattn), XOXO.load(XOXO.dump(XOXO.load(kmattn))) assert_equal XOXO.dump(XOXO.load(kmattn)), XOXO.dump(XOXO.load(XOXO.dump(XOXO.load(kmattn)))) end def test_unicode_roundtrip unicode = "Tantek \xc3\x87elik and a snowman \xe2\x98\x83" assert_equal unicode, XOXO.load(XOXO.dump(unicode)) end # TBD: Implement proper encodings. # # def test_utf8_roundtrip # end # def test_windows1252_roundtrip # end end