Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting EncodedString specs from #134 #151

Merged
merged 9 commits into from
Jan 23, 2015

Conversation

bf4
Copy link
Contributor

@bf4 bf4 commented Jan 7, 2015

See #134

I need help with the matcher

Also, I decided not to include the new differ specs in here,
to reduce complexity, but am open to adding it.

@bf4 bf4 force-pushed the encoding_specs branch 2 times, most recently from e6e04bc to 601924a Compare January 7, 2015 06:04
#
# Raised by byte <-> char conversions
# RangeError: out of char range
# e.g. the UTF-16LE emoji: 128169.chr
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this too much detail in the comments?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The detail is helpful, actually.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice docs. There's not enough about ruby encodings around the place so this is great.

# and "\x80".encode('UTF-8','ASCII-8BIT', undef: :replace, replace: '<undef>')
# # => '<undef>'
# Encoding::CompatibilityError
# when Enconding.compatbile?(str1, str2) is false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is technically incorrect. as written, it's when nil. I'll revise if everything else is ok.

I was confusing enc.ascii_compatible?

* Returns whether ASCII-compatible or not.
 *
 *   Encoding::UTF_8.ascii_compatible?     #=> true
 *   Encoding::UTF_16BE.ascii_compatible?  #=> false

with rb_enc_check

rb_enc_check(VALUE str1, VALUE str2)
{
    rb_encoding *enc = rb_enc_compatible(str1, str2);
    if (!enc)
    rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",

where enc_compatible is `Encoding.compatible?(str1,str2)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, please fix this. (Good catch!). Also, s/compatbile/compatible/

@myronmarston
Copy link
Member

I opened a PR against your branch that refactors the matcher and does a couple other small changes:

bf4#1

@bf4
Copy link
Contributor Author

bf4 commented Jan 7, 2015

I opened a PR against your branch that refactors the matcher and does a couple other small changes:

oh fun. Will review

@bf4
Copy link
Contributor Author

bf4 commented Jan 8, 2015

Didn't finish addressing comments tonight. Merged and amended last commit in your PR. Will finish and push code 'tomorrow' 💤

@bf4
Copy link
Contributor Author

bf4 commented Jan 9, 2015

Didn't work on it today. Probably won't again till Sunday.

@myronmarston
Copy link
Member

That's fine :).

bf4 and others added 5 commits January 15, 2015 00:29
- Add tests for EncodedString#to_s, #split, #<<
- For each Encoding failure
  - assert the expected failure is raised o a String, but not on an 'EncodedString'
  - assert invalid bytes or unconvertale characters are replaced

Currently one test is failing (pending)
  -  EncodedString#split when the string has an invalid byte sequence
   incorrectly raises an ArgumentError

Use 'expect_identical_string' to avoid running expectation failures
through the differ, which also uses EncodingString
It’s actually not quite the hot spot it says it here.

Encoded strings are only created when an expectation fails
that uses a diffable matcher.  I believe that expectations normally
pass (since people usually try to keep their test suite green
and only have a small number of failing specs at a time), so encoded
strings are not created by every expectation.
These cases are contrasts (as one example raises the
error, but the other does not), so using `and` was
confusing since they don’t do the same thing. `vs`
makes more sense.
This reads better, provides better failure output, and is composable.
@bf4
Copy link
Contributor Author

bf4 commented Jan 15, 2015

Rebased off of current master and force pushed

Add new commits to PR per discussion for easy review, if ok, would like to discuss which concepts in the pr deserve their own commit and how your PR into my PR should appear. (if you don't care, I'm comfortable just doing something).

Also, I looked into windows encodings more and think I'd like to document how to set the default external encoding that the suite expects on posix and windows, see #151 (comment) and #151 (comment).

@bf4
Copy link
Contributor Author

bf4 commented Jan 23, 2015

@myronmarston This is ready for review, when you get the chance. (Also see previous comment).

myronmarston added a commit that referenced this pull request Jan 23, 2015
Extracting EncodedString specs from #134
@myronmarston myronmarston merged commit eb27b60 into rspec:master Jan 23, 2015
@myronmarston
Copy link
Member

Merged. Thanks, @bf4!

@bf4
Copy link
Contributor Author

bf4 commented Jan 23, 2015

🌈 🎆 🐴 💯 yay!

# vs "\x80".encode('UTF-8','ASCII-8BIT', undef: :replace, replace: '<undef>')
# # => '<undef>'
# Encoding::CompatibilityError
# when Enconding.compatbile?(str1, str2) is false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should be Encoding. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prol'y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants