fu/t/pgtypes.t
Yorhel 8f94dd0921 pg: Initial support for receiving binary results
Just the initial framework stuff and a few types to test with.
2025-02-07 15:18:45 +01:00

28 lines
999 B
Perl

use v5.36;
use Test::More;
no warnings 'experimental::builtin';
use builtin qw/true false is_bool created_as_number/;
plan skip_all => $@ if !eval { require FU::PG; } && $@ =~ /Unable to load libpq/;
die $@ if $@;
plan skip_all => 'Please set FU_TEST_DB to a PostgreSQL connection string to run these tests' if !$ENV{FU_TEST_DB};
my $conn = FU::PG->connect($ENV{FU_TEST_DB});
$conn->_debug_trace(0);
sub v($type, $v, $sql=$v) {
$sql = "($sql)::$type";
my $res = $conn->q("SELECT $sql")->text_results(0)->val;
ok is_bool($res), "recv bool $sql" if $type eq 'bool';
ok created_as_number($res), "recv number $sql" if $type =~ /^int/;
is $res, $v, "recv value $sql";
}
v bool => true, 'true';
v bool => false, 'false';
v int2 => $_ for (1, -1, -32768, 32767, 12345, -12345);
v int4 => $_ for (1, -1, -2147483648, 2147483647, 1234567890, -1234567890);
v int8 => $_ for (1, -1, -9223372036854775808, 9223372036854775807, 1234567890123456789, -1234567890123456789);
done_testing;