Module: StringExt::Etest

Defined in:
lib/vex/base/string/string_ext.rb

Instance Method Summary collapse

Instance Method Details

#test_constantizeObject


144
145
146
147
# File 'lib/vex/base/string/string_ext.rb', line 144

def test_constantize
  assert_equal String, "String".constantize?
  assert_equal nil, "I::Dont::Know::This".constantize?
end

#test_downcaseObject


149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/vex/base/string/string_ext.rb', line 149

def test_downcase
  assert_equal true, "expected".downcase?
  assert_equal false, "Expected".downcase?
  assert_equal false, "EXPECTED".downcase?

  assert_equal false, "expected".upcase?
  assert_equal false, "Expected".upcase?
  assert_equal true, "EXPECTED".upcase?

  assert_equal true, "".upcase?
  assert_equal true, "".downcase?
end

#test_truncateObject

truncate :length => 30, :omission => “…”


114
115
116
117
118
119
120
# File 'lib/vex/base/string/string_ext.rb', line 114

def test_truncate
  assert_equal("", "".truncate)
  assert_equal("123456", "123456".truncate)
  assert_equal("123…", "1234567".truncate(:length => 6))
  assert_equal("123…", "1234567".truncate(6))
  assert_equal("12345~", "1234567".truncate(6, "~"))
end

#test_truncate!Object


122
123
124
125
126
127
128
129
130
# File 'lib/vex/base/string/string_ext.rb', line 122

def test_truncate!
  s = "1234567"

  assert_equal "123…", s.truncate(6)
  assert_equal "1234567", s

  assert_equal "123…", s.truncate!(6)
  assert_equal "123…", s
end

#test_unhtmlObject


106
107
108
109
110
111
# File 'lib/vex/base/string/string_ext.rb', line 106

def test_unhtml
  assert_equal("", "".unhtml)
  assert_equal("hjghjg", "<p>hjghjg</p>".unhtml)
  assert_equal("&auml", "&auml".unhtml)
  assert_equal("ä", "&auml;".unhtml)
end

#test_uriObject


138
139
140
141
142
# File 'lib/vex/base/string/string_ext.rb', line 138

def test_uri
  assert_equal true, "http://".uri?
  assert_equal false, "//".uri?
  assert_equal false, "c:\\x\\y".uri?
end

#test_word_wrapObject


132
133
134
135
136
# File 'lib/vex/base/string/string_ext.rb', line 132

def test_word_wrap
  assert_equal "abcdef\nghijkl",  "abcdef ghijkl".word_wrap(8)
  assert_equal "abc def\nghijkl", "abc def ghijkl".word_wrap(8)
  assert_equal "abcdefghijkl",    "abcdefghijkl".word_wrap(8)
end