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

Fixes #16577 - enhance unit detection #3854

Closed
wants to merge 1 commit into from
Closed

Conversation

ares
Copy link
Member

@ares ares commented Sep 16, 2016

No description provided.

test '#to_gb non matching string raises exception with correct message' do
value = 'something that is not matched'
exception = assert_raises(RuntimeError) { value.to_gb }
assert exception.message =~ /^Unknown string/, "wrong exception reason #{exception.to_s}"

Choose a reason for hiding this comment

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

Redundant use of Object#to_s in interpolation.

@@ -140,17 +140,20 @@ def to_translation
end

def to_gb
value, _, unit=self.match(/(\d+(\.\d+)?) ?(([KMGT]i?B?|B))$/i)[1..3]
Copy link
Member Author

Choose a reason for hiding this comment

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

this used to fail, #match return nil if there's no match and we called [1..3] on it

@@ -140,17 +140,20 @@ def to_translation
end

def to_gb
value, _, unit=self.match(/(\d+(\.\d+)?) ?(([KMGT]i?B?|B))$/i)[1..3]
match_data = self.match(/(\d+(\.\d+)?) ?(([KMGT]i?B?|B|Bytes))$/i)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the match start at the start of the string?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to mix refactorings with fix since I thought this should be merged into 1.13 but since it was rejected I can fix existing code.

value, _, unit = match_data[1..3]
else
raise "Unknown string: #{self.inspect}!"
end
case unit.to_sym
Copy link
Member

Choose a reason for hiding this comment

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

we use case insensitive matching, so for example "10gb" will be caught, but there is no :gb symbol - perhaps .lower.to_sym?

Copy link
Member Author

Choose a reason for hiding this comment

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

alright, even though gB is not gb

Copy link
Member

Choose a reason for hiding this comment

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

technically GiB isn't the same as GB either, but we ignore that as well :)

Copy link
Member Author

Choose a reason for hiding this comment

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

right :-)

@ares
Copy link
Member Author

ares commented Sep 19, 2016

thanks @tbrisker, I made changes you requested, could you take another look?

@ares
Copy link
Member Author

ares commented Sep 20, 2016

[test foreman]

@dLobatog
Copy link
Member

[test foreman]

@tbrisker
Copy link
Member

Merged as 0771cec, thanks @ares!

@tbrisker tbrisker closed this Sep 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants