Class: TestString

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/innate/test/teststring.rb

Instance Method Summary collapse

Instance Method Details

#test_prefix_to?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/innate/test/teststring.rb', line 21

def test_prefix_to?
  assert_equal 'spud', 's'.prefix_to?('blog', 'roil', 'spud', 'star')
  assert_equal 'star', 'st'.prefix_to?('blog', 'roil', 'spud', 'star')
  assert_nil 'S'.prefix_to?('blog', 'roil', 'spud', 'star')
  assert_nil 'xz'.prefix_to?('blog', 'roil', 'spud', 'star')
end

#test_split_with_separatorObject



34
35
36
37
# File 'lib/innate/test/teststring.rb', line 34

def test_split_with_separator
  assert_equal([[nil, 'hello'], [', ', 'is darrick there'], ['? ', 'no'], ['.', '']],
                'hello, is darrick there? no.'.split_with_separator(/[.,?]\s*/))
end

#test_split_with_separator2Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/innate/test/teststring.rb', line 39

def test_split_with_separator2
  count = 0
  c = [[nil, 'hello'], [', ', 'is darrick there'], ['? ', 'no'], ['.', '']].to_cursor
  'hello, is darrick there? no.'.split_with_separator(/[.,?]\s*/) do |s, text|
    cs, ctext = c.read1next
    assert_equal cs, s
    assert_equal ctext, text
    count += 1
  end
  assert_equal 4, count
end

#test_starts_with?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
# File 'lib/innate/test/teststring.rb', line 6

def test_starts_with?
  assert_nil 'o\'hare'.starts_with?('Mc', 'Mac', 'O\'')
  assert_equal 'O\'', 'O\'hare'.starts_with?('Mc', 'Mac', 'O\'')
  assert_nil 'mcdonald'.starts_with?('Mc', 'Mac', 'O\'')
  assert_equal 'Mc', 'Mcdonald'.starts_with?('Mc', 'Mac', 'O\'')
  assert_nil 'normal'.starts_with?('Mc', 'Mac', 'O\'')
end

#test_starts_with_i?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/innate/test/teststring.rb', line 14

def test_starts_with_i?
  assert_equal 'O\'', 'o\'hare'.starts_with_i?('Mc', 'Mac', 'O\'')
  assert_equal 'O\'', 'O\'hare'.starts_with_i?('Mc', 'Mac', 'O\'')
  assert_equal 'Mc', 'mcdonald'.starts_with_i?('Mc', 'Mac', 'O\'')
  assert_nil 'normal'.starts_with_i?('Mc', 'Mac', 'O\'')
end