Skip to content

Commit 8298bc6

Browse files
aminmansuriandrykonchin
authored andcommitted
Add Time.new specs for strings ending where a colon is expected
Every other error-case string in core/time/new_spec.rb carries a trailing zone suffix, so no example ended at the byte where the parser expects a ':'. That is the one position where the message stops short of the offending byte, and it was unexercised. The gap turned up while investigating jruby/jruby#9623, where these three inputs read past the end of the string instead of raising ArgumentError.
1 parent 8209a75 commit 8298bc6

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎core/time/new_spec.rb‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,23 @@ def obj.to_int; 3; end
570570
}.should.raise(ArgumentError, /missing min part: 00 |can't parse:/)
571571
end
572572

573+
# These strings end exactly at the byte where the parser expects a ':', so
574+
# the message has no offending byte to append. The other error cases here
575+
# all carry a trailing zone, which left that boundary unexercised.
576+
it "raises ArgumentError if the time string ends where a ':' is expected" do
577+
-> {
578+
Time.new("2020-12-25 00:56")
579+
}.should.raise(ArgumentError, /\Amissing sec part: 00:56\z|can't parse:/)
580+
581+
-> {
582+
Time.new("2020-12-25T00:56")
583+
}.should.raise(ArgumentError, /\Amissing sec part: 00:56\z|can't parse:/)
584+
585+
-> {
586+
Time.new("2020-12-25 00")
587+
}.should.raise(ArgumentError, /\Amissing min part: 00\z|can't parse:/)
588+
end
589+
573590
it "raises ArgumentError if the time part is missing" do
574591
-> {
575592
Time.new("2020-12-25")

0 commit comments

Comments
 (0)