File: 92-postgresql_pagila.t

package info (click to toggle)
libsql-splitstatement-perl 1.00020-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 456 kB
  • sloc: perl: 3,231; sql: 1,478; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,217 bytes parent folder | download | duplicates (3)
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
63
64
65
66
#!/usr/bin/env perl

use strict;
use warnings;

use SQL::SplitStatement;

use Test::More tests => 38;

my $filename;
my $sql_code;

my $splitter;
my @statements;
my @endings;

$splitter = SQL::SplitStatement->new;

$filename = 't/data/pagila-schema.sql';
open my $fh, '<', $filename
    or die "Can't open file $filename: ", $!;
$sql_code = do { local $/; <$fh> };

@statements = $splitter->split( $sql_code );

cmp_ok(
    @statements, '==', 225,
    'Statements correctly split'
);

@endings = (
    qw|
        'UTF8'
        off
        false
        warning
        off
        schema'
        plpgsql
        postgres
        pg_catalog
        1
        postgres
        ''
        false
    |,
    ( ')', 'postgres' ) x 3,
    qw|IMMUTABLE postgres ) postgres 1 postgres ) postgres 1 postgres|,
    ( ')', 'postgres' ) x 3,
    qw|a.last_name|
);

like( $statements[$_], qr/\Q$endings[$_]\E$/, 'Statement ' . ($_+1) . ' check' )
    for 0..$#endings;

$splitter->keep_extra_spaces(1);
$splitter->keep_empty_statements(1);
$splitter->keep_terminator(1);
$splitter->keep_comments(1);

@statements = $splitter->split( $sql_code );

is(
    join( '', @statements ), $sql_code,
    'SQL code correctly rebuilt'
);