-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
fix repeat of test; remove unused variable by use of each_key #9763
fix repeat of test; remove unused variable by use of each_key #9763
Conversation
vipulnsward
commented
Mar 17, 2013
- The loop was unnecessarily repeating itself
- Removed unused variable by use of each_key in place of each
string.each_char do |char| | ||
assert_match %r{^[a-zA-Z']*$}, ActiveSupport::Inflector.transliterate(string) | ||
end | ||
assert_match %r{^[a-zA-Z']*$}, ActiveSupport::Inflector.transliterate(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to get better error messages. The string created by line 20 is:
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽž
In the event of a failure it's nicer to know exactly where it failed rather than "somewhere in there." A few of the characters don't actually decompose down to a letter and a diacritic, so the places where failures are most likely to arise due to refactoring the transliteration code are not intuitive to most people. I would leave this one alone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@norman So instead the test should be taking place on char
variable instead of string
right?
Because even if we are going over the whole string, we are just keeping on doing the same thing for all the characters, if I am not wrong.
ie. we do assert_match %r{^[a-zA-Z']*$}, ActiveSupport::Inflector.transliterate(string)
instead of assert_match %r{^[a-zA-Z']*$}, ActiveSupport::Inflector.transliterate(char)
repeatedly. Or is this intentional too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So instead the test should be taking place on char variable instead of string right?
Ah, yes that's right. I looked right past that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating the PR to reflect this then
@carlosantoniodasilva @norman Fixed/Squashed it. |
Fix repeat of test; remove unused variable by use of each_key
Thanks @Normal @vipulnsward |