diff options
Diffstat (limited to 'spec/ruby/library/date/shared')
| -rw-r--r-- | spec/ruby/library/date/shared/civil.rb | 16 | ||||
| -rw-r--r-- | spec/ruby/library/date/shared/commercial.rb | 39 | ||||
| -rw-r--r-- | spec/ruby/library/date/shared/jd.rb | 14 | ||||
| -rw-r--r-- | spec/ruby/library/date/shared/new_bang.rb | 14 | ||||
| -rw-r--r-- | spec/ruby/library/date/shared/ordinal.rb | 22 | ||||
| -rw-r--r-- | spec/ruby/library/date/shared/parse.rb | 4 | ||||
| -rw-r--r-- | spec/ruby/library/date/shared/parse_eu.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/library/date/shared/parse_us.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/library/date/shared/valid_civil.rb | 36 | ||||
| -rw-r--r-- | spec/ruby/library/date/shared/valid_commercial.rb | 34 | ||||
| -rw-r--r-- | spec/ruby/library/date/shared/valid_jd.rb | 32 | ||||
| -rw-r--r-- | spec/ruby/library/date/shared/valid_ordinal.rb | 26 |
12 files changed, 18 insertions, 235 deletions
diff --git a/spec/ruby/library/date/shared/civil.rb b/spec/ruby/library/date/shared/civil.rb index bbed4a8866..4499cdf8e9 100644 --- a/spec/ruby/library/date/shared/civil.rb +++ b/spec/ruby/library/date/shared/civil.rb @@ -36,14 +36,14 @@ describe :date_civil, shared: true do end it "doesn't create dates for invalid arguments" do - -> { Date.send(@method, 2000, 13, 31) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2000, 12, 32) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2000, 2, 30) }.should raise_error(ArgumentError) - -> { Date.send(@method, 1900, 2, 29) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2000, 2, 29) }.should_not raise_error(ArgumentError) - - -> { Date.send(@method, 1582, 10, 14) }.should raise_error(ArgumentError) - -> { Date.send(@method, 1582, 10, 15) }.should_not raise_error(ArgumentError) + -> { Date.send(@method, 2000, 13, 31) }.should.raise(ArgumentError) + -> { Date.send(@method, 2000, 12, 32) }.should.raise(ArgumentError) + -> { Date.send(@method, 2000, 2, 30) }.should.raise(ArgumentError) + -> { Date.send(@method, 1900, 2, 29) }.should.raise(ArgumentError) + -> { Date.send(@method, 2000, 2, 29) }.should_not.raise(ArgumentError) + + -> { Date.send(@method, 1582, 10, 14) }.should.raise(ArgumentError) + -> { Date.send(@method, 1582, 10, 15) }.should_not.raise(ArgumentError) end diff --git a/spec/ruby/library/date/shared/commercial.rb b/spec/ruby/library/date/shared/commercial.rb deleted file mode 100644 index 39c9af47b6..0000000000 --- a/spec/ruby/library/date/shared/commercial.rb +++ /dev/null @@ -1,39 +0,0 @@ -describe :date_commercial, shared: true do - it "creates a Date for Julian Day Number day 0 by default" do - d = Date.send(@method) - d.year.should == -4712 - d.month.should == 1 - d.day.should == 1 - end - - it "creates a Date for the monday in the year and week given" do - d = Date.send(@method, 2000, 1) - d.year.should == 2000 - d.month.should == 1 - d.day.should == 3 - d.cwday.should == 1 - end - - it "creates a Date for the correct day given the year, week and day number" do - d = Date.send(@method, 2004, 1, 1) - d.year.should == 2003 - d.month.should == 12 - d.day.should == 29 - d.cwday.should == 1 - d.cweek.should == 1 - d.cwyear.should == 2004 - end - - it "creates only Date objects for valid weeks" do - -> { Date.send(@method, 2004, 53, 1) }.should_not raise_error(ArgumentError) - -> { Date.send(@method, 2004, 53, 0) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2004, 53, 8) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2004, 54, 1) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2004, 0, 1) }.should raise_error(ArgumentError) - - -> { Date.send(@method, 2003, 52, 1) }.should_not raise_error(ArgumentError) - -> { Date.send(@method, 2003, 53, 1) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2003, 52, 0) }.should raise_error(ArgumentError) - -> { Date.send(@method, 2003, 52, 8) }.should raise_error(ArgumentError) - end -end diff --git a/spec/ruby/library/date/shared/jd.rb b/spec/ruby/library/date/shared/jd.rb deleted file mode 100644 index 511557b4f7..0000000000 --- a/spec/ruby/library/date/shared/jd.rb +++ /dev/null @@ -1,14 +0,0 @@ -describe :date_jd, shared: true do - it "constructs a Date object if passed a Julian day" do - Date.send(@method, 2454482).should == Date.civil(2008, 1, 16) - end - - it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed" do - Date.send(@method).should == Date.civil(-4712, 1, 1) - end - - it "constructs a Date object if passed a negative number" do - Date.send(@method, -1).should == Date.civil(-4713, 12, 31) - end - -end diff --git a/spec/ruby/library/date/shared/new_bang.rb b/spec/ruby/library/date/shared/new_bang.rb deleted file mode 100644 index 90f1b432f0..0000000000 --- a/spec/ruby/library/date/shared/new_bang.rb +++ /dev/null @@ -1,14 +0,0 @@ -describe :date_new_bang, shared: true do - - it "returns a new Date object set to Astronomical Julian Day 0 if no arguments passed" do - d = Date.send(@method) - d.ajd.should == 0 - end - - it "accepts astronomical julian day number, offset as a fraction of a day and returns a new Date object" do - d = Date.send(@method, 10, 0.5) - d.ajd.should == 10 - d.jd.should == 11 - end - -end diff --git a/spec/ruby/library/date/shared/ordinal.rb b/spec/ruby/library/date/shared/ordinal.rb deleted file mode 100644 index 4b182d5a25..0000000000 --- a/spec/ruby/library/date/shared/ordinal.rb +++ /dev/null @@ -1,22 +0,0 @@ -# reference: -# October 1582 (the Gregorian calendar, Civil Date) -# S M Tu W Th F S -# 1 2 3 4 15 16 -# 17 18 19 20 21 22 23 -# 24 25 26 27 28 29 30 -# 31 - -describe :date_ordinal, shared: true do - it "constructs a Date object from an ordinal date" do - # October 1582 (the Gregorian calendar, Ordinal Date) - # S M Tu W Th F S - # 274 275 276 277 278 279 - # 280 281 282 283 284 285 286 - # 287 288 289 290 291 292 293 - # 294 - Date.send(@method, 1582, 274).should == Date.civil(1582, 10, 1) - Date.send(@method, 1582, 277).should == Date.civil(1582, 10, 4) - Date.send(@method, 1582, 278).should == Date.civil(1582, 10, 15) - Date.send(@method, 1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND) - end -end diff --git a/spec/ruby/library/date/shared/parse.rb b/spec/ruby/library/date/shared/parse.rb index 1015285e04..40af908386 100644 --- a/spec/ruby/library/date/shared/parse.rb +++ b/spec/ruby/library/date/shared/parse.rb @@ -13,7 +13,7 @@ describe :date_parse, shared: true do d.day.should == 23 end - it "can parse a 'mmm DD YYYY' string into a Date object" do + it "can parse a 'DD mmm YYYY' string into a Date object" do d = Date.parse("23#{@sep}feb#{@sep}2008") d.year.should == 2008 d.month.should == 2 @@ -42,7 +42,7 @@ describe :date_parse, shared: true do d.should == Date.civil(2005, 11, 5) end - it "can parse a year, day and month name into a Date object" do + it "can parse a day, month name and year into a Date object" do d = Date.parse("5th#{@sep}november#{@sep}2005") d.should == Date.civil(2005, 11, 5) end diff --git a/spec/ruby/library/date/shared/parse_eu.rb b/spec/ruby/library/date/shared/parse_eu.rb index ecb15e3c0e..3819524a57 100644 --- a/spec/ruby/library/date/shared/parse_eu.rb +++ b/spec/ruby/library/date/shared/parse_eu.rb @@ -7,28 +7,28 @@ describe :date_parse_eu, shared: true do d.day.should == 1 end - it "can parse a MM-DD-YYYY string into a Date object" do + it "can parse a DD-MM-YYYY string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}2007") d.year.should == 2007 d.month.should == 1 d.day.should == 10 end - it "can parse a MM-DD-YY string into a Date object" do + it "can parse a YY-MM-DD string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}07") d.year.should == 2010 d.month.should == 1 d.day.should == 7 end - it "can parse a MM-DD-YY string into a Date object NOT using the year digits as 20XX" do + it "can parse a YY-MM-DD string into a Date object NOT using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", false) d.year.should == 10 d.month.should == 1 d.day.should == 7 end - it "can parse a MM-DD-YY string into a Date object using the year digits as 20XX" do + it "can parse a YY-MM-DD string into a Date object using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", true) d.year.should == 2010 d.month.should == 1 diff --git a/spec/ruby/library/date/shared/parse_us.rb b/spec/ruby/library/date/shared/parse_us.rb index 7be62b1af1..17e2fc96c1 100644 --- a/spec/ruby/library/date/shared/parse_us.rb +++ b/spec/ruby/library/date/shared/parse_us.rb @@ -6,28 +6,28 @@ describe :date_parse_us, shared: true do d.day.should == 1 end - it "parses a MM#{@sep}DD#{@sep}YYYY string into a Date object" do + it "parses a DD#{@sep}MM#{@sep}YYYY string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}2007") d.year.should == 2007 d.month.should == 1 d.day.should == 10 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}07") d.year.should == 2010 d.month.should == 1 d.day.should == 7 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object NOT using the year digits as 20XX" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object NOT using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", false) d.year.should == 10 d.month.should == 1 d.day.should == 7 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object using the year digits as 20XX" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", true) d.year.should == 2010 d.month.should == 1 diff --git a/spec/ruby/library/date/shared/valid_civil.rb b/spec/ruby/library/date/shared/valid_civil.rb deleted file mode 100644 index 545c207bbe..0000000000 --- a/spec/ruby/library/date/shared/valid_civil.rb +++ /dev/null @@ -1,36 +0,0 @@ -describe :date_valid_civil?, shared: true do - - # reference: - # October 1582 (the Gregorian calendar, Civil Date) - # S M Tu W Th F S - # 1 2 3 4 15 16 - # 17 18 19 20 21 22 23 - # 24 25 26 27 28 29 30 - # 31 - - it "returns true if it is a valid civil date" do - Date.send(@method, 1582, 10, 15).should be_true - Date.send(@method, 1582, 10, 14, Date::ENGLAND).should be_true - end - - it "returns false if it is not a valid civil date" do - Date.send(@method, 1582, 10, 14).should == false - end - - it "handles negative months and days" do - # October 1582 (the Gregorian calendar, Civil Date) - # S M Tu W Th F S - # -21 -20 -19 -18 -17 -16 - # -15 -14 -13 -12 -11 -10 -9 - # -8 -7 -6 -5 -4 -3 -2 - # -1 - Date.send(@method, 1582, -3, -22).should be_false - Date.send(@method, 1582, -3, -21).should be_true - Date.send(@method, 1582, -3, -18).should be_true - Date.send(@method, 1582, -3, -17).should be_true - - Date.send(@method, 2007, -11, -10).should be_true - Date.send(@method, 2008, -11, -10).should be_true - end - -end diff --git a/spec/ruby/library/date/shared/valid_commercial.rb b/spec/ruby/library/date/shared/valid_commercial.rb deleted file mode 100644 index 117dfe1d3d..0000000000 --- a/spec/ruby/library/date/shared/valid_commercial.rb +++ /dev/null @@ -1,34 +0,0 @@ -describe :date_valid_commercial?, shared: true do - - it "returns true if it is a valid commercial date" do - # October 1582 (the Gregorian calendar, Commercial Date) - # M Tu W Th F Sa Su - # 39: 1 2 3 4 5 6 7 - # 40: 1 2 3 4 5 6 7 - # 41: 1 2 3 4 5 6 7 - Date.send(@method, 1582, 39, 4).should be_true - Date.send(@method, 1582, 39, 5).should be_true - Date.send(@method, 1582, 41, 4).should be_true - Date.send(@method, 1582, 41, 5).should be_true - Date.send(@method, 1582, 41, 4, Date::ENGLAND).should be_true - Date.send(@method, 1752, 37, 4, Date::ENGLAND).should be_true - end - - it "returns false it is not a valid commercial date" do - Date.send(@method, 1999, 53, 1).should be_false - end - - it "handles negative week and day numbers" do - # October 1582 (the Gregorian calendar, Commercial Date) - # M Tu W Th F Sa Su - # -12: -7 -6 -5 -4 -3 -2 -1 - # -11: -7 -6 -5 -4 -3 -2 -1 - # -10: -7 -6 -5 -4 -3 -2 -1 - Date.send(@method, 1582, -12, -4).should be_true - Date.send(@method, 1582, -12, -3).should be_true - Date.send(@method, 2007, -44, -2).should be_true - Date.send(@method, 2008, -44, -2).should be_true - Date.send(@method, 1999, -53, -1).should be_false - end - -end diff --git a/spec/ruby/library/date/shared/valid_jd.rb b/spec/ruby/library/date/shared/valid_jd.rb deleted file mode 100644 index f6ca3f579d..0000000000 --- a/spec/ruby/library/date/shared/valid_jd.rb +++ /dev/null @@ -1,32 +0,0 @@ -describe :date_valid_jd?, shared: true do - it "returns true if passed a number value" do - Date.send(@method, -100).should be_true - Date.send(@method, 100.0).should be_true - Date.send(@method, 2**100).should be_true - Date.send(@method, Rational(1,2)).should be_true - end - - it "returns false if passed nil" do - Date.send(@method, nil).should be_false - end - - ruby_version_is ''...'2.7' do - it "returns true if passed symbol" do - Date.send(@method, :number).should be_true - end - - it "returns true if passed false" do - Date.send(@method, false).should be_true - end - end - - ruby_version_is '2.7' do - it "returns false if passed symbol" do - Date.send(@method, :number).should be_false - end - - it "returns false if passed false" do - Date.send(@method, false).should be_false - end - end -end diff --git a/spec/ruby/library/date/shared/valid_ordinal.rb b/spec/ruby/library/date/shared/valid_ordinal.rb deleted file mode 100644 index 1ed961be23..0000000000 --- a/spec/ruby/library/date/shared/valid_ordinal.rb +++ /dev/null @@ -1,26 +0,0 @@ -describe :date_valid_ordinal?, shared: true do - it "determines if the date is a valid ordinal date" do - # October 1582 (the Gregorian calendar, Ordinal Date) - # S M Tu W Th F S - # 274 275 276 277 278 279 - # 280 281 282 283 284 285 286 - # 287 288 289 290 291 292 293 - # 294 - Date.send(@method, 1582, 277).should == true - Date.send(@method, 1582, 278).should == true - Date.send(@method, 1582, 287).should == true - Date.send(@method, 1582, 288).should == true - end - - it "handles negative day numbers" do - # October 1582 (the Gregorian calendar, Ordinal Date) - # S M Tu W Th F S - # -82 -81 -80 -79 -78 -77 - # -76 -75 -74 -73 -72 -71 -70 - # -69 -68 -67 -66 -65 -64 -63 - # -62 - Date.send(@method, 1582, -79).should == true - Date.send(@method, 1582, -78).should == true - Date.send(@method, 2007, -100).should == true - end -end |
