From cf95a04a500db97e5edcd6c0852490a1e0c317a7 Mon Sep 17 00:00:00 2001 From: Tony Kelman Date: Thu, 26 Jan 2017 12:23:30 -0800 Subject: [PATCH] Change tests of deleted methods to test_throws MethodError --- test/dates/arithmetic.jl | 10 ++++++++++ test/dates/periods.jl | 1 + 2 files changed, 11 insertions(+) diff --git a/test/dates/arithmetic.jl b/test/dates/arithmetic.jl index 61b39509c7e5b..0a43dda06ee8f 100644 --- a/test/dates/arithmetic.jl +++ b/test/dates/arithmetic.jl @@ -429,3 +429,13 @@ t5 = [Dates.Time(0, 0, 0) Dates.Time(0, 0, 1) Dates.Time(0, 0, 2); Dates.Time(0, @test t4 - t3 == [Dates.Millisecond(1000), Dates.Millisecond(60000), Dates.Millisecond(3600000)] @test (Dates.Date(2009, 1, 1):Dates.Week(1):Dates.Date(2009, 1, 21)) - (Dates.Date(2009, 1, 1):Dates.Day(1):Dates.Date(2009, 1, 3)) == [Dates.Day(0), Dates.Day(6), Dates.Day(12)] @test (Dates.DateTime(2009, 1, 1, 1, 1, 1):Dates.Second(1):Dates.DateTime(2009, 1, 1, 1, 1, 3)) - (Dates.DateTime(2009, 1, 1, 1, 1):Dates.Second(1):Dates.DateTime(2009, 1, 1, 1, 1, 2)) == [Dates.Second(1), Dates.Second(1), Dates.Second(1)] + +# ensure no non-commutative subtraction methods are defined, #20205 +@test_throws MethodError Dates.Day(1) .- t1 +@test_throws MethodError Dates.Hour(1) .- t3 +@test_throws MethodError Dates.Day(1) - t1 +@test_throws MethodError Dates.Hour(1) - t3 +@test_throws MethodError (Dates.Month(1) + Dates.Day(1)) .- t1 +@test_throws MethodError (Dates.Hour(1) + Dates.Minute(1)) .- t3 +@test_throws MethodError (Dates.Month(1) + Dates.Day(1)) - t1 +@test_throws MethodError (Dates.Hour(1) + Dates.Minute(1)) - t3 diff --git a/test/dates/periods.jl b/test/dates/periods.jl index 24fb166a90a13..f951790b85696 100644 --- a/test/dates/periods.jl +++ b/test/dates/periods.jl @@ -315,6 +315,7 @@ emptyperiod = ((y + d) - d) - y @test Dates.canonicalize(-y + m - w + d - h + mi - s + ms).periods == Dates.Period[-11m, -6d, -59mi, -999ms] @test Dates.Date(2009, 2, 1) - (Dates.Month(1) + Dates.Day(1)) == Dates.Date(2008, 12, 31) +@test_throws MethodError (Dates.Month(1) + Dates.Day(1)) - Dates.Date(2009,2,1) pa = [1y 1m 1w 1d; 1h 1mi 1s 1ms] cpa = [1y + 1s 1m + 1s 1w + 1s 1d + 1s; 1h + 1s 1mi + 1s 2m + 1s 1s + 1ms]