test/vcard_test.rb in vcard-0.2.1 vs test/vcard_test.rb in vcard-0.2.2

- old
+ new

@@ -22,11 +22,11 @@ # RFC2425 - 8.2. Example 2 def test_ex2 card = nil assert_nothing_thrown { card = Vcard::Vcard.decode(vcard(:ex2)).first } assert_equal(vcard(:ex2), card.encode(0)) - assert_raises(InvalidEncodingError) { card.version } + assert_raises(::Vcard::InvalidEncodingError) { card.version } assert_equal("Bj=F8rn Jensen", card.name.fullname) assert_equal("Jensen", card.name.family) assert_equal("Bj=F8rn", card.name.given) assert_equal("", card.name.prefix) @@ -167,54 +167,59 @@ assert_equal('fax', card[ "fax", 'bar' ]) end def test_bad # FIXME: this should THROW, it's badly encoded! - assert_raises(InvalidEncodingError) do + assert_raises(::Vcard::InvalidEncodingError) do Vcard::Vcard.decode("BEGIN:VCARD\nVERSION:3.0\nKEYencoding=b:this could be \nmy certificate\n\nEND:VCARD\n") end end def test_create card = Vcard::Vcard.create - key = Vcard::DirectoryInfo.decode("key;type=x509;encoding=B:dGhpcyBjb3VsZCBiZSAKbXkgY2VydGlmaWNhdGUK\n")['key'] - card << Vcard::DirectoryInfo::Field.create('key', key, 'encoding' => :b64) - assert_equal(key, card['key']) end - def test_values - # date - assert_equal [2002, 4, 22], Vcard.decode_date(" 20020422 ") - assert_equal [2002, 4, 22], Vcard.decode_date(" 2002-04-22 ") - assert_equal [2002, 4, 22], Vcard.decode_date(" 2002-04-22 \n") + def test_decode_date + assert_equal [2002, 4, 22], Vcard.decode_date(" 20020422 ") + assert_equal [2002, 4, 22], Vcard.decode_date(" 2002-04-22 ") + assert_equal [2002, 4, 22], Vcard.decode_date(" 2002-04-22 \n") + end + + def test_decode_date_list assert_equal [[2002, 4, 22]], Vcard.decode_date_list(" 2002-04-22 ") assert_equal [[2002, 4, 22],[2002, 4, 22]], Vcard.decode_date_list(" 2002-04-22, 2002-04-22,") assert_equal [[2002, 4, 22],[2002, 4, 22]], Vcard.decode_date_list(" 2002-04-22,,, , ,2002-04-22, , \n") assert_equal [], Vcard.decode_date_list(" , , ") + end - # time + def test_decode_time assert_equal [4, 53, 22, 0, nil], Vcard.decode_time(" 04:53:22 \n") assert_equal [4, 53, 22, 0.10, nil], Vcard.decode_time(" 04:53:22.10 \n") assert_equal [4, 53, 22, 0.10, "Z"], Vcard.decode_time(" 04:53:22.10Z \n") assert_equal [4, 53, 22, 0, "Z"], Vcard.decode_time(" 045322Z \n") assert_equal [4, 53, 22, 0, "+0530"], Vcard.decode_time(" 04:5322+0530 \n") assert_equal [4, 53, 22, 0.10, "Z"], Vcard.decode_time(" 045322.10Z \n") + end - # date-time + def test_decode_date_time assert_equal [2002, 4, 22, 4, 53, 22, 0, nil], Vcard.decode_date_time("20020422T04:53:22 \n") assert_equal [2002, 4, 22, 4, 53, 22, 0.10, nil], Vcard.decode_date_time(" 2002-04-22T04:53:22.10 \n") assert_equal [2002, 4, 22, 4, 53, 22, 0.10, "Z"], Vcard.decode_date_time(" 20020422T04:53:22.10Z \n") assert_equal [2002, 4, 22, 4, 53, 22, 0, "Z"], Vcard.decode_date_time(" 20020422T045322Z \n") assert_equal [2002, 4, 22, 4, 53, 22, 0, "+0530"], Vcard.decode_date_time(" 20020422T04:5322+0530 \n") assert_equal [2002, 4, 22, 4, 53, 22, 0.10, "Z"], Vcard.decode_date_time(" 20020422T045322.10Z \n") assert_equal [2003, 3, 25, 3, 20, 35, 0, "Z"], Vcard.decode_date_time("20030325T032035Z") + end - # text + def test_decode_text assert_equal "aa,\n\n,\\,\\a;;b", Vcard.decode_text('aa,\\n\\n,\\\\\,\\\\a\;\;b') + end + + def test_decode_text_list assert_equal ['', "1\n2,3", "bbb", '', "zz", ''], Vcard.decode_text_list(',1\\n2\\,3,bbb,,zz,') end def test_create_1 card = Vcard::Vcard.create @@ -299,14 +304,14 @@ end def test_modify_name card = Vcard.decode("begin:vcard\nend:vcard\n").first - assert_raises(InvalidEncodingError) do + assert_raises(::Vcard::InvalidEncodingError) do card.name end - assert_raises(Unencodeable) do + assert_raises(::Vcard::Unencodeable) do Vcard::Maker.make2(card) {} end card.make do |m| m.name {}