Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 09f90ba06ac7
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2d57f735d923
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jun 12, 2016

  1. Copy the full SHA
    e693ec4 View commit details
  2. Merge pull request #2811 from jhass/char_error

    Improve error messages for invalid values of Char
    jhass authored Jun 12, 2016
    Copy the full SHA
    2d57f73 View commit details
Showing with 9 additions and 3 deletions.
  1. +7 −1 spec/std/char_spec.cr
  2. +2 −2 src/char.cr
8 changes: 7 additions & 1 deletion spec/std/char_spec.cr
Original file line number Diff line number Diff line change
@@ -207,6 +207,12 @@ describe "Char" do
it "does for unicode" do
'青'.bytesize.should eq(3)
end

it "raises on codepoint bigger than 0x10ffff" do
expect_raises InvalidByteSequenceError do
(0x10ffff + 1).chr.bytesize
end
end
end

describe "in_set?" do
@@ -254,7 +260,7 @@ describe "Char" do
end

it "raises on codepoint bigger than 0x10ffff when doing each_byte" do
expect_raises do
expect_raises InvalidByteSequenceError do
(0x10ffff + 1).chr.each_byte { |b| }
end
end
4 changes: 2 additions & 2 deletions src/char.cr
Original file line number Diff line number Diff line change
@@ -513,7 +513,7 @@ struct Char
yield (0x80 | ((c >> 6) & 0x3f)).to_u8
yield (0x80 | (c & 0x3f)).to_u8
else
raise "Invalid char value"
raise InvalidByteSequenceError.new("Invalid char value #{dump}")
end
end

@@ -540,7 +540,7 @@ struct Char
# 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
4
else
raise "Invalid char value"
raise InvalidByteSequenceError.new("Invalid char value #{dump}")
end
end