reapack-index 1.0beta3 → 1.0beta4

Sign up to get free protection for your applications and to get access to all the features.
@@ -132,7 +132,7 @@ class TestMetadata < MiniTest::Test
132
132
  md.push_link :website, 'hello'
133
133
  end
134
134
 
135
- assert_equal 'invalid link: hello', error.message
135
+ assert_equal "invalid link 'hello'", error.message
136
136
  assert_equal after.chomp, before.to_s
137
137
  end
138
138
 
@@ -172,7 +172,7 @@ class TestMetadata < MiniTest::Test
172
172
  md.remove_link :website, 'hello'
173
173
  end
174
174
 
175
- assert_equal 'no such website link: hello', error.message
175
+ assert_equal "no such website link 'hello'", error.message
176
176
  end
177
177
 
178
178
  def test_replace_link_url
@@ -3,87 +3,96 @@ require File.expand_path '../helper', __FILE__
3
3
  class TestNamedNode < MiniTest::Test
4
4
  include XMLHelper
5
5
 
6
+ def setup
7
+ @mock = Class.new(ReaPack::Index::NamedNode) { @tag = 'node' }
8
+ end
9
+
6
10
  def test_no_tag_set
7
- mock = Class.new ReaPack::Index::NamedNode
11
+ @ock = Class.new ReaPack::Index::NamedNode
8
12
  assert_raises { mock.tag }
9
13
  end
10
14
 
11
- def test_find_in
12
- node = make_node '<root><node name="hello"/><node name="world"/></root>'
13
- mock = Class.new(ReaPack::Index::NamedNode) { @tag = 'node' }
15
+ def test_create_node
16
+ before = make_node '<parent />'
14
17
 
15
- instance = mock.find_in node, 'hello'
16
- assert_nil mock.find_in node, 'bacon'
18
+ after = <<-XML
19
+ <parent>
20
+ <node name="name here"/>
21
+ </parent>
22
+ XML
17
23
 
18
- assert_kind_of mock, instance
19
- assert_equal 'hello', instance.name
24
+ instance = @mock.create 'name here', before
25
+ assert instance.is_new?, 'instance is not new'
26
+ assert instance.modified?, 'instance is not modified'
27
+
28
+ assert_equal after.chomp, before.to_s
29
+ end
30
+
31
+ def test_from_existing_node
32
+ before = make_node '<node name="1.0"/>'
33
+
34
+ instance = @mock.new before
20
35
  refute instance.is_new?, 'instance is new'
21
36
  refute instance.modified?, 'instance is modified'
22
37
  end
23
38
 
39
+ def test_find_one
40
+ node = make_node '<root><node name="hello"/><node name="world"/></root>'
41
+
42
+ instance = @mock.find_one 'hello', node
43
+ assert_kind_of @mock, instance
44
+ assert_equal 'hello', instance.name
45
+
46
+ assert_nil @mock.find_one 'bacon', node
47
+ end
48
+
24
49
  def test_find_all
25
50
  node = make_node '<root><node name="hello"/><node name="world"/></root>'
26
- mock = Class.new(ReaPack::Index::NamedNode) { @tag = 'node' }
27
51
 
28
- instances = mock.find_all node
52
+ instances = @mock.find_all node
29
53
  assert_equal 2, instances.size
30
54
 
31
- assert_kind_of mock, instances.first
55
+ assert_kind_of @mock, instances.first
32
56
  assert_equal 'hello', instances.first.name
33
- refute instances.first.is_new?, 'instance is new'
34
57
 
58
+ assert_kind_of @mock, instances.last
35
59
  assert_equal 'world', instances.last.name
36
60
  end
37
61
 
38
- def test_get_readonly
62
+ def test_fetch_existing
39
63
  node = make_node '<root><node name="hello"/></root>'
40
- mock = Class.new(ReaPack::Index::NamedNode) { @tag = 'node' }
41
64
 
42
- instance = mock.get 'hello', node, false
43
- assert_kind_of mock, instance
65
+ instance = @mock.fetch 'hello', node, false
66
+ assert_kind_of @mock, instance
44
67
 
45
- assert_nil mock.get 'world', node, false
68
+ assert_nil @mock.fetch 'world', node, false
46
69
  end
47
70
 
