Module: StringExt::Etest

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

Instance Method Summary collapse

Instance Method Details

#test_constantizeObject



149
150
151
152
# File 'lib/vex/base/string/string_ext.rb', line 149

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

#test_downcaseObject



154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/vex/base/string/string_ext.rb', line 154

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 => “…”



119
120
121
122
123
124
125
# File 'lib/vex/base/string/string_ext.rb', line 119

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



127
128
129
130
131
132
133
134
135
# File 'lib/vex/base/string/string_ext.rb', line 127

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



111
112
113
114
115
116
# File 'lib/vex/base/string/string_ext.rb', line 111

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



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

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

#test_word_wrapObject



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

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