mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
Add tests for corrected behavior around casting
This commit is contained in:
parent
8070e51e26
commit
66f0835d51
3 changed files with 30 additions and 5 deletions
|
@ -3732,7 +3732,7 @@ pub fn checked_cast_text_to_numeric(text: &str) -> std::result::Result<OwnedValu
|
|||
// sqlite will parse the first N digits of a string to numeric value, then determine
|
||||
// whether _that_ value is more likely a real or integer value. e.g.
|
||||
// '-100234-2344.23e14' evaluates to -100234 instead of -100234.0
|
||||
let bytes = text.as_bytes();
|
||||
let bytes = text.trim().as_bytes();
|
||||
let mut end = 0;
|
||||
let mut has_decimal = false;
|
||||
let mut has_exponent = false;
|
||||
|
|
|
@ -260,9 +260,13 @@ do_execsql_test add-agg-int-agg-float {
|
|||
SELECT sum(id) + sum(price) from products
|
||||
} {689.0}
|
||||
|
||||
do_execsql_test add-agg-int-agg-float {
|
||||
SELECT sum(id) + sum(price) from products
|
||||
} {689.0}
|
||||
do_execsql_test add-float-text-edgecase {
|
||||
SELECT '-123.22342-24' + '232.3x32';
|
||||
} {109.07658}
|
||||
|
||||
do_execsql_test add-str-edgecase {
|
||||
SELECT '-1+23.22342-24' + '2-32.3x32';
|
||||
} {1}
|
||||
|
||||
|
||||
|
||||
|
@ -298,6 +302,9 @@ do_execsql_test subtract-agg-float-agg-int {
|
|||
SELECT sum(price) - sum(id) from products
|
||||
} {557.0}
|
||||
|
||||
do_execsql_test subtract-str-float-edgecase {
|
||||
SELECT '-123.22342-24' - '232.3x32';
|
||||
} {-355.52342}
|
||||
|
||||
|
||||
do_execsql_test multiply-agg-int {
|
||||
|
@ -332,6 +339,9 @@ do_execsql_test multiply-agg-float-agg-int {
|
|||
SELECT sum(price) * sum(id) from products
|
||||
} {41118.0}
|
||||
|
||||
do_execsql_test multiply-str-floats-edgecase {
|
||||
SELECT '-123.22342-24' * '232.3x32';
|
||||
} {-28624.800466}
|
||||
|
||||
|
||||
do_execsql_test divide-agg-int {
|
||||
|
@ -557,6 +567,8 @@ foreach {testname lhs rhs ans} {
|
|||
text_float-text_int '8.0' '1' 4
|
||||
text_float-text_float '8.0' '3.0' 1
|
||||
text_float-text '8.0' 'a' 8
|
||||
text-int-text-edge '123-23' 2 30
|
||||
text-signed-text-edge '-123' '2xi' -31
|
||||
text-null '8' NULL {}
|
||||
} {
|
||||
do_execsql_test shift-right-$testname "SELECT $lhs >> $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
|
||||
|
|
|
@ -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}
|
||||
# } {P236|H210|T522|A261|R163|R163|R150|K530|K530|X000|0000}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue