Skip to content

Commit

Permalink
Add varchar to date conversion tests with signed year
Browse files Browse the repository at this point in the history
Supplements a094360 with test cases
with a sign.
  • Loading branch information
findepi committed Aug 10, 2022
1 parent acdecbe commit 750adac
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ public void testDateLiteral()
// large year
assertInvalidFunction("DATE '5881580-07-12'", INVALID_LITERAL, "line 1:1: '5881580-07-12' is not a valid date literal");
assertInvalidFunction("DATE '392251590-07-12'", INVALID_LITERAL, "line 1:1: '392251590-07-12' is not a valid date literal");
// signed
assertFunction("DATE '+2013-02-02'", DATE, toDate(new DateTime(2013, 2, 2, 0, 0, 0, 0, UTC)));
assertFunction("DATE '-2013-02-02'", DATE, toDate(new DateTime(-2013, 2, 2, 0, 0, 0, 0, UTC)));
// signed with whitespace
assertFunction("DATE ' +2013-02-02'", DATE, toDate(new DateTime(2013, 2, 2, 0, 0, 0, 0, UTC)));
assertInvalidFunction("DATE '+ 2013-02-02'", INVALID_LITERAL, "line 1:1: '+ 2013-02-02' is not a valid date literal");
assertInvalidFunction("DATE ' + 2013-02-02'", INVALID_LITERAL, "line 1:1: ' + 2013-02-02' is not a valid date literal");
assertFunction("DATE ' -2013-02-02'", DATE, toDate(new DateTime(-2013, 2, 2, 0, 0, 0, 0, UTC)));
assertInvalidFunction("DATE '- 2013-02-02'", INVALID_LITERAL, "line 1:1: '- 2013-02-02' is not a valid date literal");
assertInvalidFunction("DATE ' - 2013-02-02'", INVALID_LITERAL, "line 1:1: ' - 2013-02-02' is not a valid date literal");
}

/**
Expand Down Expand Up @@ -314,6 +324,16 @@ public void testDateCastFromVarchar()
// large year
assertInvalidFunction("CAST('5881580-07-12' AS date)", INVALID_CAST_ARGUMENT, "Value cannot be cast to date: 5881580-07-12");
assertInvalidFunction("CAST('392251590-07-12' AS date)", INVALID_CAST_ARGUMENT, "Value cannot be cast to date: 392251590-07-12");
// signed
assertFunction("CAST('+2013-02-02' AS date)", DATE, toDate(new DateTime(2013, 2, 2, 0, 0, 0, 0, UTC)));
assertFunction("CAST('-2013-02-02' AS date)", DATE, toDate(new DateTime(-2013, 2, 2, 0, 0, 0, 0, UTC)));
// signed with whitespace
assertFunction("CAST(' +2013-02-02' AS date)", DATE, toDate(new DateTime(2013, 2, 2, 0, 0, 0, 0, UTC)));
assertInvalidFunction("CAST('+ 2013-02-02' AS date)", INVALID_CAST_ARGUMENT, "Value cannot be cast to date: + 2013-02-02");
assertInvalidFunction("CAST(' + 2013-02-02' AS date)", INVALID_CAST_ARGUMENT, "Value cannot be cast to date: + 2013-02-02");
assertFunction("CAST(' -2013-02-02' AS date)", DATE, toDate(new DateTime(-2013, 2, 2, 0, 0, 0, 0, UTC)));
assertInvalidFunction("CAST('- 2013-02-02' AS date)", INVALID_CAST_ARGUMENT, "Value cannot be cast to date: - 2013-02-02");
assertInvalidFunction("CAST(' - 2013-02-02' AS date)", INVALID_CAST_ARGUMENT, "Value cannot be cast to date: - 2013-02-02");
}

@Test
Expand Down

0 comments on commit 750adac

Please sign in to comment.