1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
# Initialize node
my $node = PostgreSQL::Test::Cluster->new('node');
$node->init;
$node->start;
# Create extension
$node->safe_psql("postgres", "CREATE EXTENSION vector;");
my @types = ("vector", "halfvec", "sparsevec");
my @inputs = ("[1.23,4.56,7.89]", "[1.23,4.56,7.89]", "{1:1.23,2:4.56,3:7.89}/3");
my @subs = (" ", " ", ",", ":", "-", "1", "9", "\0", "2147483648", "-2147483649");
for my $i (0 .. $#types)
{
my $type = $types[$i];
for (1 .. 100)
{
my $input = $inputs[$i] . "";
for (1 .. 1 + int(rand() * 2))
{
my $r = int(rand() * length($input));
my $sub = $subs[int(rand() * scalar(@subs))];
if ($sub eq "\0")
{
# Truncate
$input = substr($input, 0, $r);
}
elsif (rand() > 0.5)
{
# Insert
substr($input, $r, 0) = $sub;
}
else
{
# Replace
substr($input, $r, length($sub), $sub);
}
}
my ($ret, $stdout, $stderr) = $node->psql("postgres", "SELECT '$input'::$type;");
if ($ret != 0)
{
# Test for type in error message
like($stderr, qr/$type/);
}
else
{
# Count test
is($ret, 0);
}
}
}
done_testing();
|