Skip to content
Browse files

Fix rule 5 of encoding compatibility

  • Loading branch information...
1 parent 361c7d9 commit 407ae311d0daa220e010dec69f28987b15f5fbd8 @candlerb candlerb committed Aug 6, 2009
Showing with 11 additions and 5 deletions.
  1. +11 −5 string19.rb
View
16 string19.rb
@@ -563,19 +563,25 @@ def test_string19
[a.encoding, b.encoding, Encoding.compatible?(a, b)]
# 5. If one object is a String which contains only 7-bit ASCII characters
-# (ascii_only?), then the objects are compatible and the result has the
+# (ascii_only?), and the other is an object with an ASCII-compatible
+# encoding, then the objects are compatible and the result has the
# encoding of the other object.
- a = "hello"
- b = "\xff".force_encoding "ISO-8859-1"
+ a = "hello" # ascii_only
+ b = "\xff".force_encoding "ISO-8859-1" # ascii_compat encoding
is [Encoding::UTF_8, Encoding::ISO_8859_1, Encoding::ISO_8859_1],
[a.encoding, b.encoding, Encoding.compatible?(a,b)]
- a = "groß"
- b = "world".force_encoding "ISO-8859-1"
+ a = "groß" # ascii_compat encoding
+ b = "world".force_encoding "ISO-8859-1" # ascii_only
is [Encoding::UTF_8, Encoding::ISO_8859_1, Encoding::UTF_8],
[a.encoding, b.encoding, Encoding.compatible?(a,b)]
+ a = "hello" # ascii_only
+ b = "\xff\xff".force_encoding("UTF-16BE") # not ascii_compat
+ is nil,
+ Encoding.compatible?(a, b)
+
# If *both* are strings containing only 7-bit ASCII characters, then the
# result has the encoding of the first.

0 comments on commit 407ae31

Please sign in to comment.
Something went wrong with that request. Please try again.