Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/bindings/swig/ruby/test/test_core.rb view on Meta::CPAN
# encoding = utf-8
# ====================================================================
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ====================================================================
require "my-assertions"
require "util"
require "stringio"
require "svn/core"
require "svn/repos"
class SvnCoreTest < Test::Unit::TestCase
include SvnTestUtil
def setup
setup_default_variables
@config_file = File.join(@config_path, Svn::Core::CONFIG_CATEGORY_CONFIG)
@servers_file = File.join(@config_path, Svn::Core::CONFIG_CATEGORY_SERVERS)
setup_repository(@repos_path)
setup_config
setup_tmp
end
def teardown
teardown_repository(@repos_path)
teardown_config
teardown_tmp
end
def test_binary_mime_type?
assert(Svn::Core.binary_mime_type?("image/png"))
assert(!Svn::Core.binary_mime_type?("text/plain"))
end
def test_time
now = Time.now.gmtime
str = now.strftime("%Y-%m-%dT%H:%M:%S.") + "#{now.usec}Z"
if RUBY_VERSION > '1.9'
# ruby 1.9 Time comparison gets into the nano-seconds, strftime
# shaves these off. So we can compare epoch time instead
assert_equal(now.to_i, Time.from_svn_format(str).gmtime.to_i)
else
assert_equal(now, Time.from_svn_format(str).gmtime)
end
apr_time = now.to_i * 1000000 + now.usec
assert_equal(apr_time, now.to_apr_time)
end
def test_not_new_auth_provider_object
assert_raise(NoMethodError) do
Svn::Core::AuthProviderObject.new
end
end
def test_version_to_x
major = 1
minor = 2
patch = 3
tag = "-dev"
ver = Svn::Core::Version.new(major, minor, patch, tag)
assert_equal("#{major}.#{minor}.#{patch}#{tag}", ver.to_s)
assert_equal([major, minor, patch, tag], ver.to_a)
end
def test_version_valid?
assert_true(Svn::Core::Version.new(1, 2, 3, "-devel").valid?)
assert_true(Svn::Core::Version.new(nil, nil, nil, "").valid?)
assert_true(Svn::Core::Version.new.valid?)
end
def test_version_equal
major = 1
minor = 2
patch = 3
tag = ""
ver1 = Svn::Core::Version.new(major, minor, patch, tag)
ver2 = Svn::Core::Version.new(major, minor, patch, tag)
ver3 = Svn::Core::Version.new
assert_equal(ver1, ver2)
assert_not_equal(ver1, ver3)
end
def test_version_compatible?
major = 1
minor = 2
patch = 3
my_tag = "-devel"
src/subversion/subversion/bindings/swig/ruby/test/test_core.rb view on Meta::CPAN
assert(!Svn::Core::Property.have_svn_prop?({"my-mime-type" => "text/plain"}))
end
def test_valid_prop_name
assert(Svn::Core::Property.valid_name?("svn:mime-type"))
assert(Svn::Core::Property.valid_name?("my-mime-type"))
assert(!Svn::Core::Property.valid_name?("ããããã£"))
end
def test_depth_conversion
%w(unknown empty files immediates infinity).each do |depth|
depth_value = Svn::Core.const_get("DEPTH_#{depth.upcase}")
assert_equal(depth_value, Svn::Core::Depth.from_string(depth))
assert_equal(depth, Svn::Core::Depth.to_string(depth_value))
end
end
def test_depth_input
depth_infinity = Svn::Core::DEPTH_INFINITY
assert_equal("infinity", Svn::Core::Depth.to_string(depth_infinity))
assert_equal("infinity", Svn::Core::Depth.to_string("infinity"))
assert_equal("infinity", Svn::Core::Depth.to_string(:infinity))
assert_equal("unknown", Svn::Core::Depth.to_string("XXX"))
assert_raises(ArgumentError) do
Svn::Core::Depth.to_string([])
end
end
def test_stream_copy
source = "content"
original = StringIO.new(source)
copied = StringIO.new("")
original_stream = Svn::Core::Stream.new(original)
copied_stream = Svn::Core::Stream.new(copied)
original_stream.copy(copied_stream)
copied.rewind
assert_equal("", original.read)
assert_equal(source, copied.read)
original.rewind
copied.string = ""
assert_raises(Svn::Error::Cancelled) do
original_stream.copy(copied_stream) do
raise Svn::Error::Cancelled
end
end
copied.rewind
assert_equal(source, original.read)
assert_equal("", copied.read)
end
def test_mime_type_parse
type_map = {
"html" => "text/html",
"htm" => "text/html",
"png" => "image/png",
}
mime_types_source = <<-EOM
text/html html htm
application/octet-stream
image/png png
EOM
mime_types = Tempfile.new("svn-ruby-mime-type")
mime_types.puts(mime_types_source)
mime_types.close
assert_equal(type_map, Svn::Core::MimeType.parse_file(mime_types.path))
assert_equal(type_map, Svn::Core::MimeType.parse(mime_types_source))
end
def test_mime_type_detect
empty_file = Tempfile.new("svn-ruby-mime-type")
assert_equal(nil, Svn::Core::MimeType.detect(empty_file.path))
binary_file = Tempfile.new("svn-ruby-mime-type")
binary_file.print("\0\1\2")
binary_file.close
assert_equal("application/octet-stream",
Svn::Core::MimeType.detect(binary_file.path))
text_file = Tempfile.new("svn-ruby-mime-type")
text_file.print("abcde")
text_file.close
assert_equal(nil, Svn::Core::MimeType.detect(text_file.path))
end
def test_mime_type_detect_with_type_map
type_map = {
"html" => "text/html",
"htm" => "text/html",
"png" => "image/png",
}
nonexistent_html_file = File.join(@tmp_path, "nonexistent.html")
assert_raises(Svn::Error::BadFilename) do
Svn::Core::MimeType.detect(nonexistent_html_file)
end
assert_equal("text/html",
Svn::Core::MimeType.detect(nonexistent_html_file, type_map))
empty_html_file = File.join(@tmp_path, "empty.html")
FileUtils.touch(empty_html_file)
assert_equal(nil, Svn::Core::MimeType.detect(empty_html_file))
assert_equal("text/html",
Svn::Core::MimeType.detect(empty_html_file, type_map))
empty_htm_file = File.join(@tmp_path, "empty.htm")
FileUtils.touch(empty_htm_file)
assert_equal(nil, Svn::Core::MimeType.detect(empty_htm_file))
assert_equal("text/html",
Svn::Core::MimeType.detect(empty_htm_file, type_map))
dummy_png_file = File.join(@tmp_path, "dummy.png")
File.open(dummy_png_file, "wb") do |png|
png.print("\211PNG\r\n\032\n")
end
assert_equal(nil, Svn::Core::MimeType.detect(dummy_png_file))
assert_equal("image/png",
Svn::Core::MimeType.detect(dummy_png_file, type_map))
empty_png_file = File.join(@tmp_path, "empty.png")
FileUtils.touch(empty_png_file)
assert_equal(nil, Svn::Core::MimeType.detect(empty_png_file))
assert_equal("image/png",
Svn::Core::MimeType.detect(empty_png_file, type_map))
invalid_png_file = File.join(@tmp_path, "invalid.png")
File.open(invalid_png_file, "w") do |png|
png.puts("text")
end
assert_equal(nil, Svn::Core::MimeType.detect(invalid_png_file))
assert_equal("image/png",
Svn::Core::MimeType.detect(invalid_png_file, type_map))
end
def test_prop_categorize
name = "svn:mime-type"
value = "text/plain"
entry_name = "svn:entry:XXX"
entry_value = "XXX"
props = [Svn::Core::Prop.new(name, value),
Svn::Core::Prop.new(entry_name, entry_value)]
assert_equal([
[Svn::Core::Prop.new(entry_name, entry_value)],
[],
[Svn::Core::Prop.new(name, value)],
],
Svn::Core::Property.categorize(props))
props = {name => value, entry_name => entry_value}
assert_equal([
{entry_name => entry_value },
{},
{name => value},
],
Svn::Core::Property.categorize2(props))
end
def test_mergeinfo_parse
assert_equal({}, Svn::Core::MergeInfo.parse(""))
input = "/trunk: 5,7-9,10,11,13,14"
result = Svn::Core::MergeInfo.parse(input)
assert_equal(["/trunk"], result.keys)
assert_equal([[4, 5, true], [6, 11, true], [12, 14, true]],
result["/trunk"].collect {|range| range.to_a})
input = "/trunk: 5*,7-9,10,11,13,14"
result = Svn::Core::MergeInfo.parse(input)
assert_equal(["/trunk"], result.keys)
assert_equal([[4, 5, false], [6, 11, true], [12, 14, true]],
result["/trunk"].collect {|range| range.to_a})
end
def test_mergeinfo_diff
input1 = "/trunk: 5,7-9,10,11,13,14"
input2 = "/trunk: 5,6,7-9,10,11"
info1 = Svn::Core::MergeInfo.parse(input1)
info2 = Svn::Core::MergeInfo.parse(input2)
result = info1.diff(info2)
deleted, added = result
assert_equal(["/trunk"], deleted.keys)
assert_equal(["/trunk"], added.keys)
assert_equal([[12, 14, true]],
deleted["/trunk"].collect {|range| range.to_a})
assert_equal([[5, 6, true]],
added["/trunk"].collect {|range| range.to_a})
end
def test_mergeinfo_merge
info = Svn::Core::MergeInfo.parse("/trunk: 5,7-9")
( run in 0.943 second using v1.01-cache-2.11-cpan-df04353d9ac )