* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
[svn.git] / subversion / bindings / swig / ruby / test / test_core.rb
blobe72254263070a833677df25dd4cc2a388940cd11
1 require "my-assertions"
2 require "util"
4 require "stringio"
6 require "svn/core"
7 require "svn/repos"
9 class SvnCoreTest < Test::Unit::TestCase
10   include SvnTestUtil
12   def setup
13     setup_default_variables
14     @config_file = File.join(@config_path, Svn::Core::CONFIG_CATEGORY_CONFIG)
15     @servers_file = File.join(@config_path, Svn::Core::CONFIG_CATEGORY_SERVERS)
16     setup_repository(@repos_path)
17     setup_config
18     setup_tmp
19   end
21   def teardown
22     teardown_repository(@repos_path)
23     teardown_config
24     teardown_tmp
25   end
27   def test_binary_mime_type?
28     assert(Svn::Core.binary_mime_type?("image/png"))
29     assert(!Svn::Core.binary_mime_type?("text/plain"))
30   end
32   def test_time
33     now = Time.now.gmtime
34     str = now.strftime("%Y-%m-%dT%H:%M:%S.") + "#{now.usec}Z"
36     assert_equal(now, Time.from_svn_format(str))
38     apr_time = now.to_i * 1000000 + now.usec
39     assert_equal(apr_time, now.to_apr_time)
40   end
42   def test_not_new_auth_provider_object
43     assert_raise(NoMethodError) do
44       Svn::Core::AuthProviderObject.new
45     end
46   end
48   def test_version_to_x
49     major = 1
50     minor = 2
51     patch = 3
52     tag = "-dev"
53     ver = Svn::Core::Version.new(major, minor, patch, tag)
55     assert_equal("#{major}.#{minor}.#{patch}#{tag}", ver.to_s)
56     assert_equal([major, minor, patch, tag], ver.to_a)
57   end
59   def test_version_valid?
60     assert_true(Svn::Core::Version.new(1, 2, 3, "-devel").valid?)
61     assert_true(Svn::Core::Version.new(nil, nil, nil, "").valid?)
62     assert_true(Svn::Core::Version.new.valid?)
63   end
65   def test_version_equal
66     major = 1
67     minor = 2
68     patch = 3
69     tag = ""
70     ver1 = Svn::Core::Version.new(major, minor, patch, tag)
71     ver2 = Svn::Core::Version.new(major, minor, patch, tag)
72     ver3 = Svn::Core::Version.new
73     assert_equal(ver1, ver2)
74     assert_not_equal(ver1, ver3)
75   end
77   def test_version_compatible?
78     major = 1
79     minor = 2
80     patch = 3
82     my_tag = "-devel"
83     lib_tag = "-devel"
84     ver1 = Svn::Core::Version.new(major, minor, patch, my_tag)
85     ver2 = Svn::Core::Version.new(major, minor, patch, lib_tag)
86     ver3 = Svn::Core::Version.new(major, minor, patch, lib_tag + "x")
87     assert_true(ver1.compatible?(ver2))
88     assert_false(ver1.compatible?(ver3))
90     my_tag = "-devel"
91     lib_tag = ""
92     ver1 = Svn::Core::Version.new(major, minor, patch, my_tag)
93     ver2 = Svn::Core::Version.new(major, minor, patch, lib_tag)
94     ver3 = Svn::Core::Version.new(major, minor, patch - 1, lib_tag)
95     assert_false(ver1.compatible?(ver2))
96     assert_true(ver1.compatible?(ver3))
98     tag = ""
99     ver1 = Svn::Core::Version.new(major, minor, patch, tag)
100     ver2 = Svn::Core::Version.new(major, minor, patch, tag)
101     ver3 = Svn::Core::Version.new(major, minor, patch - 1, tag)
102     ver4 = Svn::Core::Version.new(major, minor + 1, patch, tag)
103     ver5 = Svn::Core::Version.new(major, minor - 1, patch, tag)
104     assert_true(ver1.compatible?(ver2))
105     assert_true(ver1.compatible?(ver3))
106     assert_true(ver1.compatible?(ver4))
107     assert_false(ver1.compatible?(ver5))
108   end
110   def test_version
111     vers = [Svn::Core::VER_MAJOR, Svn::Core::VER_MINOR, Svn::Core::VER_PATCH]
112     ver_num = vers.collect {|ver| ver.to_s}.join(".")
113     assert_equal(ver_num, Svn::Core::VER_NUM)
114     assert_equal("#{ver_num}#{Svn::Core::VER_NUMTAG}", Svn::Core::VER_NUMBER)
115     assert_equal("#{ver_num}#{Svn::Core::VER_TAG}", Svn::Core::VERSION)
116   end
118   def test_auth_parameter
119     key = "key"
120     value = "value"
121     auth = Svn::Core::AuthBaton.new
122     assert_nil(auth[key])
123     auth[key] = value
124     assert_equal(value, auth[key])
126     assert_raise(TypeError) do
127       auth[key] = 1
128     end
129   end
131   def test_pool_GC
132     gc_disable do
133       made_number_of_pool = 100
134       pools = []
136       gc
137       before_number_of_pools = Svn::Core::Pool.number_of_pools
138       made_number_of_pool.times do
139         pools << used_pool
140       end
141       gc
142       current_number_of_pools = Svn::Core::Pool.number_of_pools
143       created_number_of_pools = current_number_of_pools - before_number_of_pools
144       assert_operator(made_number_of_pool, :<=, current_number_of_pools)
146       gc
147       pools.clear
148       before_number_of_pools = Svn::Core::Pool.number_of_pools
149       gc
150       current_number_of_pools = Svn::Core::Pool.number_of_pools
151       recycled_number_of_pools =
152         before_number_of_pools - current_number_of_pools
153       assert_operator(made_number_of_pool * 0.8, :<=, recycled_number_of_pools)
154     end
155   end
157   def test_config
158     assert_equal([
159                    Svn::Core::CONFIG_CATEGORY_CONFIG,
160                    Svn::Core::CONFIG_CATEGORY_SERVERS,
161                  ].sort,
162                  Svn::Core::Config.config(@config_path).keys.sort)
164     config = Svn::Core::Config.read(@config_file)
165     section = Svn::Core::CONFIG_SECTION_HELPERS
166     option = Svn::Core::CONFIG_OPTION_DIFF_CMD
167     value = "diff"
169     assert_nil(config.get(section, option))
170     config.set(section, option, value)
171     assert_equal(value, config.get(section, option))
172   end
174   def test_config_bool
175     config = Svn::Core::Config.read(@config_file)
176     section = Svn::Core::CONFIG_SECTION_MISCELLANY
177     option = Svn::Core::CONFIG_OPTION_ENABLE_AUTO_PROPS
179     assert(config.get_bool(section, option, true))
180     config.set_bool(section, option, false)
181     assert(!config.get_bool(section, option, true))
182   end
184   def test_config_each
185     config = Svn::Core::Config.read(@config_file)
186     section = Svn::Core::CONFIG_SECTION_HELPERS
187     options = {
188       Svn::Core::CONFIG_OPTION_DIFF_CMD => "diff",
189       Svn::Core::CONFIG_OPTION_DIFF3_CMD => "diff3",
190     }
192     infos = {}
193     config.each_option(section) do |name, value|
194       infos[name] = value
195       true
196     end
197     assert_equal({}, infos)
199     section_names = []
200     config.each_section do |name|
201       section_names << name
202       true
203     end
204     assert_equal([], section_names)
206     options.each do |option, value|
207       config.set(section, option, value)
208     end
210     config.each_option(section) do |name, value|
211       infos[name] = value
212       true
213     end
214     assert_equal(options, infos)
216     config.each_section do |name|
217       section_names << name
218       true
219     end
220     assert_equal([section], section_names)
222     infos = options.collect {|key, value| [section, key, value]}
223     config_infos = []
224     config.each do |section, name, value|
225       config_infos << [section, name, value]
226     end
227     assert_equal(infos.sort, config_infos.sort)
228     assert_equal(infos.sort, config.collect {|args| args}.sort)
229   end
231   def test_config_find_group
232     config = Svn::Core::Config.read(@config_file)
233     section = Svn::Core::CONFIG_SECTION_HELPERS
234     option = Svn::Core::CONFIG_OPTION_DIFF_CMD
235     value = "diff"
237     assert_nil(config.find_group(value, section))
238     config.set(section, option, value)
239     assert_equal(option, config.find_group(value, section))
240   end
242   def test_config_get_server_setting
243     group = "group1"
244     host_prop_name = "http-proxy-host"
245     host_prop_value = "*.example.com"
246     default_host_value = "example.net"
247     port_prop_name = "http-proxy-port"
248     port_prop_value = 8080
249     default_port_value = 1818
251     File.open(@servers_file, "w") do |f|
252       f.puts("[#{group}]")
253     end
255     config = Svn::Core::Config.read(@servers_file)
256     assert_equal(default_host_value,
257                  config.get_server_setting(group,
258                                            host_prop_name,
259                                            default_host_value))
260     assert_equal(default_port_value,
261                  config.get_server_setting_int(group,
262                                                port_prop_name,
263                                                default_port_value))
265     File.open(@servers_file, "w") do |f|
266       f.puts("[#{group}]")
267       f.puts("#{host_prop_name} = #{host_prop_value}")
268       f.puts("#{port_prop_name} = #{port_prop_value}")
269     end
271     config = Svn::Core::Config.read(@servers_file)
272     assert_equal(host_prop_value,
273                  config.get_server_setting(group,
274                                            host_prop_name,
275                                            default_host_value))
276     assert_equal(port_prop_value,
277                  config.get_server_setting_int(group,
278                                                port_prop_name,
279                                                default_port_value))
280   end
282   def test_config_auth_data
283     cred_kind = Svn::Core::AUTH_CRED_SIMPLE
284     realm_string = "sample"
285     assert_nil(Svn::Core::Config.read_auth_data(cred_kind,
286                                                 realm_string,
287                                                 @config_path))
288     Svn::Core::Config.write_auth_data({},
289                                       cred_kind,
290                                       realm_string,
291                                       @config_path)
292     assert_equal({Svn::Core::CONFIG_REALMSTRING_KEY => realm_string},
293                  Svn::Core::Config.read_auth_data(cred_kind,
294                                                   realm_string,
295                                                   @config_path))
296   end
298   def test_config_to_s
299     config = Svn::Core::Config.read(@config_file)
300     section = Svn::Core::CONFIG_SECTION_HELPERS
301     options = {
302       Svn::Core::CONFIG_OPTION_DIFF_CMD => "diff",
303       Svn::Core::CONFIG_OPTION_DIFF3_CMD => "diff3",
304     }
306     options.each do |option, value|
307       config[section, option] = value
308     end
310     temp_config = Tempfile.new("svn-test-config")
311     temp_config.open
312     temp_config.print(config.to_s)
313     temp_config.close
315     parsed_config = Svn::Core::Config.read(temp_config.path)
316     assert_equal({section => options}, parsed_config.to_hash)
317   end
319   def test_config_to_hash
320     config = Svn::Core::Config.read(@config_file)
321     section = Svn::Core::CONFIG_SECTION_HELPERS
322     options = {
323       Svn::Core::CONFIG_OPTION_DIFF_CMD => "diff",
324       Svn::Core::CONFIG_OPTION_DIFF3_CMD => "diff3",
325     }
327     assert_equal({}, config.to_hash)
329     options.each do |option, value|
330       config[section, option] = value
331     end
333     assert_equal({section => options}, config.to_hash)
334   end
336   def test_diff_version
337     assert_equal(Svn::Core.subr_version, Svn::Core::Diff.version)
338   end
340   def test_diff_unified
341     original = Tempfile.new("original")
342     modified = Tempfile.new("modified")
343     original_src = <<-EOS
344   a
346   c
348     modified_src = <<-EOS
353     original_header = "(orig)"
354     modified_header = "(mod)"
356     original.open
357     original.print(original_src)
358     original.close
359     modified.open
360     modified.print(modified_src)
361     modified.close
363     expected = <<-EOD
364 --- #{original_header}
365 +++ #{modified_header}
366 @@ -1,3 +1,3 @@
367 -  a
369 -  c
372 + c
374     diff = Svn::Core::Diff.file_diff(original.path, modified.path)
375     assert_equal(normalize_line_break(expected),
376                  diff.unified(original_header, modified_header))
378     options = Svn::Core::DiffFileOptions.parse("--ignore-space-change")
379     expected = <<-EOD
380 --- #{original_header}
381 +++ #{modified_header}
382 @@ -1,3 +1,3 @@
383 -  a
387    c
389     diff = Svn::Core::Diff.file_diff(original.path, modified.path, options)
390     assert_equal(normalize_line_break(expected),
391                  diff.unified(original_header, modified_header))
393     options = Svn::Core::DiffFileOptions.parse("--ignore-all-space")
394     expected = <<-EOD
395 --- #{original_header}
396 +++ #{modified_header}
397 @@ -1,3 +1,3 @@
398    a
401    c
403     diff = Svn::Core::Diff.file_diff(original.path, modified.path, options)
404     assert_equal(normalize_line_break(expected),
405                  diff.unified(original_header, modified_header))
406   end
408   def test_diff_merge
409     original = Tempfile.new("original")
410     modified = Tempfile.new("modified")
411     latest = Tempfile.new("latest")
412     original_src = <<-EOS
419     modified_src = <<-EOS
426     latest_src = <<-EOS
428   b
434     original.open
435     original.print(original_src)
436     original.close
437     modified.open
438     modified.print(modified_src)
439     modified.close
440     latest.open
441     latest.print(latest_src)
442     latest.close
444     expected = <<-EOD
446   b
451     diff = Svn::Core::Diff.file_diff3(original.path,
452                                       modified.path,
453                                       latest.path)
454     assert_equal(normalize_line_break(expected), diff.merge)
456     options = Svn::Core::DiffFileOptions.parse("--ignore-space-change")
457     expected = <<-EOD
464     diff = Svn::Core::Diff.file_diff3(original.path,
465                                       modified.path,
466                                       latest.path,
467                                       options)
468     assert_equal(normalize_line_break(expected), diff.merge)
470     options = Svn::Core::DiffFileOptions.parse("--ignore-all-space")
471     expected = <<-EOD
478     diff = Svn::Core::Diff.file_diff3(original.path,
479                                       modified.path,
480                                       latest.path,
481                                       options)
482     assert_equal(normalize_line_break(expected), diff.merge)
483   end
485   def test_diff_file_options
486     args = ["--ignore-all-space"]
487     options = Svn::Core::DiffFileOptions.parse(*args)
488     assert_equal(Svn::Core::DIFF_FILE_IGNORE_SPACE_ALL,
489                  options.ignore_space)
490     assert_false(options.ignore_eol_style)
492     args = ["--ignore-space-change"]
493     options = Svn::Core::DiffFileOptions.parse(*args)
494     assert_equal(Svn::Core::DIFF_FILE_IGNORE_SPACE_CHANGE,
495                  options.ignore_space)
496     assert_false(options.ignore_eol_style)
498     args = ["--ignore-space-change", "--ignore-eol-style"]
499     options = Svn::Core::DiffFileOptions.parse(*args)
500     assert_equal(Svn::Core::DIFF_FILE_IGNORE_SPACE_CHANGE,
501                  options.ignore_space)
502     assert_true(options.ignore_eol_style)
504     options = Svn::Core::DiffFileOptions.parse(args)
505     assert_equal(Svn::Core::DIFF_FILE_IGNORE_SPACE_CHANGE,
506                  options.ignore_space)
507     assert_true(options.ignore_eol_style)
508   end
510   def test_create_commit_info
511     info = Svn::Core::CommitInfo.new
512     now = Time.now.gmtime
513     date_str = now.strftime("%Y-%m-%dT%H:%M:%S")
514     date_str << ".#{now.usec}Z"
515     info.date = date_str
516     assert_equal(now, info.date)
517   end
519   def test_svn_prop
520     assert(Svn::Core::Property.svn_prop?("svn:mime-type"))
521     assert(!Svn::Core::Property.svn_prop?("my-mime-type"))
523     assert(Svn::Core::Property.has_svn_prop?({"svn:mime-type" => "text/plain"}))
524     assert(!Svn::Core::Property.has_svn_prop?({"my-mime-type" => "text/plain"}))
526     assert(Svn::Core::Property.have_svn_prop?({"svn:mime-type" => "text/plain"}))
527     assert(!Svn::Core::Property.have_svn_prop?({"my-mime-type" => "text/plain"}))
528   end
530   def test_valid_prop_name
531     assert(Svn::Core::Property.valid_name?("svn:mime-type"))
532     assert(Svn::Core::Property.valid_name?("my-mime-type"))
533     assert(!Svn::Core::Property.valid_name?("プロパティ"))
534   end
536   def test_depth_conversion
537     %w(unknown empty files immediates infinity).each do |depth|
538       depth_value = Svn::Core.const_get("DEPTH_#{depth.upcase}")
539       assert_equal(depth_value, Svn::Core::Depth.from_string(depth))
540       assert_equal(depth, Svn::Core::Depth.to_string(depth_value))
541     end
542   end
544   def test_depth_input
545     depth_infinity = Svn::Core::DEPTH_INFINITY
546     assert_equal("infinity", Svn::Core::Depth.to_string(depth_infinity))
547     assert_equal("infinity", Svn::Core::Depth.to_string("infinity"))
548     assert_equal("infinity", Svn::Core::Depth.to_string(:infinity))
549     assert_equal("unknown", Svn::Core::Depth.to_string("XXX"))
550     assert_raises(ArgumentError) do
551       Svn::Core::Depth.to_string([])
552     end
553   end
555   def test_stream_copy
556     source = "content"
557     original = StringIO.new(source)
558     copied = StringIO.new("")
559     original_stream = Svn::Core::Stream.new(original)
560     copied_stream = Svn::Core::Stream.new(copied)
563     original_stream.copy(copied_stream)
565     copied.rewind
566     assert_equal("", original.read)
567     assert_equal(source, copied.read)
570     original.rewind
571     copied.string = ""
572     assert_raises(Svn::Error::Cancelled) do
573       original_stream.copy(copied_stream) do
574         raise Svn::Error::Cancelled
575       end
576     end
578     copied.rewind
579     assert_equal(source, original.read)
580     assert_equal("", copied.read)
581   end
583   def test_mime_type_parse
584     type_map = {
585       "html" => "text/html",
586       "htm" => "text/html",
587       "png" => "image/png",
588     }
589     mime_types_source = <<-EOM
590 text/html html htm
591 application/octet-stream
593 image/png png
596     mime_types = Tempfile.new("svn-ruby-mime-type")
597     mime_types.puts(mime_types_source)
598     mime_types.close
600     assert_equal(type_map, Svn::Core::MimeType.parse_file(mime_types.path))
601     assert_equal(type_map, Svn::Core::MimeType.parse(mime_types_source))
602   end
604   def test_mime_type_detect
605     empty_file = Tempfile.new("svn-ruby-mime-type")
606     assert_equal(nil, Svn::Core::MimeType.detect(empty_file.path))
608     binary_file = Tempfile.new("svn-ruby-mime-type")
609     binary_file.print("\0\1\2")
610     binary_file.close
611     assert_equal("application/octet-stream",
612                  Svn::Core::MimeType.detect(binary_file.path))
614     text_file = Tempfile.new("svn-ruby-mime-type")
615     text_file.print("abcde")
616     text_file.close
617     assert_equal(nil, Svn::Core::MimeType.detect(text_file.path))
618   end
620   def test_mime_type_detect_with_type_map
621     type_map = {
622       "html" => "text/html",
623       "htm" => "text/html",
624       "png" => "image/png",
625     }
627     nonexistent_html_file = File.join(@tmp_path, "nonexistent.html")
628     assert_raises(Svn::Error::BadFilename) do
629       Svn::Core::MimeType.detect(nonexistent_html_file)
630     end
631     assert_raises(Svn::Error::BadFilename) do
632       Svn::Core::MimeType.detect(nonexistent_html_file, type_map)
633     end
635     empty_html_file = File.join(@tmp_path, "empty.html")
636     FileUtils.touch(empty_html_file)
637     assert_equal(nil, Svn::Core::MimeType.detect(empty_html_file))
638     assert_equal("text/html",
639                  Svn::Core::MimeType.detect(empty_html_file, type_map))
641     empty_htm_file = File.join(@tmp_path, "empty.htm")
642     FileUtils.touch(empty_htm_file)
643     assert_equal(nil, Svn::Core::MimeType.detect(empty_htm_file))
644     assert_equal("text/html",
645                  Svn::Core::MimeType.detect(empty_htm_file, type_map))
648     dummy_png_file = File.join(@tmp_path, "dummy.png")
649     File.open(dummy_png_file, "wb") do |png|
650       png.print("\211PNG\r\n\032\n")
651     end
652     assert_equal(nil, Svn::Core::MimeType.detect(dummy_png_file))
653     assert_equal("image/png",
654                  Svn::Core::MimeType.detect(dummy_png_file, type_map))
656     empty_png_file = File.join(@tmp_path, "empty.png")
657     FileUtils.touch(empty_png_file)
658     assert_equal(nil, Svn::Core::MimeType.detect(empty_png_file))
659     assert_equal("image/png",
660                  Svn::Core::MimeType.detect(empty_png_file, type_map))
662     invalid_png_file = File.join(@tmp_path, "invalid.png")
663     File.open(invalid_png_file, "w") do |png|
664       png.puts("text")
665     end
666     assert_equal(nil, Svn::Core::MimeType.detect(invalid_png_file))
667     assert_equal("image/png",
668                  Svn::Core::MimeType.detect(invalid_png_file, type_map))
669   end
671   def test_prop_categorize
672     name = "svn:mime-type"
673     value = "text/plain"
674     entry_name = "svn:entry:XXX"
675     entry_value = "XXX"
677     props = [Svn::Core::Prop.new(name, value),
678              Svn::Core::Prop.new(entry_name, entry_value)]
679     assert_equal([
680                   [Svn::Core::Prop.new(entry_name, entry_value)],
681                   [],
682                   [Svn::Core::Prop.new(name, value)],
683                  ],
684                  Svn::Core::Property.categorize(props))
686     props = {name => value, entry_name => entry_value}
687     assert_equal([
688                   {entry_name => entry_value },
689                   {},
690                   {name => value},
691                  ],
692                  Svn::Core::Property.categorize2(props))
693   end
695   def test_mergeinfo_parse
696     assert_equal({}, Svn::Core::MergeInfo.parse(""))
698     input = "/trunk: 5,7-9,10,11,13,14"
699     result = Svn::Core::MergeInfo.parse(input)
700     assert_equal(["/trunk"], result.keys)
701     assert_equal([[4, 5, true], [6, 11, true], [12, 14, true]],
702                  result["/trunk"].collect {|range| range.to_a})
704     input = "/trunk: 5*,7-9,10,11,13,14"
705     result = Svn::Core::MergeInfo.parse(input)
706     assert_equal(["/trunk"], result.keys)
707     assert_equal([[4, 5, false], [6, 11, true], [12, 14, true]],
708                  result["/trunk"].collect {|range| range.to_a})
709   end
711   def test_mergeinfo_diff
712     input1 = "/trunk: 5,7-9,10,11,13,14"
713     input2 = "/trunk: 5,6,7-9,10,11"
715     info1 = Svn::Core::MergeInfo.parse(input1)
716     info2 = Svn::Core::MergeInfo.parse(input2)
717     result = info1.diff(info2)
718     deleted, added = result
719     assert_equal(["/trunk"], deleted.keys)
720     assert_equal(["/trunk"], added.keys)
721     assert_equal([[12, 14, true]],
722                  deleted["/trunk"].collect {|range| range.to_a})
723     assert_equal([[5, 6, true]],
724                  added["/trunk"].collect {|range| range.to_a})
725   end
727   def test_mergeinfo_merge
728     info = Svn::Core::MergeInfo.parse("/trunk: 5,7-9")
729     assert_equal(["/trunk"], info.keys)
730     assert_equal([[4, 5, true], [6, 9, true]],
731                  info["/trunk"].collect {|range| range.to_a})
733     changes = Svn::Core::MergeInfo.parse("/trunk: 6-13")
734     merged = info.merge(changes)
735     assert_equal(["/trunk"], merged.keys)
736     assert_equal([[4, 13, true]],
737                  merged["/trunk"].collect {|range| range.to_a})
738   end
740   def test_mergeinfo_remove
741     info = Svn::Core::MergeInfo.parse("/trunk: 5-13")
742     assert_equal(["/trunk"], info.keys)
743     assert_equal([[4, 13, true]],
744                  info["/trunk"].collect {|range| range.to_a})
746     eraser = Svn::Core::MergeInfo.parse("/trunk: 7,9-11")
747     removed = info.remove(eraser)
748     assert_equal(["/trunk"], removed.keys)
749     assert_equal([[4, 6, true], [7, 8, true], [11, 13, true]],
750                  removed["/trunk"].collect {|range| range.to_a})
751   end
753   def test_mergeinfo_to_s
754     info = Svn::Core::MergeInfo.parse("/trunk: 5,7,9-13")
755     assert_equal("/trunk:5,7,9-13", info.to_s)
756     assert_not_equal(info.to_s, info.inspect)
758     info = Svn::Core::MergeInfo.parse("/trunk: 5*,7,9-13")
759     assert_equal("/trunk:5*,7,9-13", info.to_s)
760     assert_not_equal(info.to_s, info.inspect)
761   end
763   def test_mergeinfo_sort
764     info = Svn::Core::MergeInfo.parse("/trunk: 5,7,9-13")
766     info["/trunk"] = info["/trunk"].reverse
767     assert_equal(["/trunk"], info.keys)
768     assert_equal([[13, 8, true], [7, 6, true], [5, 4, true]],
769                  info["/trunk"].collect {|range| range.to_a})
771     sorted_info = info.sort
772     assert_equal(["/trunk"], sorted_info.keys)
773     assert_equal([[5, 4, true], [7, 6, true], [13, 8, true]],
774                  sorted_info["/trunk"].collect {|range| range.to_a})
775   end
777   def test_range_list_diff
778     range_list1 = Svn::Core::RangeList.new([5, 5, true], [9, 13, true])
779     range_list2 = Svn::Core::RangeList.new([7, 11, true])
781     deleted, added = range_list1.diff(range_list2)
782     assert_equal([[7, 9, true]], added.collect {|range| range.to_a})
783     assert_equal([[5, 5, true], [11, 13, true]],
784                  deleted.collect {|range| range.to_a})
785   end
787   def test_range_list_merge
788     range_list1 = Svn::Core::RangeList.new([5, 5, true],
789                                            [7, 7, true], [9, 13, true])
790     range_list2 = Svn::Core::RangeList.new([5, 9, true])
792     merged = range_list1.merge(range_list2)
793     assert_equal([[5, 13, true]], merged.collect {|range| range.to_a})
794   end
796   def test_range_list_remove
797     range_list1 = Svn::Core::RangeList.new([5, 5, true],
798                                            [7, 7, true], [9, 13, true])
799     range_list2 = Svn::Core::RangeList.new([5, 9, true])
801     removed = range_list1.remove(range_list2)
802     assert_equal([[9, 13, true]], removed.collect {|range| range.to_a})
803   end
805   def test_range_list_intersect
806     range_list1 = Svn::Core::RangeList.new([5, 9, true])
807     range_list2 = Svn::Core::RangeList.new([5, 5, true],
808                                            [7, 7, true], [9, 13, true])
810     intersected = range_list1.intersect(range_list2)
811     assert_equal([[5, 5, true], [7, 7, true]],
812                  intersected.collect {|range| range.to_a})
813   end
815   def test_range_list_reverse
816     range_list = Svn::Core::RangeList.new([5, 5, true],
817                                           [7, 7, true], [9, 13, true])
819     reversed = range_list.reverse
820     assert_equal([[13, 9, true], [7, 7, true], [5, 5, true]],
821                  reversed.collect {|range| range.to_a})
822   end
824   def test_range_list_to_s
825     range_list = Svn::Core::RangeList.new([5, 5, true],
826                                           [7, 7, true], [9, 13, true])
827     assert_equal("6-5,8-7,10-13", range_list.to_s)
828     assert_not_equal("6-5,8-7,10-13", range_list.inspect)
829   end
831   def test_mergerange_equality
832     mergerange1 = Svn::Core::MergeRange.new(1,2,true)
833     mergerange2 = Svn::Core::MergeRange.new(1,2,true)
834     mergerange3 = Svn::Core::MergeRange.new(1,2,false)
835     mergerange4 = Svn::Core::MergeRange.new(1,4,true)
837     assert_equal(mergerange1, mergerange2)
838     assert_not_equal(mergerange1, mergerange3)
839     assert_not_equal(mergerange1, mergerange4)
840   end
842   private
843   def used_pool
844     pool = Svn::Core::Pool.new
845     now = Time.now.gmtime
846     Svn::Core.time_to_human_cstring(now.to_apr_time, pool)
847     pool
848   end