Skip to content

Commit

Permalink
Confirm very large decimals round-trip
Browse files Browse the repository at this point in the history
No code changes are needed, but very large denominators in a Rat are fragile. This test ensures DBIish doesn't accidentally overflow the Rat.
  • Loading branch information
rbt committed Nov 28, 2022
1 parent 07bdcb9 commit 6bc46bd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion t/34-pg-types.t
Expand Up @@ -2,7 +2,7 @@ use v6;
use Test;
use DBIish::CommonTesting;

plan 2;
plan 3;

my %con-parms;
# If env var set, no parameter needed.
Expand Down Expand Up @@ -48,3 +48,16 @@ subtest 'Test changing column type' => {
($col1) = $sth.row;
is $col1, 'changed', 'Changed';
}

subtest 'Big Decimals' => {
my FatRat @values = '0.00000000000000000000123'.FatRat,
'1.123456789123456789123456789123456789123456789123456789'.FatRat;
for @values -> $val {
my $sth = $dbh.execute('SELECT ?::numeric', $val);
my ($col1) = $sth.row;
isa-ok $col1, Rat, 'Rational';

# Convert to FatRat to prevent comparison issues during stringification that is (via eq) uses.
is $col1.FatRat, $val.FatRat, 'Expected value roundtripped';
}
}

0 comments on commit 6bc46bd

Please sign in to comment.