Skip to content

Commit

Permalink
Fix documentation and add an additional test case for Timezone#=~.
Browse files Browse the repository at this point in the history
  • Loading branch information
philr committed Apr 30, 2019
1 parent 1c5d810 commit 8e4baff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 8 additions & 6 deletions lib/tzinfo/timezone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1119,12 +1119,14 @@ def hash
identifier.hash
end

# @param regex [Regex] a `Regex` to match against the identifier of this
# {Timezone}.
# @return [Integer, nil] `Integer` offset of the match on the identifier,
# otherwise `nil` if there is no match.
def =~(regex)
regex =~ identifier
# Matches `regexp` against the {identifier} of this {Timezone}.
#
# @param regexp [Regexp] a `Regexp` to match against the {identifier} of
# this {Timezone}.
# @return [Integer] the position the match starts, or `nil` if there is no
# match.
def =~(regexp)
regexp =~ identifier
end

# Returns a serialized representation of this {Timezone}. This method is
Expand Down
9 changes: 7 additions & 2 deletions test/tc_timezone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1702,8 +1702,13 @@ def test_hash

define_method("test_=~_operator_matches_against_identifier") do
tz = TestTimezone.new('Europe/London')
assert_equal(0, tz =~ /Europe\/London/)
assert_nil(tz =~ /America\/NewYork/)
assert_equal(0, tz =~ /\AEurope\/London\z/)
assert_equal(6, tz =~ /\/London/)
end

define_method("test_=~_operator_returns_nil_when_regexp_does_not_match") do
tz = TestTimezone.new('Europe/London')
assert_nil(tz =~ /America\/New_York/)
end

def test_marshal_data
Expand Down

0 comments on commit 8e4baff

Please sign in to comment.