From 66f0835d515eb605650d08cb9d5bf0f217a53e61 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Sun, 23 Feb 2025 12:54:57 -0500 Subject: [PATCH] Add tests for corrected behavior around casting --- core/vdbe/mod.rs | 2 +- testing/math.test | 19 ++++++++++++++++--- testing/scalar-functions.test | 14 +++++++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index 5da0cd8e4..339bc8a4a 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -3732,7 +3732,7 @@ pub fn checked_cast_text_to_numeric(text: &str) -> std::result::Result> $rhs" $::ans @@ -627,6 +639,7 @@ foreach {testname lhs ans} { text-int-2 '1' 0 text-float-1 '1.0' 0 text-float-2 '0.0' 1 + text-float-edge '12-23.0' 0 null NULL {} } { do_execsql_test boolean-not "SELECT not $lhs" $::ans diff --git a/testing/scalar-functions.test b/testing/scalar-functions.test index 2315117b2..01feb7c1b 100755 --- a/testing/scalar-functions.test +++ b/testing/scalar-functions.test @@ -848,6 +848,18 @@ do_execsql_test cast-small-float-to-numeric { SELECT typeof(CAST('1.23' AS NUMERIC)), CAST('1.23' AS NUMERIC); } {real|1.23} +do_execsql_test cast-signed-edgecase-int-to-numeric { + SELECT typeof(CAST('-1230-23.40e24' AS NUMERIC)), CAST('-1230-23.40e24' AS NUMERIC); +} {integer|-1230} + +do_execsql_test cast-edgecase-int-to-numeric { + SELECT typeof(CAST('1230-23.40e24' AS NUMERIC)), CAST('1230-23.40e24' AS NUMERIC); +} {integer|1230} + +do_execsql_test cast-edgecase-int-to-numeric { + SELECT typeof(CAST('123023.4024' AS NUMERIC)), CAST('123023.4024' AS NUMERIC); +} {real|123023.4024} + do_execsql_test_regex sqlite-version-should-return-valid-output { SELECT sqlite_version(); } {\d+\.\d+\.\d+} @@ -869,4 +881,4 @@ do_execsql_test cast-in-where { # TODO: sqlite seems not enable soundex() by default unless build it with SQLITE_SOUNDEX enabled. # do_execsql_test soundex-text { # select soundex('Pfister'), soundex('husobee'), soundex('Tymczak'), soundex('Ashcraft'), soundex('Robert'), soundex('Rupert'), soundex('Rubin'), soundex('Kant'), soundex('Knuth'), soundex('x'), soundex(''); -# } {P236|H210|T522|A261|R163|R163|R150|K530|K530|X000|0000} \ No newline at end of file +# } {P236|H210|T522|A261|R163|R163|R150|K530|K530|X000|0000}