instiki/vendor/rubyzip-0.5.8/test/stdrubyexttest.rb

53 lines
1.3 KiB
Ruby
Raw Normal View History

2005-01-15 21:26:54 +01:00
#!/usr/bin/env ruby
$VERBOSE = true
2005-04-10 18:55:44 +02:00
$: << "../lib"
2005-01-15 21:26:54 +01:00
2005-04-10 18:55:44 +02:00
require 'test/unit'
2005-01-15 21:26:54 +01:00
require 'zip/stdrubyext'
2005-04-10 18:55:44 +02:00
class ModuleTest < Test::Unit::TestCase
2005-01-15 21:26:54 +01:00
def test_select_map
2005-04-10 18:55:44 +02:00
assert_equal([2, 4, 8, 10], [1, 2, 3, 4, 5].select_map { |e| e == 3 ? nil : 2*e })
2005-01-15 21:26:54 +01:00
end
end
2005-04-10 18:55:44 +02:00
class StringExtensionsTest < Test::Unit::TestCase
2005-01-15 21:26:54 +01:00
def test_starts_with
assert("hello".starts_with(""))
assert("hello".starts_with("h"))
assert("hello".starts_with("he"))
assert(! "hello".starts_with("hello there"))
assert(! "hello".starts_with(" he"))
2005-04-10 18:55:44 +02:00
assert_raise(TypeError, "type mismatch: NilClass given") {
2005-01-15 21:26:54 +01:00
"hello".starts_with(nil)
}
end
def test_ends_with
assert("hello".ends_with("o"))
assert("hello".ends_with("lo"))
assert("hello".ends_with("hello"))
assert(!"howdy".ends_with("o"))
assert(!"howdy".ends_with("oy"))
assert(!"howdy".ends_with("howdy doody"))
assert(!"howdy".ends_with("doody howdy"))
end
def test_ensure_end
2005-04-10 18:55:44 +02:00
assert_equal("hello!", "hello!".ensure_end("!"))
assert_equal("hello!", "hello!".ensure_end("o!"))
assert_equal("hello!", "hello".ensure_end("!"))
assert_equal("hello!", "hel".ensure_end("lo!"))
2005-01-15 21:26:54 +01:00
end
end
# Copyright (C) 2002, 2003 Thomas Sondergaard
# rubyzip is free software; you can redistribute it and/or
# modify it under the terms of the ruby license.