aboutsummaryrefslogtreecommitdiffstats
path: root/community/crystal/disable-specs-using-GB2312-encoding.patch
blob: 74d244cca8595571361c3a3fca6579fca56c2639 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
From 774c93390cfa5af0675b398b308f90cd692b4af6 Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Mon, 26 Mar 2018 02:20:06 +0200
Subject: [PATCH] Disable specs using GB2312 encoding on musl

Musl libc does not support GB2312 encoding.

Fixes #3976

Upstream-Issue: https://github.com/crystal-lang/crystal/pull/5867
---
 spec/std/io/buffered_spec.cr |  19 ++++---
 spec/std/io/io_spec.cr       | 133 +++++++++++++++++++++++--------------------
 spec/std/string_spec.cr      |  41 ++++++-------
 3 files changed, 104 insertions(+), 89 deletions(-)

diff --git a/spec/std/io/buffered_spec.cr b/spec/std/io/buffered_spec.cr
index 1e4d4a473f..6e34c994ea 100644
--- a/spec/std/io/buffered_spec.cr
+++ b/spec/std/io/buffered_spec.cr
@@ -374,15 +374,18 @@ describe "IO::Buffered" do
         end
       end
 
-      it "gets big GB2312 string" do
-        str = ("你好我是人\n" * 1000).encode("GB2312")
-        base_io = IO::Memory.new(str)
-        io = BufferedWrapper.new(base_io)
-        io.set_encoding("GB2312")
-        1000.times do
-          io.gets(chomp: false).should eq("你好我是人\n")
+      # Musl does not support GB2312 encoding.
+      {% unless flag?(:musl) %}
+        it "gets big GB2312 string" do
+          str = ("你好我是人\n" * 1000).encode("GB2312")
+          base_io = IO::Memory.new(str)
+          io = BufferedWrapper.new(base_io)
+          io.set_encoding("GB2312")
+          1000.times do
+            io.gets(chomp: false).should eq("你好我是人\n")
+          end
         end
-      end
+      {% end %}
 
       it "reads char" do
         str = "x\nHello world" + ("1234567890" * 1000)
diff --git a/spec/std/io/io_spec.cr b/spec/std/io/io_spec.cr
index 01e829c800..946bfa70ac 100644
--- a/spec/std/io/io_spec.cr
+++ b/spec/std/io/io_spec.cr
@@ -550,16 +550,19 @@ describe IO do
         end
       end
 
-      it "gets big GB2312 string" do
-        2.times do
-          str = ("你好我是人\n" * 1000).encode("GB2312")
-          io = SimpleIOMemory.new(str)
-          io.set_encoding("GB2312")
-          1000.times do
-            io.gets.should eq("你好我是人")
+      # Musl does not support GB2312 encoding.
+      {% unless flag?(:musl) %}
+        it "gets big GB2312 string" do
+          2.times do
+            str = ("你好我是人\n" * 1000).encode("GB2312")
+            io = SimpleIOMemory.new(str)
+            io.set_encoding("GB2312")
+            1000.times do
+              io.gets.should eq("你好我是人")
+            end
           end
         end
-      end
+      {% end %}
 
       it "does gets on unicode with char and limit without off-by-one" do
         io = SimpleIOMemory.new("test\nabc".encode("UCS-2LE"))
@@ -635,51 +638,54 @@ describe IO do
         io.read_utf8_byte.should be_nil
       end
 
-      it "reads utf8" do
-        io = IO::Memory.new("你".encode("GB2312"))
-        io.set_encoding("GB2312")
+      # Musl does not support GB2312 encoding.
+      {% unless flag?(:musl) %}
+        it "reads utf8" do
+          io = IO::Memory.new("你".encode("GB2312"))
+          io.set_encoding("GB2312")
 
-        buffer = uninitialized UInt8[1024]
-        bytes_read = io.read_utf8(buffer.to_slice) # => 3
-        bytes_read.should eq(3)
-        buffer.to_slice[0, bytes_read].to_a.should eq("你".bytes)
-      end
+          buffer = uninitialized UInt8[1024]
+          bytes_read = io.read_utf8(buffer.to_slice) # => 3
+          bytes_read.should eq(3)
+          buffer.to_slice[0, bytes_read].to_a.should eq("你".bytes)
+        end
 
-      it "raises on incomplete byte sequence" do
-        io = SimpleIOMemory.new("好".byte_slice(0, 1))
-        io.set_encoding("GB2312")
-        expect_raises ArgumentError, "Incomplete multibyte sequence" do
-          io.read_char
+        it "raises on incomplete byte sequence" do
+          io = SimpleIOMemory.new("好".byte_slice(0, 1))
+          io.set_encoding("GB2312")
+          expect_raises ArgumentError, "Incomplete multibyte sequence" do
+            io.read_char
+          end
         end
-      end
 
-      it "says invalid byte sequence" do
-        io = SimpleIOMemory.new(Slice.new(1, 140_u8))
-        io.set_encoding("GB2312")
-        expect_raises ArgumentError, "Invalid multibyte sequence" do
-          io.read_char
+        it "says invalid byte sequence" do
+          io = SimpleIOMemory.new(Slice.new(1, 140_u8))
+          io.set_encoding("GB2312")
+          expect_raises ArgumentError, "Invalid multibyte sequence" do
+            io.read_char
+          end
         end
-      end
 