48
- def test_get_create
71
+ def test_fetch_create
49
72
  node = make_node '<root></root>'
50
- mock = Class.new(ReaPack::Index::NamedNode) { @tag = 'node' }
51
73
 
52
- instance = mock.get 'hello', node, true
74
+ instance = @mock.fetch 'hello', node, true
53
75
 
54
- assert_kind_of mock, instance
76
+ assert_kind_of @mock, instance
55
77
  assert instance.is_new?, 'instance is not new'
56
78
  assert instance.modified?, 'instance is not modified'
57
79
  end
58
80
 
59
81
  def test_get_null_parent
60
- mock = Class.new(ReaPack::Index::NamedNode) { @tag = 'node' }
61
-
62
- assert_nil mock.get 'hello', nil, false
82
+ assert_nil @mock.fetch 'hello', nil, false
63
83
  end
64
84
 
65
85
  def test_empty
66
- node = make_node <<-XML
67
- <root>
68
- <node name="first"/>
69
- <node name="second"><something/></node>
70
- </root>
71
- XML
72
-
73
- mock = Class.new(ReaPack::Index::NamedNode) { @tag = 'node' }
74
-
75
- first = mock.find_in node, 'first'
86
+ first = @mock.new make_node('<node/>')
76
87
  assert first.empty?, 'first is not empty'
77
88
 
78
- second = mock.find_in node, 'second'
89
+ second = @mock.new make_node('<node><something/></node>')
79
90
  refute second.empty?, 'second is empty'
80
91
  end
81
92
 
82
93
  def test_remove
83
94
  node = make_node '<root><node name="test"/></root>'
84
- mock = Class.new(ReaPack::Index::NamedNode) { @tag = 'node' }
85
-
86
- instance = mock.find_in node, 'test'
95
+ instance = @mock.find_one 'test', node
87
96
 
88
97
  assert_equal 1, node.children.size
89
98
  instance.remove
@@ -91,10 +100,9 @@ class TestNamedNode < MiniTest::Test
91
100
  end
92
101
 
93
102
  def test_children
94
- node = make_node '<root><node name="test"><a/><b/></root>'
95
- mock = Class.new(ReaPack::Index::NamedNode) { @tag = 'node' }
103
+ node = make_node '<node name="test"><a/><b><a/></b></node>'
96
104
 
97
- instance = mock.find_in node, 'test'
98
- assert_equal node.css('a').inspect, instance.children('a').inspect
105
+ instance = @mock.new node
106
+ assert_equal node.css('> a').inspect, instance.children('a').inspect
99
107
  end
100
108
  end
@@ -3,39 +3,16 @@ require File.expand_path '../helper', __FILE__
3
3
  class TestPackage < MiniTest::Test
4
4
  include XMLHelper
5
5
 
6
- def test_create
7
- before = make_node '<category />'
8
- after = <<-XML
9
- <category>
10
- <reapack name="1.0"/>
11
- </category>
12
- XML
13
-
14
- pkg = ReaPack::Index::Package.new '1.0', before
15
- assert pkg.is_new?, 'package is not new'
16
- assert pkg.modified?, 'package is not modified'
17
-
18
- assert_equal after.chomp, before.to_s
19
- end
20
-
21
- def test_use
22
- before = make_node '<reapack name="1.0"/>'
23
-
24
- pkg = ReaPack::Index::Package.new before
25
- refute pkg.is_new?, 'package is new'
26
- refute pkg.modified?, 'package is modified'
27
- end
28
-
29
6
  def test_change_type
30
7
  before = make_node '<reapack name="1.0"/>'
31
8
  after = '<reapack name="1.0" type="script"/>'
32
9
 
33
10
  pkg = ReaPack::Index::Package.new before
34
- assert_empty pkg.type
11
+ assert_nil pkg.type
35
12
 
36
13
  pkg.type = 'script'
37
14
  assert pkg.modified?, 'package is not modified'
38
- assert_equal 'script', pkg.type
15
+ assert_equal :script, pkg.type
39
16
 
40
17
  assert_equal after, before.to_s
41
18
  end
@@ -45,7 +22,7 @@ class TestPackage < MiniTest::Test
45
22
 
46
23
  pkg = ReaPack::Index::Package.new before
