File: 10-simple.t

package info (click to toggle)
libsql-splitstatement-perl 1.00020-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 456 kB
  • sloc: perl: 3,231; sql: 1,478; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,218 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
67
68
69
70
#!/usr/bin/env perl

use strict;
use warnings;

use SQL::SplitStatement;

use Test::More tests => 5;

my $sql = <<'SQL';
CREATE TABLE foo (
    foo_field_1 VARCHAR,
    foo_field_2 VARCHAR
);

CREATE TABLE bar (
    bar_field_1 VARCHAR,
    bar_field_2 VARCHAR
);
SQL

chomp ( my $clean_sql = <<'SQL' );
CREATE TABLE foo (
    foo_field_1 VARCHAR,
    foo_field_2 VARCHAR
)CREATE TABLE bar (
    bar_field_1 VARCHAR,
    bar_field_2 VARCHAR
)
SQL

my $sql_splitter = SQL::SplitStatement->new({
    keep_terminator       => 1,
    keep_extra_spaces     => 1,
    keep_empty_statements => 1
});

my @statements;

@statements = $sql_splitter->split($sql);

cmp_ok (
    scalar(@statements), '==', 3,
    'number of atomic statements w/ semicolon'
);

is (
    join( '', @statements ), $sql,
    'SQL code rebuilt w/ semicolon'
);

$sql_splitter->keep_terminators(0);
@statements = $sql_splitter->split($sql);

is (
    join( ';', @statements ), $sql,
    'SQL code rebuilt w/o semicolon'
);

@statements = $sql_splitter->new->split($sql);

cmp_ok (
    scalar(@statements), '==', 2,
    'number of atomic statements w/o semicolon'
);

is (
    join( '', @statements ), $clean_sql,
    'SQL code rebuilt w/o semicolon'
);