summaryrefslogtreecommitdiffstats
path: root/test/ruby/test_utf32.rb
blob: f81524f29e884982e331f7556d795ba6837ffd8f (plain)
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
require 'test/unit'

class TestUTF32 < Test::Unit::TestCase
  def encdump(str)
    d = str.dump
    if /\.force_encoding\("[A-Za-z0-9.:_+-]*"\)\z/ =~ d
      d
    else
      "#{d}.force_encoding(#{str.encoding.name.dump})"
    end
  end

  def assert_str_equal(expected, actual, message=nil)
    full_message = build_message(message, <<EOT)
#{encdump expected} expected but not equal to
#{encdump actual}.
EOT
    assert_block(full_message) { expected == actual }
  end

  def test_substr
    assert_str_equal(
      "abcdefgh".force_encoding("utf-32be"),
      "abcdefgh".force_encoding("utf-32be")[0,3])
  end
end