- $KCODE = 'u'
- require 'test/unit'
- def encode_unicode_codepoints(str)
- str.unpack("U*").map { |b|
- if b >= 128
- "\\u%04x" % b
- else
- b.chr
- end
- }.join
- end
- class RoflTest < Test::Unit::TestCase
- def test_blah
- str = "こんにちは world !"
- assert_equal '\u3053\u3093\u306b\u3061\u306f world \uff01', encode_unicode_codepoints(str)
- end
- end