-      it "skips invalid byte sequences" do
-        string = String.build do |str|
-          str.write "好".encode("GB2312")
-          str.write_byte 140_u8
-          str.write "是".encode("GB2312")
+        it "skips invalid byte sequences" do
+          string = String.build do |str|
+            str.write "好".encode("GB2312")
+            str.write_byte 140_u8
+            str.write "是".encode("GB2312")
+          end
+          io = SimpleIOMemory.new(string)
+          io.set_encoding("GB2312", invalid: :skip)
+          io.read_char.should eq('好')
+          io.read_char.should eq('是')
+          io.read_char.should be_nil
         end
-        io = SimpleIOMemory.new(string)
-        io.set_encoding("GB2312", invalid: :skip)
-        io.read_char.should eq('好')
-        io.read_char.should eq('是')
-        io.read_char.should be_nil
-      end
 
-      it "says invalid 'invalid' option" do
-        io = SimpleIOMemory.new
-        expect_raises ArgumentError, "Valid values for `invalid` option are `nil` and `:skip`, not :foo" do
-          io.set_encoding("GB2312", invalid: :foo)
+        it "says invalid 'invalid' option" do
+          io = SimpleIOMemory.new
+          expect_raises ArgumentError, "Valid values for `invalid` option are `nil` and `:skip`, not :foo" do
+            io.set_encoding("GB2312", invalid: :foo)
+          end
         end
-      end
+      {% end %}
 
       it "says invalid encoding" do
         io = SimpleIOMemory.new("foo")
@@ -803,28 +809,31 @@ describe IO do
         slice.should eq("hi-123-45.67".encode("UCS-2LE"))
       end
 
-      it "raises on invalid byte sequence" do
-        io = SimpleIOMemory.new
-        io.set_encoding("GB2312")
-        expect_raises ArgumentError, "Invalid multibyte sequence" do
-          io.print "ñ"
+      # Musl does not support GB2312 encoding.
+      {% unless flag?(:musl) %}
+        it "raises on invalid byte sequence" do
+          io = SimpleIOMemory.new
+          io.set_encoding("GB2312")
+          expect_raises ArgumentError, "Invalid multibyte sequence" do
+            io.print "ñ"
+          end
         end
-      end
 
-      it "skips on invalid byte sequence" do
-        io = SimpleIOMemory.new
-        io.set_encoding("GB2312", invalid: :skip)
-        io.print "ñ"
-        io.print "foo"
-      end
+        it "skips on invalid byte sequence" do
+          io = SimpleIOMemory.new
+          io.set_encoding("GB2312", invalid: :skip)
+          io.print "ñ"
+          io.print "foo"
+        end
 
-      it "raises on incomplete byte sequence" do
-        io = SimpleIOMemory.new
-        io.set_encoding("GB2312")
-        expect_raises ArgumentError, "Incomplete multibyte sequence" do
-          io.print "好".byte_slice(0, 1)
+        it "raises on incomplete byte sequence" do
+          io = SimpleIOMemory.new
+          io.set_encoding("GB2312")
+          expect_raises ArgumentError, "Incomplete multibyte sequence" do
+            io.print "好".byte_slice(0, 1)
+          end
         end
-      end
+      {% end %}
 
       it "says invalid encoding" do
         io = SimpleIOMemory.new
diff --git a/spec/std/string_spec.cr b/spec/std/string_spec.cr
index 6fbdebc7d0..761398fb8f 100644
--- a/spec/std/string_spec.cr
+++ b/spec/std/string_spec.cr
@@ -2285,35 +2285,38 @@ describe "String" do
       end
     end
 
-    it "raises if illegal byte sequence" do
-      expect_raises ArgumentError, "Invalid multibyte sequence" do
-        "ñ".encode("GB2312")
+    # Musl does not support GB2312 encoding.
+    {% unless flag?(:musl) %}
+      it "raises if illegal byte sequence" do
+        expect_raises ArgumentError, "Invalid multibyte sequence" do
+          "ñ".encode("GB2312")
+        end
       end
-    end
 
-    it "doesn't raise on invalid byte sequence" do
-      "好ñ是".encode("GB2312", invalid: :skip).to_a.should eq([186, 195, 202, 199])
-    end
+      it "doesn't raise on invalid byte sequence" do
+        "好ñ是".encode("GB2312", invalid: :skip).to_a.should eq([186, 195, 202, 199])
+      end
 
-    it "raises if incomplete byte sequence" do
-      expect_raises ArgumentError, "Incomplete multibyte sequence" do
-        "好".byte_slice(0, 1).encode("GB2312")
+      it "raises if incomplete byte sequence" do
+        expect_raises ArgumentError, "Incomplete multibyte sequence" do
+          "好".byte_slice(0, 1).encode("GB2312")
+        end
       end
-    end
 
-    it "doesn't raise if incomplete byte sequence" do
-      ("好".byte_slice(0, 1) + "是").encode("GB2312", invalid: :skip).to_a.should eq([202, 199])
-    end
+      it "doesn't raise if incomplete byte sequence" do
+        ("好".byte_slice(0, 1) + "是").encode("GB2312", invalid: :skip).to_a.should eq([202, 199])
+      end
+
+      it "decodes with skip" do
+        bytes = Bytes[186, 195, 140, 202, 199]
+        String.new(bytes, "GB2312", invalid: :skip).should eq("好是")
+      end
+    {% end %}
 
     it "decodes" do
       bytes = "Hello".encode("UTF-16LE")
       String.new(bytes, "UTF-16LE").should eq("Hello")
     end
-
-    it "decodes with skip" do
-      bytes = Bytes[186, 195, 140, 202, 199]
-      String.new(bytes, "GB2312", invalid: :skip).should eq("好是")
-    end
   end
 
   it "inserts" do