class TestString

Public Instance Methods

test_escape() click to toggle source
# File vendor/qwik/lib/qwik/util-string.rb, line 157
def test_escape
  # test_escape
  assert_equal('A', 'A'.escape)
  assert_equal("+", ' '.escape)
  assert_equal('%2B', "+".escape)
  assert_equal('%21', "!".escape)
  assert_equal("ABC%82%A0%82%A2%82%A4+%2B%23", "ABCあいう +#".escape)

  # test_unescape
  assert_equal('A', '%41'.unescape)
  assert_equal(' ', "+".unescape)
  assert_equal("!", '%21'.unescape)
  assert_equal("ABCあいう +#", "ABC%82%A0%82%A2%82%A4+%2B%23".unescape)

  # test_escapeHTML
  assert_equal("&lt;", "<".escapeHTML)
  assert_equal("&gt;", ">".escapeHTML)
  assert_equal("&amp;", "&".escapeHTML)
  assert_equal("&lt;a href=&quot;http://e.com/&quot;&gt;e.com&lt;/a&gt;",
               '<a href="http://e.com/">e.com</a>'.escapeHTML)

  # test_unescapeHTML
  assert_equal("<", "&lt;".unescapeHTML)
  assert_equal(">", "&gt;".unescapeHTML)
  assert_equal("&", "&amp;".unescapeHTML)
  assert_equal("<a href='http://e.com/'>e.com</a>",
               "&lt;a href=&quot;http://e.com/&quot;&gt;e.com&lt;/a&gt;".unescapeHTML)
end
test_mb_length() click to toggle source
# File vendor/qwik/lib/qwik/util-string.rb, line 186
def test_mb_length
  str = "日本語文字列"
  assert_equal(6,str.mb_length)

  str = "English"
  assert_equal(7,str.mb_length)
end
test_mb_substring() click to toggle source
# File vendor/qwik/lib/qwik/util-string.rb, line 194
def test_mb_substring
  str = "日本語文字列"
  assert_equal("本語文",str.mb_substring(1,4))

  str = "English"
  assert_equal("ngl",str.mb_substring(1,4))
end
test_string() click to toggle source
# File vendor/qwik/lib/qwik/util-string.rb, line 114
def test_string
  # test_xchomp
  assert_equal '', ''.xchomp
  assert_equal '', "\n".xchomp
  assert_equal '', "\r".xchomp
  assert_equal '', "\r\n".xchomp
  assert_equal "\n", "\n\r".xchomp
  assert_equal 't', 't'.xchomp
  assert_equal 't', "t\r".xchomp
  assert_equal 't', "t\n".xchomp

  # test_chompp
  assert_equal '', "\n\r".chompp
  assert_equal '', "\n\r\n\r".chompp

  # test_normalize_eol
  assert_equal "\n", ''.normalize_eol
  assert_equal "\n", "\n".normalize_eol
  assert_equal "t\n", 't'.normalize_eol
  assert_equal "t\n", "t\n".normalize_eol

  # test_normalize_newline
  assert_equal "\n", "\n".normalize_newline
  assert_equal "\n", "\r".normalize_newline
  assert_equal "\n", "\r\n".normalize_newline
  assert_equal "\n\n", "\n\r".normalize_newline
  assert_equal "\na\n", "\ra\r".normalize_newline
  assert_equal "\na\n", "\r\na\r\n".normalize_newline
  assert_equal "\n\na\n\n", "\n\ra\n\r".normalize_newline

  # test_sub_str
  assert_equal 'a:b', 'a*b'.sub_str('*', ':')

  # test_md5
  assert_instance_of String, 't'.md5
  assert_equal 16, 't'.md5.length
  assert_equal "\343X\357\244\211\365\200b\361\r\3271ked\236", 't'.md5
  assert_instance_of String, 't'.md5hex
  assert_equal 32, 't'.md5hex.length
  assert_equal 'e358efa489f58062f10dd7316b65649e', 't'.md5hex
  assert_equal 'dA==', 't'.base64
end