summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPatrick May <patrick@hexane.org>2006-09-10 19:31:12 +0000
committerPatrick May <patrick@hexane.org>2006-09-10 19:31:12 +0000
commitba316d1482d036ebdca8bfac6044b58b0c149f74 (patch)
treebd4f26c54ddc5262c9dc7d7d50fe1d7a2cd5ba26 /test
parent26926e1634ccdca8ebb407a5bba1b64747b60b31 (diff)
downloadplist-ba316d1482d036ebdca8bfac6044b58b0c149f74.tar.gz
fixed bugs, changed data elements to return StringIO
Diffstat (limited to 'test')
-rw-r--r--test/assets/test_empty_key.plist13
-rw-r--r--test/test_generator_basic_types.rb34
-rw-r--r--test/test_parser.rb42
3 files changed, 62 insertions, 27 deletions
diff --git a/test/assets/test_empty_key.plist b/test/assets/test_empty_key.plist
new file mode 100644
index 0000000..5b37513
--- /dev/null
+++ b/test/assets/test_empty_key.plist
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+ <dict>
+ <key>key</key>
+ <dict>
+ <key></key>
+ <string>1</string>
+ <key>subkey</key>
+ <string>2</string>
+ </dict>
+ </dict>
+</plist> \ No newline at end of file
diff --git a/test/test_generator_basic_types.rb b/test/test_generator_basic_types.rb
index 3483373..ed59757 100644
--- a/test/test_generator_basic_types.rb
+++ b/test/test_generator_basic_types.rb
@@ -49,4 +49,38 @@ class TestBasicTypes < Test::Unit::TestCase
assert_equal wrap('date', test_date.strftime('%Y-%m-%dT%H:%M:%SZ')), [test_date].to_plist(false)
assert_equal wrap('date', test_datetime.strftime('%Y-%m-%dT%H:%M:%SZ')), [test_datetime].to_plist(false)
end
+
+ # generater tests from patrick's plist.rb code
+ def test_to_plist
+ assert_equal( Plist::_xml("<string>Hello, World</string>"), "Hello, World".to_plist )
+ assert_equal( Plist::_xml("<real>151936595.697543</real>"), 151936595.697543.to_plist )
+ assert_equal( Plist::_xml("<date>2006-04-21T16:47:58Z</date>"), DateTime.parse("2006-04-21T16:47:58Z").to_plist )
+ assert_equal( Plist::_xml("<integer>999000</integer>"), 999000.to_plist )
+ assert_equal( Plist::_xml("<false/>"), false.to_plist )
+ assert_equal( Plist::_xml("<true/>"), true.to_plist )
+
+ assert_equal( Plist::_xml("<array>\n\t<true/>\n\t<false/>\n</array>"),
+ [ true, false ].to_plist )
+
+ assert_equal( Plist::_xml("<dict>\n\t<key>False</key>\n\t<false/>\n\t<key>True</key>\n\t<true/>\n</dict>"),
+ { 'True' => true, 'False' => false }.to_plist )
+
+ source = File.open("test/assets/AlbumData.xml") { |f| f.read }
+
+ result = Plist::parse_xml(source)
+
+ assert_equal( result, Plist::parse_xml(result.to_plist) )
+
+ File.delete('hello.plist') if File.exists?('hello.plist')
+ "Hello, World".save_plist('hello.plist')
+ assert_equal( Plist::_xml("<string>Hello, World</string>"),
+ File.open('hello.plist') {|f| f.read } )
+ File.delete('hello.plist') if File.exists?('hello.plist')
+ end
+
+ def test_escape_string_values
+ assert_equal( Plist::_xml("<string>&lt;plist&gt;</string>"), "<plist>".to_plist )
+ assert_equal( Plist::_xml("<string>Fish &amp; Chips</string>"), "Fish & Chips".to_plist )
+ end
+
end
diff --git a/test/test_parser.rb b/test/test_parser.rb
index 2e94a1c..5aeda6c 100644
--- a/test/test_parser.rb
+++ b/test/test_parser.rb
@@ -54,6 +54,7 @@ class TestPlist < Test::Unit::TestCase
end
+ # uncomment this test to work on speed optimization
#def test_load_something_big
# plist = Plist::parse_xml( "~/Pictures/iPhoto Library/AlbumData.xml" )
#end
@@ -66,33 +67,6 @@ class TestPlist < Test::Unit::TestCase
assert_equal( "2007-10-25T12:36:35Z", result.first['Expires'].to_s )
end
- def test_to_plist
- assert_equal( Plist::_xml("<string>Hello, World</string>"), "Hello, World".to_plist )
- assert_equal( Plist::_xml("<real>151936595.697543</real>"), 151936595.697543.to_plist )
- assert_equal( Plist::_xml("<date>2006-04-21T16:47:58Z</date>"), DateTime.parse("2006-04-21T16:47:58Z").to_plist )
- assert_equal( Plist::_xml("<integer>999000</integer>"), 999000.to_plist )
- assert_equal( Plist::_xml("<false/>"), false.to_plist )
- assert_equal( Plist::_xml("<true/>"), true.to_plist )
-
- assert_equal( Plist::_xml("<array>\n\t<true/>\n\t<false/>\n</array>"),
- [ true, false ].to_plist )
-
- assert_equal( Plist::_xml("<dict>\n\t<key>False</key>\n\t<false/>\n\t<key>True</key>\n\t<true/>\n</dict>"),
- { 'True' => true, 'False' => false }.to_plist )
-
- source = File.open("test/assets/AlbumData.xml") { |f| f.read }
-
- result = Plist::parse_xml(source)
-
- assert_equal( result, Plist::parse_xml(result.to_plist) )
-
- File.delete('hello.plist') if File.exists?('hello.plist')
- "Hello, World".save_plist('hello.plist')
- assert_equal( Plist::_xml("<string>Hello, World</string>"),
- File.open('hello.plist') {|f| f.read } )
- File.delete('hello.plist') if File.exists?('hello.plist')
- end
-
# this functionality is credited to Mat Schaffer,
# who discovered the plist with the data tag
# supplied the test data, and provided the parsing code.
@@ -109,6 +83,20 @@ class TestPlist < Test::Unit::TestCase
end
+ # bug fix for empty <key>
+ # reported by Matthias Peick <matthias@peick.de>
+ # reported and fixed by Frederik Seiffert <ego@frederikseiffert.de>
+ def test_empty_dict_key
+ data = Plist::parse_xml("test/assets/test_empty_key.plist");
+ assert_equal("2", data['key']['subkey'])
+ end
+
+ # bug fix for decoding entities
+ # reported by Matthias Peick <matthias@peick.de>
+ def test_decode_entities
+ data = Plist::parse_xml(Plist::_xml('<string>Fish &amp; Chips</string>'))
+ assert_equal('Fish & Chips', data)
+ end
end
__END__