File: stdrubyexttest.rb

package info (click to toggle)
libzip-ruby 0.5.6-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 368 kB
  • ctags: 639
  • sloc: ruby: 5,616; makefile: 52
file content (52 lines) | stat: -rwxr-xr-x 1,344 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env ruby

$VERBOSE = true

$: << ".."

require 'rubyunit'
require 'zip/stdrubyext'

class ModuleTest < RUNIT::TestCase

  def test_select_map
    assert_equals([2, 4, 8, 10], [1, 2, 3, 4, 5].select_map { |e| e == 3 ? nil : 2*e })
  end
  
end

class StringExtensionsTest < RUNIT::TestCase

  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"))

    assert_exception(TypeError, "type mismatch: NilClass given") { 
      "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
    assert_equals("hello!", "hello!".ensure_end("!"))
    assert_equals("hello!", "hello!".ensure_end("o!"))
    assert_equals("hello!", "hello".ensure_end("!"))
    assert_equals("hello!", "hel".ensure_end("lo!"))
  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.