sj-plist 3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ ##############################################################
2
+ # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
+ # Patrick May <patrick@hexane.org> #
4
+ # #
5
+ # Distributed under the MIT license. #
6
+ ##############################################################
7
+
8
+ require 'test/unit'
9
+ require 'plist'
10
+
11
+ class TestGeneratorBasicTypes < Test::Unit::TestCase
12
+ def wrap(tag, content)
13
+ return "<#{tag}>#{content}</#{tag}>"
14
+ end
15
+
16
+ def test_strings
17
+ expected = wrap('string', 'testdata')
18
+
19
+ assert_equal expected, Plist::Emit.dump('testdata', false).chomp
20
+ assert_equal expected, Plist::Emit.dump(:testdata, false).chomp
21
+ end
22
+
23
+ def test_strings_with_escaping
24
+ expected = wrap('string', "&lt;Fish &amp; Chips&gt;")
25
+
26
+ assert_equal expected, Plist::Emit.dump('<Fish & Chips>', false).chomp
27
+ end
28
+
29
+ def test_integers
30
+ [42, 2376239847623987623, -8192].each do |i|
31
+ assert_equal wrap('integer', i), Plist::Emit.dump(i, false).chomp
32
+ end
33
+ end
34
+
35
+ def test_floats
36
+ [3.14159, -38.3897, 2398476293847.9823749872349980].each do |i|
37
+ assert_equal wrap('real', i), Plist::Emit.dump(i, false).chomp
38
+ end
39
+ end
40
+
41
+ def test_booleans
42
+ assert_equal "<true/>", Plist::Emit.dump(true, false).chomp
43
+ assert_equal "<false/>", Plist::Emit.dump(false, false).chomp
44
+ end
45
+
46
+ def test_time
47
+ test_time = Time.now
48
+ assert_equal wrap('date', test_time.utc.strftime('%Y-%m-%dT%H:%M:%SZ')), Plist::Emit.dump(test_time, false).chomp
49
+ end
50
+
51
+ def test_dates
52
+ test_date = Date.today
53
+ test_datetime = DateTime.now
54
+
55
+ assert_equal wrap('date', test_date.strftime('%Y-%m-%dT%H:%M:%SZ')), Plist::Emit.dump(test_date, false).chomp
56
+ assert_equal wrap('date', test_datetime.strftime('%Y-%m-%dT%H:%M:%SZ')), Plist::Emit.dump(test_datetime, false).chomp
57
+ end
58
+ end
@@ -0,0 +1,82 @@
1
+ ##############################################################
2
+ # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
+ # Patrick May <patrick@hexane.org> #
4
+ # #
5
+ # Distributed under the MIT license. #
6
+ ##############################################################
7
+
8
+ require 'test/unit'
9
+ require 'plist'
10
+
11
+ class TestGeneratorCollections < Test::Unit::TestCase
12
+ def test_array
13
+ expected = <<END
14
+ <array>
15
+ <integer>1</integer>
16
+ <integer>2</integer>
17
+ <integer>3</integer>
18
+ </array>
19
+ END
20
+
21
+ assert_equal expected, [1,2,3].to_plist(false)
22
+ end
23
+
24
+ def test_empty_array
25
+ expected = <<END
26
+ <array/>
27
+ END
28
+
29
+ assert_equal expected, [].to_plist(false)
30
+ end
31
+
32
+ def test_hash
33
+ expected = <<END
34
+ <dict>
35
+ <key>abc</key>
36
+ <integer>123</integer>
37
+ <key>foo</key>
38
+ <string>bar</string>
39
+ </dict>
40
+ END
41
+ # thanks to recent changes in the generator code, hash keys are sorted before emission,
42
+ # so multi-element hash tests should be reliable. We're testing that here too.
43
+ assert_equal expected, {:foo => :bar, :abc => 123}.to_plist(false)
44
+ end
45
+
46
+ def test_empty_hash
47
+ expected = <<END
48
+ <dict/>
49
+ END
50
+
51
+ assert_equal expected, {}.to_plist(false)
52
+ end
53
+
54
+ def test_hash_with_array_element
55
+ expected = <<END
56
+ <dict>
57
+ <key>ary</key>
58
+ <array>
59
+ <integer>1</integer>
60
+ <string>b</string>
61
+ <string>3</string>
62
+ </array>
63
+ </dict>
64
+ END
65
+ assert_equal expected, {:ary => [1,:b,'3']}.to_plist(false)
66
+ end
67
+
68
+ def test_array_with_hash_element
69
+ expected = <<END
70
+ <array>
71
+ <dict>
72
+ <key>foo</key>
73
+ <string>bar</string>
74
+ </dict>
75
+ <string>b</string>
76
+ <integer>3</integer>
77
+ </array>
78
+ END
79
+
80
+ assert_equal expected, [{:foo => 'bar'}, :b, 3].to_plist(false)
81
+ end
82
+ end
@@ -0,0 +1,100 @@
1
+ ##############################################################
2
+ # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
+ # Patrick May <patrick@hexane.org> #
4
+ # #
5
+ # Distributed under the MIT license. #
6
+ ##############################################################
7
+
8
+ require 'test/unit'
9
+
10
+ require 'plist'
11
+
12
+ class TestParser < Test::Unit::TestCase
13
+ def test_Plist_parse_xml
14
+ result = Plist::parse_xml("test/assets/AlbumData.xml")
15
+
16
+ # dict
17
+ assert_kind_of( Hash, result )
18
+ assert_equal( ["List of Albums",
19
+ "Minor Version",
20
+ "Master Image List",
21
+ "Major Version",
22
+ "List of Keywords",
23
+ "Archive Path",
24
+ "List of Rolls",
25
+ "Application Version"].sort,
26
+ result.keys.sort )
27
+
28
+ # array
29
+ assert_kind_of( Array, result["List of Rolls"] )
30
+ assert_equal( [ {"PhotoCount"=>1,
31
+ "KeyList"=>["7"],
32
+ "Parent"=>999000,
33
+ "Album Type"=>"Regular",
34
+ "AlbumName"=>"Roll 1",
35
+ "AlbumId"=>6}],
36
+ result["List of Rolls"] )
37
+
38
+ # string
39
+ assert_kind_of( String, result["Application Version"] )
40
+ assert_equal( "5.0.4 (263)", result["Application Version"] )
41
+
42
+ # integer
43
+ assert_kind_of( Integer, result["Major Version"] )
44
+ assert_equal( 2, result["Major Version"] )
45
+
46
+ # true
47
+ assert_kind_of( TrueClass, result["List of Albums"][0]["Master"] )
48
+ assert( result["List of Albums"][0]["Master"] )
49
+
50
+ # false
51
+ assert_kind_of( FalseClass, result["List of Albums"][1]["SlideShowUseTitles"] )
52
+ assert( ! result["List of Albums"][1]["SlideShowUseTitles"] )
53
+
54
+ end
55
+
56
+ # uncomment this test to work on speed optimization
57
+ #def test_load_something_big
58
+ # plist = Plist::parse_xml( "~/Pictures/iPhoto Library/AlbumData.xml" )
59
+ #end
60
+
61
+ # date fields are credited to
62
+ def test_date_fields
63
+ result = Plist::parse_xml("test/assets/Cookies.plist")
64
+ assert_kind_of( DateTime, result.first['Expires'] )
65
+ assert_match( /\A2007-10-25T12:36:35(Z|\+00:00)\Z/, result.first['Expires'].to_s )
66
+ end
67
+
68
+ # bug fix for empty <key>
69
+ # reported by Matthias Peick <matthias@peick.de>
70
+ # reported and fixed by Frederik Seiffert <ego@frederikseiffert.de>
71
+ def test_empty_dict_key
72
+ data = Plist::parse_xml("test/assets/test_empty_key.plist");
73
+ assert_equal("2", data['key']['subkey'])
74
+ end
75
+
76
+ # bug fix for decoding entities
77
+ # reported by Matthias Peick <matthias@peick.de>
78
+ def test_decode_entities
79
+ data = Plist::parse_xml('<string>Fish &amp; Chips</string>')
80
+ assert_equal('Fish & Chips', data)
81
+ end
82
+
83
+ def test_comment_handling_and_empty_plist
84
+ assert_nothing_raised do
85
+ assert_nil( Plist::parse_xml( File.read('test/assets/commented.plist') ) )
86
+ end
87
+ end
88
+
89
+ def test_filename_or_xml_is_stringio
90
+ require 'stringio'
91
+
92
+ str = StringIO.new
93
+ data = Plist::parse_xml(str)
94
+
95
+ assert_nil data
96
+ end
97
+
98
+ end
99
+
100
+ __END__
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sj-plist
3
+ version: !ruby/object:Gem::Version
4
+ version: '3.2'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Bleything and Patrick May. Binary support merged by Sijmen Mulder.
9
+ autorequire: plist
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! "Plist is a library to manipulate Property List files, also known as
15
+ plists. It can parse plist files into native Ruby data structures as well as generating
16
+ new plist files from your Ruby objects.\n\n This fork includes support for binary
17
+ plists.\n"
18
+ email:
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - Rakefile
24
+ - README
25
+ - MIT-LICENSE
26
+ - docs/USAGE
27
+ - lib/plist/ascii.rb
28
+ - lib/plist/binary.rb
29
+ - lib/plist/generator.rb
30
+ - lib/plist/parser.rb
31
+ - lib/plist.rb
32
+ - test/test_ascii.rb
33
+ - test/test_binary.rb
34
+ - test/test_data_elements.rb
35
+ - test/test_generator.rb
36
+ - test/test_generator_basic_types.rb
37
+ - test/test_generator_collections.rb
38
+ - test/test_parser.rb
39
+ - test/assets/AlbumData.xml
40
+ - test/assets/commented.plist
41
+ - test/assets/Cookies.plist
42
+ - test/assets/example_data.bin
43
+ - test/assets/example_data.jpg
44
+ - test/assets/example_data.plist
45
+ - test/assets/example_data_ascii.plist
46
+ - test/assets/ruby.plist
47
+ - test/assets/test_data_elements.plist
48
+ - test/assets/test_empty_key.plist
49
+ homepage: http://github.com/sjmulder/plist
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: All-purpose Property List manipulation library (w/ binary support).
73
+ test_files:
74
+ - test/test_ascii.rb
75
+ - test/test_binary.rb
76
+ - test/test_data_elements.rb
77
+ - test/test_generator.rb
78
+ - test/test_generator_basic_types.rb
79
+ - test/test_generator_collections.rb
80
+ - test/test_parser.rb