47
24
 
48
- assert_equal 'script', pkg.type
25
+ assert_equal :script, pkg.type
49
26
  pkg.type = pkg.type
50
27
 
51
28
  refute pkg.modified?, 'package is modified'
@@ -92,4 +69,16 @@ class TestPackage < MiniTest::Test
92
69
 
93
70
  assert pkg.has_version?('1.1'), 'version 1.1 not found'
94
71
  end
72
+
73
+ def test_category_and_path
74
+ pkg1 = ReaPack::Index::Package.new make_node('<reapack/>')
75
+ assert_nil pkg1.category
76
+ assert_nil pkg1.path
77
+
78
+ pkg2 = ReaPack::Index::Package.create 'test',
79
+ make_node('<category name="Hello/World"/>')
80
+
81
+ assert_equal 'Hello/World', pkg2.category
82
+ assert_equal 'Hello/World/test', pkg2.path
83
+ end
95
84
  end
@@ -0,0 +1,68 @@
1
+ require File.expand_path '../helper', __FILE__
2
+
3
+ class TestProvides < MiniTest::Test
4
+ def test_parse_all
5
+ enum = ReaPack::Index::Provides.parse_each "file1\nfile2"
6
+ assert_equal 2, enum.to_a.size
7
+ end
8
+
9
+ def test_filename
10
+ names = [
11
+ 'file.txt',
12
+ 'hello world.lua',
13
+ '[file]',
14
+ ]
15
+
16
+ assert_equal names,
17
+ names.map {|l| ReaPack::Index::Provides.parse(l).file_pattern }
18
+ end
19
+
20
+ def test_url_template
21
+ bucket = [
22
+ 'file http://hello/world',
23
+ 'file https://chunky/bacon',
24
+ 'file file:///foo',
25
+ 'file scp://bar',
26
+ ].map {|l| ReaPack::Index::Provides.parse l }
27
+
28
+ assert_equal ['http://hello/world', 'https://chunky/bacon', 'file:///foo', nil],
29
+ bucket.map {|line| line.url_template }
30
+
31
+ assert_equal ['file', 'file', 'file', 'file scp://bar'],
32
+ bucket.map {|line| line.file_pattern }
33
+ end
34
+
35
+ def test_platforms
36
+ assert_equal [:windows, :win32, :win64, :darwin, :darwin32, :darwin64],
37
+ [
38
+ '[windows] file',
39
+ '[win32] file',
40
+ '[win64] file',
41
+ '[Darwin]file',
42
+ ' [ darwin32 ] file',
43
+ '[win32, darwin64] file',
44
+ ].map {|l| ReaPack::Index::Provides.parse(l).platform }
45
+
46
+ error = assert_raises ReaPack::Index::Error do
47
+ ReaPack::Index::Provides.parse '[HeLlO] file'
48
+ end
49
+
50
+ assert_equal "unknown option (platform or type) 'HeLlO'", error.message
51
+ end
52
+
53
+ def test_types
54
+ assert_equal [:script, :data, nil, nil],
55
+ vals = [
56
+ '[script] file',
57
+ '[windows,Data] file',
58
+ '[windows] file',
59
+ '[,windows,,] file',
60
+ ].map {|l| ReaPack::Index::Provides.parse(l).type }
61
+
62
+ error = assert_raises ReaPack::Index::Error do
63
+ ReaPack::Index::Provides.parse '[, Test] file'
64
+ end
65
+
66
+ assert_equal "unknown option (platform or type) 'Test'", error.message
67
+ end
68
+ end
@@ -0,0 +1,115 @@
1
+ require File.expand_path '../helper', __FILE__
2
+
3
+ class TestSource < MiniTest::Test
4
+ include XMLHelper
5
+
6
+ def test_escape_url
7
+ before = make_node '<version name="1.0"/>'
8
+ after = <<-XML
9
+ <version name="1.0">
10
+ <source platform="all">http://files.cfillion.tk/hello%20world.lua</source>
11
+ </version>
12
+ XML
13
+
14
+ src = ReaPack::Index::Source.new 'http://files.cfillion.tk/hello world.lua'
15
+ assert_equal 'http://files.cfillion.tk/hello world.lua', src.url
16
+
17
+ src.make_node before
18
+
19
+ assert_equal after.chomp, before.to_s
20
+ end
21
+
22
+ def test_invalid_url
23
+ after = '<version name="1.0"/>'
24
+ before = make_node after
25
+
26
+ src = ReaPack::Index::Source.new 'http://hello world/'
27
+ assert_equal 'http://hello world/', src.url
28
+
29
+ error = assert_raises ReaPack::Index::Error do
30
+ src.make_node before
31
+ end
32
+
33
+ refute_empty error.message
34
+ assert_equal after.chomp, before.to_s
35
+ end
36
+
37
+ def test_file
38
+ before = make_node '<version name="1.0"/>'
39
+ after = <<-XML
40
+ <version name="1.0">
41
+ <source platform="all" file="test.png">http://hello/world</source>
42
+ </version>
43
+ XML
44
+
45
+ src = ReaPack::Index::Source.new 'http://hello/world'
46
+ assert_nil src.file
47
+
48
+ src.file = 'test.png'
49
+ assert_equal 'test.png', src.file
50
+
51
+ src.make_node before
52
+
53
+ assert_equal after.chomp, before.to_s
54
+ end
55
+
56
+ def test_platform
57
+ src = ReaPack::Index::Source.new
58
+ assert_equal :all, src.platform
59
+
60
+ src.platform = 'windows'
61
+ assert_equal :windows, src.platform
62
+
63
+ src.platform = nil
64
+ assert_equal :all, src.platform
65
+
66
+ src.platform = :darwin
67
+ assert_equal :darwin, src.platform
68
+
69
+ error = assert_raises ReaPack::Index::Error do
70
+ src.platform = :hello
71
+ end
72
+
73
+ assert_equal "invalid platform 'hello'", error.message
74
+ assert_equal :darwin, src.platform
75
+ end
76
+
77
+ def test_type
78
+ before = make_node '<version name="1.0"/>'
79
+ after = <<-XML
80
+ <version name="1.0">
81
+ <source platform="all" type="effect">http://hello/world</source>
82
+ </version>
83
+ XML
84
+
85
+ src = ReaPack::Index::Source.new 'http://hello/world'
86
+ assert_nil src.type
87
+
88
+ src.type = 'script'
89
+ assert_equal :script, src.type
90
+
91
+ src.type = nil
92
+ assert_nil src.type
93
+
94
+ src.type = :effect
95
+ assert_equal :effect, src.type
96
+
97
+ error = assert_raises ReaPack::Index::Error do
98
+ src.type = 'jsfx'
99
+ end
100
+
101
+ assert_equal "invalid type 'jsfx'", error.message
102
+ assert_equal :effect, src.type
103
+
104
+ src.make_node before
105
+
106
+ assert_equal after.chomp, before.to_s
107
+ end
108
+
109
+ def test_is_platform
110
+ assert_equal [false, true, true, false],
111
+ [nil, :windows, 'windows', :atari].map {|p|
112
+ ReaPack::Index::Source.is_platform? p
113
+ }
114
+ end
115
+ end
@@ -3,29 +3,6 @@ require File.expand_path '../helper', __FILE__
3
3
  class TestVersion < MiniTest::Test
