2008-09-18 04:57:33 -04:00
|
|
|
|
# -*- coding: cp932 -*-
|
2015-12-16 00:07:31 -05:00
|
|
|
|
# frozen_string_literal: false
|
2015-12-03 01:38:01 -05:00
|
|
|
|
# This test is in a different file than TestUnicodeEscapes
|
2007-11-07 17:55:27 -05:00
|
|
|
|
# So that we can have a different coding comment above
|
|
|
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
|
|
class TestMixedUnicodeEscape < Test::Unit::TestCase
|
|
|
|
|
def test_basic
|
|
|
|
|
# Unicode escapes do work in an sjis encoded file, but only
|
|
|
|
|
# if they don't contain other multi-byte chars
|
|
|
|
|
assert_equal("A", "\u0041")
|
|
|
|
|
# 8-bit character escapes are okay.
|
|
|
|
|
assert_equal("B\xFF", "\u0042\xFF")
|
|
|
|
|
|
2018-01-15 20:43:25 -05:00
|
|
|
|
# sjis mb chars mixed with Unicode should not work
|
2007-11-07 17:55:27 -05:00
|
|
|
|
assert_raise(SyntaxError) { eval %q("<22><>\u1234")}
|
|
|
|
|
assert_raise(SyntaxError) { eval %q("\u{1234}<7D><>")}
|
|
|
|
|
|
2018-01-15 20:43:25 -05:00
|
|
|
|
# also should not work for Regexp
|
|
|
|
|
assert_raise(SyntaxError) { eval %q(/#{"\u1234"}#{"<22><>"}/)}
|
|
|
|
|
assert_raise(RegexpError) { eval %q(/\u{1234}#{nil}<7D><>/)}
|
|
|
|
|
assert_raise(RegexpError) { eval %q(/<2F><>#{nil}\u1234/)}
|
|
|
|
|
|
2007-11-07 17:55:27 -05:00
|
|
|
|
# String interpolation turns into an expression and we get
|
|
|
|
|
# a different kind of error, but we still can't mix these
|
2008-09-18 04:57:33 -04:00
|
|
|
|
assert_raise(Encoding::CompatibilityError) { eval %q("\u{1234}#{nil}<7D><>")}
|
|
|
|
|
assert_raise(Encoding::CompatibilityError) { eval %q("<22><>#{nil}\u1234")}
|
2007-11-07 17:55:27 -05:00
|
|
|
|
end
|
|
|
|
|
end
|