require 'test/unit' require 'eymiha/url' class TC_url_normalizer < Test::Unit::TestCase include Eymiha def test_absolute_file_path UrlNormalizer.using_pc_filesystem = true # pc tests assert( UrlNormalizer.absolute_file_path?("c:/foo/bar")) assert(! UrlNormalizer.absolute_file_path?("c:bar")) assert(! UrlNormalizer.absolute_file_path?("/foo/bar")) assert(! UrlNormalizer.absolute_file_path?("bar")) UrlNormalizer.using_pc_filesystem = false # non-pc-tests assert(! UrlNormalizer.absolute_file_path?("c:/foo/bar")) assert(! UrlNormalizer.absolute_file_path?("c:bar")) assert( UrlNormalizer.absolute_file_path?("/foo/bar")) assert(! UrlNormalizer.absolute_file_path?("bar")) end def test_valid_relative_base UrlNormalizer.using_pc_filesystem = true # pc tests assert( UrlNormalizer.valid_relative_base?("c:/foo/")) assert(! UrlNormalizer.valid_relative_base?("/foo/")) assert(! UrlNormalizer.valid_relative_base?("c:/foo")) assert(! UrlNormalizer.valid_relative_base?("/foo")) assert( UrlNormalizer.valid_relative_base?("c:/")) assert(! UrlNormalizer.valid_relative_base?("/")) UrlNormalizer.using_pc_filesystem = false # non-pc-tests assert(! UrlNormalizer.valid_relative_base?("c:/foo/")) assert( UrlNormalizer.valid_relative_base?("/foo/")) assert(! UrlNormalizer.valid_relative_base?("c:/foo")) assert(! UrlNormalizer.valid_relative_base?("/foo")) assert(! UrlNormalizer.valid_relative_base?("c:/")) assert( UrlNormalizer.valid_relative_base?("/")) end def test_file_url UrlNormalizer.using_pc_filesystem = true # pc tests assert( UrlNormalizer.file_url?("file://foo/bar")) assert( UrlNormalizer.file_url?("/foo/bar")) assert( UrlNormalizer.file_url?("c:foo")) assert( UrlNormalizer.file_url?("foo")) assert(! UrlNormalizer.file_url?("bump:mumble")) UrlNormalizer.using_pc_filesystem = false # non-pc-tests assert( UrlNormalizer.file_url?("file://foo/bar")) assert( UrlNormalizer.file_url?("/foo/bar")) assert(! UrlNormalizer.file_url?("c:foo")) assert( UrlNormalizer.file_url?("foo")) assert(! UrlNormalizer.file_url?("bump:mumble")) end def test_normalize urlNormalizer = UrlNormalizer.new UrlNormalizer.using_pc_filesystem = true # pc tests urlNormalizer.relative_base = "c:/foo/" assert(urlNormalizer.normalize("file://c:/foo/bar") == "file://c:/foo/bar") assert(urlNormalizer.normalize("c:/foo/bar") == "file://c:/foo/bar") assert(urlNormalizer.normalize("file://bar") == "file://c:/foo/bar") assert(urlNormalizer.normalize("bar") == "file://c:/foo/bar") assert(urlNormalizer.normalize("bump:mumble") == "bump:mumble") UrlNormalizer.using_pc_filesystem = false # non-pc-tests urlNormalizer.relative_base = "/foo/" assert(urlNormalizer.normalize("file:///foo/bar") == "file:///foo/bar") assert(urlNormalizer.normalize("/foo/bar") == "file:///foo/bar") assert(urlNormalizer.normalize("file://bar") == "file:///foo/bar") assert(urlNormalizer.normalize("bar") == "file:///foo/bar") assert(urlNormalizer.normalize("bump:mumble") == "bump:mumble") end def test_normalize_file urlNormalizer = UrlNormalizer.new UrlNormalizer.using_pc_filesystem = true # pc tests urlNormalizer.relative_base = "c:/foo/" assert(urlNormalizer.normalize_file("file://c:/foo/bar") == "file://c:/foo/bar") assert(urlNormalizer.normalize_file("c:/foo/bar") == "file://c:/foo/bar") assert(urlNormalizer.normalize_file("file://bar") == "file://c:/foo/bar") assert(urlNormalizer.normalize_file("bar") == "file://c:/foo/bar") UrlNormalizer.using_pc_filesystem = false # non-pc-tests urlNormalizer.relative_base = "/foo/" assert(urlNormalizer.normalize_file("file:///foo/bar") == "file:///foo/bar") assert(urlNormalizer.normalize_file("/foo/bar") == "file:///foo/bar") assert(urlNormalizer.normalize_file("file://bar") == "file:///foo/bar") assert(urlNormalizer.normalize_file("bar") == "file:///foo/bar") end def test_normalize_file_path urlNormalizer = UrlNormalizer.new assert_raise(UrlException) { urlNormalizer.normalize_file_path("bar") } UrlNormalizer.using_pc_filesystem = true # pc tests urlNormalizer.relative_base = "c:/foo/" assert(urlNormalizer.normalize_file_path("c:/foo/bar") == "c:/foo/bar") assert(urlNormalizer.normalize_file_path("bar") == "c:/foo/bar") UrlNormalizer.using_pc_filesystem = false # non-pc-tests urlNormalizer.relative_base = "/foo/" assert(urlNormalizer.normalize_file_path("/foo/bar") == "/foo/bar") assert(urlNormalizer.normalize_file_path("bar") == "/foo/bar") end def test_relative_base assert_raise(UrlException) { UrlNormalizer.relative_base = ""} urlNormalizer = UrlNormalizer.new assert_raise(UrlException) { urlNormalizer.relative_base = ""} end end # just for testing... class Eymiha::UrlNormalizer def self.using_pc_filesystem=(using_pc_filesystem) @@using_pc_filesystem = using_pc_filesystem end end