4
4
  include XMLHelper
5
5
 
6
- def test_create
7
- before = make_node '<reapack />'
8
- after = <<-XML
9
- <reapack>
10
- <version name="1.0"/>
11
- </reapack>
12
- XML
13
-
14
- ver = ReaPack::Index::Version.new '1.0', before
15
- assert ver.is_new?, 'version is not new'
16
- assert ver.modified?, 'version is not modified'
17
-
18
- assert_equal after.chomp, before.to_s
19
- end
20
-
21
- def test_use
22
- before = make_node '<version name="1.0"/>'
23
-
24
- ver = ReaPack::Index::Version.new before
25
- refute ver.is_new?, 'version is new'
26
- refute ver.modified?, 'version is modified'
27
- end
28
-
29
6
  def test_set_author
30
7
  before = make_node '<version name="1.0"/>'
31
8
  after = '<version name="1.0" author="cfillion"/>'
@@ -108,12 +85,11 @@ class TestVersion < MiniTest::Test
108
85
  before = make_node '<version name="1.0"/>'
109
86
  after = <<-XML
110
87
  <version name="1.0">
111
- <source platform="all" file="test.lua">http://files.cfillion.tk/test.lua</source>
88
+ <source platform="all">http://files.cfillion.tk/test.lua</source>
112
89
  </version>
