OSDN Git Service

ruby-1.9.1-rc1
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / test / ruby / test_mixed_unicode_escapes.rb
1 # -*- coding: cp932 -*-
2 # This test is in a differnt file than TestUnicodeEscapes
3 # So that we can have a different coding comment above
4
5 require 'test/unit'
6
7 class TestMixedUnicodeEscape < Test::Unit::TestCase
8   def test_basic
9     # Unicode escapes do work in an sjis encoded file, but only
10     # if they don't contain other multi-byte chars
11     assert_equal("A", "\u0041")
12     # 8-bit character escapes are okay.
13     assert_equal("B\xFF", "\u0042\xFF")
14
15     # sjis mb chars mixed with Unicode shound not work
16     assert_raise(SyntaxError) { eval %q("é\9d\u1234")}
17     assert_raise(SyntaxError) { eval %q("\u{1234}é\9d")}
18
19     # String interpolation turns into an expression and we get
20     # a different kind of error, but we still can't mix these
21     assert_raise(Encoding::CompatibilityError) { eval %q("\u{1234}#{nil}é\9d")}
22     assert_raise(Encoding::CompatibilityError) { eval %q("é\9d#{nil}\u1234")}
23
24   end
25 end