|
43 | 43 | Regexp.union("\u00A9".encode("ISO-8859-1"), "a".encode("UTF-8")).encoding.should == Encoding::ISO_8859_1
|
44 | 44 | end
|
45 | 45 |
|
| 46 | + it "returns ASCII-8BIT if the regexp encodings are ASCII-8BIT and at least one has non-ASCII characters" do |
| 47 | + us_ascii_implicit, us_ascii_explicit, binary = /abc/, /[\x00-\x7f]/n, /[\x80-\xBF]/n |
| 48 | + us_ascii_implicit.encoding.should == Encoding::US_ASCII |
| 49 | + us_ascii_explicit.encoding.should == Encoding::US_ASCII |
| 50 | + binary.encoding.should == Encoding::BINARY |
| 51 | + |
| 52 | + Regexp.union(us_ascii_implicit, us_ascii_explicit, binary).encoding.should == Encoding::BINARY |
| 53 | + Regexp.union(us_ascii_implicit, binary, us_ascii_explicit).encoding.should == Encoding::BINARY |
| 54 | + Regexp.union(us_ascii_explicit, us_ascii_implicit, binary).encoding.should == Encoding::BINARY |
| 55 | + Regexp.union(us_ascii_explicit, binary, us_ascii_implicit).encoding.should == Encoding::BINARY |
| 56 | + Regexp.union(binary, us_ascii_implicit, us_ascii_explicit).encoding.should == Encoding::BINARY |
| 57 | + Regexp.union(binary, us_ascii_explicit, us_ascii_implicit).encoding.should == Encoding::BINARY |
| 58 | + end |
| 59 | + |
| 60 | + it "return US-ASCII if all patterns are ASCII-only" do |
| 61 | + Regexp.union(/abc/e, /def/e).encoding.should == Encoding::US_ASCII |
| 62 | + Regexp.union(/abc/n, /def/n).encoding.should == Encoding::US_ASCII |
| 63 | + Regexp.union(/abc/s, /def/s).encoding.should == Encoding::US_ASCII |
| 64 | + Regexp.union(/abc/u, /def/u).encoding.should == Encoding::US_ASCII |
| 65 | + end |
| 66 | + |
46 | 67 | it "returns a Regexp with UTF-8 if one part is UTF-8" do
|
47 | 68 | Regexp.union(/probl[éeè]me/i, /help/i).encoding.should == Encoding::UTF_8
|
48 | 69 | end
|
|
54 | 75 | it "raises ArgumentError if the arguments include conflicting ASCII-incompatible Strings" do
|
55 | 76 | -> {
|
56 | 77 | Regexp.union("a".encode("UTF-16LE"), "b".encode("UTF-16BE"))
|
57 |
| - }.should raise_error(ArgumentError) |
| 78 | + }.should raise_error(ArgumentError, 'incompatible encodings: UTF-16LE and UTF-16BE') |
58 | 79 | end
|
59 | 80 |
|
60 | 81 | it "raises ArgumentError if the arguments include conflicting ASCII-incompatible Regexps" do
|
61 | 82 | -> {
|
62 | 83 | Regexp.union(Regexp.new("a".encode("UTF-16LE")),
|
63 | 84 | Regexp.new("b".encode("UTF-16BE")))
|
64 |
| - }.should raise_error(ArgumentError) |
| 85 | + }.should raise_error(ArgumentError, 'incompatible encodings: UTF-16LE and UTF-16BE') |
65 | 86 | end
|
66 | 87 |
|
67 | 88 | it "raises ArgumentError if the arguments include conflicting fixed encoding Regexps" do
|
68 | 89 | -> {
|
69 | 90 | Regexp.union(Regexp.new("a".encode("UTF-8"), Regexp::FIXEDENCODING),
|
70 | 91 | Regexp.new("b".encode("US-ASCII"), Regexp::FIXEDENCODING))
|
71 |
| - }.should raise_error(ArgumentError) |
| 92 | + }.should raise_error(ArgumentError, 'incompatible encodings: UTF-8 and US-ASCII') |
72 | 93 | end
|
73 | 94 |
|
74 | 95 | it "raises ArgumentError if the arguments include a fixed encoding Regexp and a String containing non-ASCII-compatible characters in a different encoding" do
|
75 | 96 | -> {
|
76 | 97 | Regexp.union(Regexp.new("a".encode("UTF-8"), Regexp::FIXEDENCODING),
|
77 | 98 | "\u00A9".encode("ISO-8859-1"))
|
78 |
| - }.should raise_error(ArgumentError) |
| 99 | + }.should raise_error(ArgumentError, 'incompatible encodings: UTF-8 and ISO-8859-1') |
79 | 100 | end
|
80 | 101 |
|
81 | 102 | it "raises ArgumentError if the arguments include a String containing non-ASCII-compatible characters and a fixed encoding Regexp in a different encoding" do
|
82 | 103 | -> {
|
83 | 104 | Regexp.union("\u00A9".encode("ISO-8859-1"),
|
84 | 105 | Regexp.new("a".encode("UTF-8"), Regexp::FIXEDENCODING))
|
85 |
| - }.should raise_error(ArgumentError) |
| 106 | + }.should raise_error(ArgumentError, 'incompatible encodings: ISO-8859-1 and UTF-8') |
86 | 107 | end
|
87 | 108 |
|
88 | 109 | it "raises ArgumentError if the arguments include an ASCII-incompatible String and an ASCII-only String" do
|
89 | 110 | -> {
|
90 | 111 | Regexp.union("a".encode("UTF-16LE"), "b".encode("UTF-8"))
|
91 |
| - }.should raise_error(ArgumentError) |
| 112 | + }.should raise_error(ArgumentError, /ASCII incompatible encoding: UTF-16LE|incompatible encodings: UTF-16LE and US-ASCII/) |
92 | 113 | end
|
93 | 114 |
|
94 | 115 | it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and an ASCII-only String" do
|
95 | 116 | -> {
|
96 | 117 | Regexp.union(Regexp.new("a".encode("UTF-16LE")), "b".encode("UTF-8"))
|
97 |
| - }.should raise_error(ArgumentError) |
| 118 | + }.should raise_error(ArgumentError, /ASCII incompatible encoding: UTF-16LE|incompatible encodings: UTF-16LE and US-ASCII/) |
98 | 119 | end
|
99 | 120 |
|
100 | 121 | it "raises ArgumentError if the arguments include an ASCII-incompatible String and an ASCII-only Regexp" do
|
101 | 122 | -> {
|
102 | 123 | Regexp.union("a".encode("UTF-16LE"), Regexp.new("b".encode("UTF-8")))
|
103 |
| - }.should raise_error(ArgumentError) |
| 124 | + }.should raise_error(ArgumentError, /ASCII incompatible encoding: UTF-16LE|incompatible encodings: UTF-16LE and US-ASCII/) |
104 | 125 | end
|
105 | 126 |
|
106 | 127 | it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and an ASCII-only Regexp" do
|
107 | 128 | -> {
|
108 | 129 | Regexp.union(Regexp.new("a".encode("UTF-16LE")), Regexp.new("b".encode("UTF-8")))
|
109 |
| - }.should raise_error(ArgumentError) |
| 130 | + }.should raise_error(ArgumentError, /ASCII incompatible encoding: UTF-16LE|incompatible encodings: UTF-16LE and US-ASCII/) |
110 | 131 | end
|
111 | 132 |
|
112 | 133 | it "raises ArgumentError if the arguments include an ASCII-incompatible String and a String containing non-ASCII-compatible characters in a different encoding" do
|
113 | 134 | -> {
|
114 | 135 | Regexp.union("a".encode("UTF-16LE"), "\u00A9".encode("ISO-8859-1"))
|
115 |
| - }.should raise_error(ArgumentError) |
| 136 | + }.should raise_error(ArgumentError, 'incompatible encodings: UTF-16LE and ISO-8859-1') |
116 | 137 | end
|
117 | 138 |
|
118 | 139 | it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and a String containing non-ASCII-compatible characters in a different encoding" do
|
119 | 140 | -> {
|
120 | 141 | Regexp.union(Regexp.new("a".encode("UTF-16LE")), "\u00A9".encode("ISO-8859-1"))
|
121 |
| - }.should raise_error(ArgumentError) |
| 142 | + }.should raise_error(ArgumentError, 'incompatible encodings: UTF-16LE and ISO-8859-1') |
122 | 143 | end
|
123 | 144 |
|
124 | 145 | it "raises ArgumentError if the arguments include an ASCII-incompatible String and a Regexp containing non-ASCII-compatible characters in a different encoding" do
|
125 | 146 | -> {
|
126 | 147 | Regexp.union("a".encode("UTF-16LE"), Regexp.new("\u00A9".encode("ISO-8859-1")))
|
127 |
| - }.should raise_error(ArgumentError) |
| 148 | + }.should raise_error(ArgumentError, 'incompatible encodings: UTF-16LE and ISO-8859-1') |
128 | 149 | end
|
129 | 150 |
|
130 | 151 | it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and a Regexp containing non-ASCII-compatible characters in a different encoding" do
|
131 | 152 | -> {
|
132 | 153 | Regexp.union(Regexp.new("a".encode("UTF-16LE")), Regexp.new("\u00A9".encode("ISO-8859-1")))
|
133 |
| - }.should raise_error(ArgumentError) |
| 154 | + }.should raise_error(ArgumentError, 'incompatible encodings: UTF-16LE and ISO-8859-1') |
134 | 155 | end
|
135 | 156 |
|
136 | 157 | it "uses to_str to convert arguments (if not Regexp)" do
|
|
154 | 175 | not_supported_on :opal do
|
155 | 176 | Regexp.union([/dogs/, /cats/i]).should == /(?-mix:dogs)|(?i-mx:cats)/
|
156 | 177 | end
|
157 |
| - ->{Regexp.union(["skiing", "sledding"], [/dogs/, /cats/i])}.should raise_error(TypeError) |
| 178 | + -> { |
| 179 | + Regexp.union(["skiing", "sledding"], [/dogs/, /cats/i]) |
| 180 | + }.should raise_error(TypeError, 'no implicit conversion of Array into String') |
158 | 181 | end
|
159 | 182 | end
|
0 commit comments