File: 99-rt34889.t

package info (click to toggle)
libsql-tokenizer-perl 0.24-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 176 kB
  • sloc: perl: 103; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,866 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;

use Test::More;

use SQL::Tokenizer;

use constant SPACE => ' ';
use constant COMMA => ',';
use constant NL    => "\n";

my $query;
my @query;
my @tokenized;

my @tests= (
    {
        description => q{rt34889},
        query       => q{SELECT t.* FROM table t},
        wanted      => [ 'SELECT', SPACE, 't.*', SPACE, 'FROM', SPACE, 'table', SPACE, 't' ],
    }, {
        description => q{Selecting all fields from db.table},
        query       => q{SELECT t.* FROM db.table t},
        wanted      => [ 'SELECT', SPACE, 't.*', SPACE, 'FROM', SPACE, 'db.table', SPACE, 't' ],
    }, {
        description => q{Selecting all fields from db.table},
        query       => q{SELECT db.table.* FROM db.table},
        wanted      => [ 'SELECT', SPACE, 'db.table.*', SPACE, 'FROM', SPACE, 'db.table' ],
    }, {
        description => q{Storing to a variable},
        query       => q{SELECT @id = column FROM db.table},
        wanted =>
          [ 'SELECT', SPACE, '@id', SPACE, '=', SPACE, 'column', SPACE, 'FROM', SPACE, 'db.table' ],
    }, {
        description => q{Declare a variable},
        query       => q{DECLARE @id INT},
        wanted      => [ 'DECLARE', SPACE, '@id', SPACE, 'INT' ],
    }, {
        description => q{Declare a variable with two @},
        query       => q{DECLARE @@id INT},
        wanted      => [ 'DECLARE', SPACE, '@@id', SPACE, 'INT' ],
    }, {
        description => q{SQL full notation for DATABASE.SCHEMA.TABLE},
        query       => q{SELECT SUM(column) FROM database..table},
        wanted      => [ 'SELECT', SPACE, 'SUM', '(', 'column', ')', SPACE,'FROM', SPACE, 'database..table' ],
	},
);

plan tests => scalar @tests;

foreach my $test (@tests) {
    my @tokenized= SQL::Tokenizer->tokenize( $test->{query} );
    is_deeply( \@tokenized, $test->{wanted}, $test->{description} );
}