File: 10-sql-operators.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 (44 lines) | stat: -rw-r--r-- 950 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
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{!},
        query       => qq{SELECT !1},
        wanted      => [ 'SELECT', SPACE, '!', 1 ],
    }, {
        description => q{Negative number},
        query       => qq{SELECT -1},
        wanted      => [ 'SELECT', SPACE, '-', 1 ],
    }

);

for my $operator (qw( - + / * <=> <= >= < > <> != = == % ~ & ^ & && | || << >> )) {
    push @tests, {
        description => qq{$operator operator},
        query       => qq{SELECT 1${operator}2},
        wanted      => [ 'SELECT', SPACE, 1, $operator, 2 ],
      };
}

plan tests => scalar @tests;

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

__END__