113
90
  XML
114
91
 
115
- src = ReaPack::Index::Source.new nil, 'test.lua',
116
- 'http://files.cfillion.tk/test.lua'
92
+ src = ReaPack::Index::Source.new 'http://files.cfillion.tk/test.lua'
117
93
 
118
94
  ver = ReaPack::Index::Version.new before
119
95
  ver.add_source src
@@ -123,37 +99,24 @@ class TestVersion < MiniTest::Test
123
99
  assert_equal after.chomp, before.to_s
124
100
  end
125
101
 
126
- def test_escape_source_url
127
- before = make_node '<version name="1.0"/>'
128
- after = <<-XML
129
- <version name="1.0">
130
- <source platform="all" file="test.lua">http://files.cfillion.tk/hello%20world.lua</source>
131
- </version>
132
- XML
133
-
134
- ver = ReaPack::Index::Version.new before
135
- ver.add_source :all, 'test.lua', 'http://files.cfillion.tk/hello world.lua'
136
-
137
- assert_equal after.chomp, before.to_s
138
- end
139
-
140
102
  def test_replace_sources
141
103
  before = make_node <<-XML
142
104
  <version name="1.0">
143
- <source platform="all" file="old.lua">http://files.cfillion.tk/old.lua</source>
105
+ <source platform="all">http://files.cfillion.tk/old.lua</source>
144
106
  </version>
145
107
  XML
146
108
 
147
109
  after = <<-XML
148
110
  <version name="1.0">
149
- <source platform="all" file="new.lua">http://files.cfillion.tk/new.lua</source>
111
+ <source platform="all">http://files.cfillion.tk/new.lua</source>
150
112
  </version>
151
113
  XML
152
114
 
153
115
  ver = ReaPack::Index::Version.new before
154
116
 
155
117
  ver.replace_sources do
156
- ver.add_source :all, 'new.lua', 'http://files.cfillion.tk/new.lua'
118
+ src = ReaPack::Index::Source.new 'http://files.cfillion.tk/new.lua'
119
+ ver.add_source src
157
120
  end
158
121
 
159
122
  assert ver.modified?, 'version is not modified'
@@ -164,14 +127,15 @@ XML
164
127
  def test_replace_sources_to_identical
165
128
  before = make_node <<-XML
166
129
  <version name="1.0">
167
- <source platform="all" file="test.lua">http://files.cfillion.tk/test.lua</source>
130
+ <source platform="all">http://files.cfillion.tk/test.lua</source>
168
131
  </version>
169
132
  XML
170
133
 
171
134
  ver = ReaPack::Index::Version.new before
172
135
 
173
136
  ver.replace_sources do
174
- ver.add_source :all, 'test.lua', 'http://files.cfillion.tk/test.lua'
137
+ src = ReaPack::Index::Source.new 'http://files.cfillion.tk/test.lua'
138
+ ver.add_source src
175
139
  end
176
140
 
177
141
  refute ver.modified?, 'version is modified'
@@ -186,23 +150,6 @@ XML
186
150
  assert ver.modified?, 'version is not modified'
187
151
  end
188
152
 
189
- def test_source_platform
190
- src = ReaPack::Index::Source.new
191
- assert_equal :all, src.platform
192
-
193
- src.platform = :windows
194
- assert_equal :windows, src.platform
195
-
196
- error = assert_raises ReaPack::Index::Error do
197
- src.platform = :hello
198
- end
199
-
200
- assert_equal 'invalid platform hello', error.message
201
-
202
- src.platform = nil
203
- assert_equal :all, src.platform
204
- end
205
-
206
153
  def test_version_without_sources
207
154
  ver = ReaPack::Index::Version.new make_node('<version name="1.0"/>')
208
155
 
@@ -210,6 +157,6 @@ XML
210
157
  ver.replace_sources do; end
211
158
  end
212
159
 
213
- assert_equal 'no sources found. @provides tag missing?', error.message
160
+ assert_equal 'no files provided', error.message
214
161
  end
215
162
  end