1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-25 20:25:28 +03:00
aports/testing/crystal/disable-specs-using-GB2312-encoding.patch
2018-03-26 02:36:13 +02:00

282 lines
9.7 KiB
Diff

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