plist 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,53 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'plist'
5
-
6
- class TestGeneratorBasicTypes < Test::Unit::TestCase
7
- def wrap(tag, content)
8
- return "<#{tag}>#{content}</#{tag}>"
9
- end
10
-
11
- def test_strings
12
- expected = wrap('string', 'testdata')
13
-
14
- assert_equal expected, Plist::Emit.dump('testdata', false).chomp
15
- assert_equal expected, Plist::Emit.dump(:testdata, false).chomp
16
- end
17
-
18
- def test_strings_with_escaping
19
- expected = wrap('string', "&lt;Fish &amp; Chips&gt;")
20
-
21
- assert_equal expected, Plist::Emit.dump('<Fish & Chips>', false).chomp
22
- end
23
-
24
- def test_integers
25
- [42, 2376239847623987623, -8192].each do |i|
26
- assert_equal wrap('integer', i), Plist::Emit.dump(i, false).chomp
27
- end
28
- end
29
-
30
- def test_floats
31
- [3.14159, -38.3897, 2398476293847.9823749872349980].each do |i|
32
- assert_equal wrap('real', i), Plist::Emit.dump(i, false).chomp
33
- end
34
- end
35
-
36
- def test_booleans
37
- assert_equal "<true/>", Plist::Emit.dump(true, false).chomp
38
- assert_equal "<false/>", Plist::Emit.dump(false, false).chomp
39
- end
40
-
41
- def test_time
42
- test_time = Time.now
43
- assert_equal wrap('date', test_time.utc.strftime('%Y-%m-%dT%H:%M:%SZ')), Plist::Emit.dump(test_time, false).chomp
44
- end
45
-
46
- def test_dates
47
- test_date = Date.today
48
- test_datetime = DateTime.now
49
-
50
- assert_equal wrap('date', test_date.strftime('%Y-%m-%dT%H:%M:%SZ')), Plist::Emit.dump(test_date, false).chomp
51
- assert_equal wrap('date', test_datetime.strftime('%Y-%m-%dT%H:%M:%SZ')), Plist::Emit.dump(test_datetime, false).chomp
52
- end
53
- end
@@ -1,77 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'plist'
5
-
6
- class TestGeneratorCollections < Test::Unit::TestCase
7
- def test_array
8
- expected = <<END
9
- <array>
10
- <integer>1</integer>
11
- <integer>2</integer>
12
- <integer>3</integer>
13
- </array>
14
- END
15
-
16
- assert_equal expected, [1,2,3].to_plist(false)
17
- end
18
-
19
- def test_empty_array
20
- expected = <<END
21
- <array/>
22
- END
23
-
24
- assert_equal expected, [].to_plist(false)
25
- end
26
-
27
- def test_hash
28
- expected = <<END
29
- <dict>
30
- <key>abc</key>
31
- <integer>123</integer>
32
- <key>foo</key>
33
- <string>bar</string>
34
- </dict>
35
- END
36
- # thanks to recent changes in the generator code, hash keys are sorted before emission,
37
- # so multi-element hash tests should be reliable. We're testing that here too.
38
- assert_equal expected, {:foo => :bar, :abc => 123}.to_plist(false)
39
- end
40
-
41
- def test_empty_hash
42
- expected = <<END
43
- <dict/>
44
- END
45
-
46
- assert_equal expected, {}.to_plist(false)
47
- end
48
-
49
- def test_hash_with_array_element
50
- expected = <<END
51
- <dict>
52
- <key>ary</key>
53
- <array>
54
- <integer>1</integer>
55
- <string>b</string>
56
- <string>3</string>
57
- </array>
58
- </dict>
59
- END
60
- assert_equal expected, {:ary => [1,:b,'3']}.to_plist(false)
61
- end
62
-
63
- def test_array_with_hash_element
64
- expected = <<END
65
- <array>
66
- <dict>
67
- <key>foo</key>
68
- <string>bar</string>
69
- </dict>
70
- <string>b</string>
71
- <integer>3</integer>
72
- </array>
73
- END
74
-
75
- assert_equal expected, [{:foo => 'bar'}, :b, 3].to_plist(false)
76
- end
77
- end
@@ -1,97 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'plist'
5
-
6
- class TestParser < Test::Unit::TestCase
7
- def test_Plist_parse_xml
8
- result = Plist::parse_xml("test/assets/AlbumData.xml")
9
-
10
- # dict
11
- assert_kind_of( Hash, result )
12
-
13
- expected = [
14
- "List of Albums",
15
- "Minor Version",
16
- "Master Image List",
17
- "Major Version",
18
- "List of Keywords",
19
- "Archive Path",
20
- "List of Rolls",
21
- "Application Version"
22
- ]
23
- assert_equal( expected.sort, result.keys.sort )
24
-
25
- # array
26
- assert_kind_of( Array, result["List of Rolls"] )
27
- assert_equal( [ {"PhotoCount"=>1,
28
- "KeyList"=>["7"],
29
- "Parent"=>999000,
30
- "Album Type"=>"Regular",
31
- "AlbumName"=>"Roll 1",
32
- "AlbumId"=>6}],
33
- result["List of Rolls"] )
34
-
35
- # string
36
- assert_kind_of( String, result["Application Version"] )
37
- assert_equal( "5.0.4 (263)", result["Application Version"] )
38
-
39
- # integer
40
- assert_kind_of( Integer, result["Major Version"] )
41
- assert_equal( 2, result["Major Version"] )
42
-
43
- # true
44
- assert_kind_of( TrueClass, result["List of Albums"][0]["Master"] )
45
- assert( result["List of Albums"][0]["Master"] )
46
-
47
- # false
48
- assert_kind_of( FalseClass, result["List of Albums"][1]["SlideShowUseTitles"] )
49
- assert( ! result["List of Albums"][1]["SlideShowUseTitles"] )
50
-
51
- end
52
-
53
- # uncomment this test to work on speed optimization
54
- #def test_load_something_big
55
- # plist = Plist::parse_xml( "~/Pictures/iPhoto Library/AlbumData.xml" )
56
- #end
57
-
58
- # date fields are credited to
59
- def test_date_fields
60
- result = Plist::parse_xml("test/assets/Cookies.plist")
61
- assert_kind_of( DateTime, result.first['Expires'] )
62
- assert_equal DateTime.parse( "2007-10-25T12:36:35Z" ), result.first['Expires']
63
- end
64
-
65
- # bug fix for empty <key>
66
- # reported by Matthias Peick <matthias@peick.de>
67
- # reported and fixed by Frederik Seiffert <ego@frederikseiffert.de>
68
- def test_empty_dict_key
69
- data = Plist::parse_xml("test/assets/test_empty_key.plist");
70
- assert_equal("2", data['key']['subkey'])
71
- end
72
-
73
- # bug fix for decoding entities
74
- # reported by Matthias Peick <matthias@peick.de>
75
- def test_decode_entities
76
- data = Plist::parse_xml('<string>Fish &amp; Chips</string>')
77
- assert_equal('Fish & Chips', data)
78
- end
79
-
80
- def test_comment_handling_and_empty_plist
81
- assert_nothing_raised do
82
- assert_nil( Plist::parse_xml( File.read('test/assets/commented.plist') ) )
83
- end
84
- end
85
-
86
- def test_filename_or_xml_is_stringio
87
- require 'stringio'
88
-
89
- str = StringIO.new
90
- data = Plist::parse_xml(str)
91
-
92
- assert_nil data
93
- end
94
-
95
- end
96
-
97
- __END__