Only output trigger 'scope' if it's set in YAML and JSON producers
[dbsrgits/SQL-Translator.git] / t / 06xsv.t
CommitLineData
046f18e5 1#!/usr/bin/perl
2# vim: set ft=perl:
9c62867a 3
046f18e5 4#
9c62867a 5# Tests for xSV parser
046f18e5 6#
046f18e5 7use strict;
8use SQL::Translator;
6b73ef23 9use SQL::Translator::Schema;
dddbae2a 10use SQL::Translator::Schema::Constants;
fbc0552f 11use Test::More;
2d691ec1 12use Test::SQL::Translator qw(maybe_plan);
fbc0552f 13
2d691ec1 14BEGIN {
15 maybe_plan(25, 'SQL::Translator::Parser::xSV');
fbc0552f 16 SQL::Translator::Parser::xSV->import('parse');
fbc0552f 17}
046f18e5 18
19my $tr = SQL::Translator->new;
6b73ef23 20my $s = SQL::Translator::Schema->new;
9c62867a 21my $data = q|One, Two, Three, Four, Five, Six, Seven
22I, Am, Some, Data, Yo, -10, .04
23And, So, am, I, "you crazy, crazy bastard", 500982, 1.1
24|;
046f18e5 25
9c62867a 26$tr->parser_args( trim_fields => 1, scan_fields => 1 );
6b73ef23 27my $val = parse($tr, $data, $s);
046f18e5 28
dddbae2a 29my $schema = $tr->schema;
30my @tables = $schema->get_tables;
31is( scalar @tables, 1, 'Correct number of tables (1)' );
32
33my $table = shift @tables;
34is( $table->name, 'table1', 'Table is named "table1"' );
35
36my @fields = $table->get_fields;
37is( scalar @fields, 7, 'Correct number of fields (7)' );
38
39my $f1 = $fields[0];
40is( $f1->name, 'One', 'First field name is "One"' );
41is( $f1->data_type, 'char', 'Data type is "char"' );
42is( $f1->size, '3', 'Size is "3"' );
43is( $f1->is_primary_key, 1, 'Field is PK' );
44
45my $f2 = $fields[1];
46is( $f2->name, 'Two', 'First field name is "Two"' );
47is( $f2->data_type, 'char', 'Data type is "char"' );
48is( $f2->size, '2', 'Size is "2"' );
49is( $f2->is_primary_key, 0, 'Field is not PK' );
50
51my $f5 = $fields[4];
52is( $f5->name, 'Five', 'Fifth field name is "Five"' );
53is( $f5->data_type, 'char', 'Data type is "char"' );
54is( $f5->size, '26', 'Size is "26"' );
55is( $f5->is_primary_key, 0, 'Field is not PK' );
56
57my $f6 = $fields[5];
58is( $f6->name, 'Six', 'Sixth field name is "Six"' );
59is( $f6->data_type, 'integer', 'Data type is "integer"' );
60is( $f6->size, '6', 'Size is "6"' );
61
62my $f7 = $fields[6];
63is( $f7->name, 'Seven', 'Seventh field name is "Seven"' );
64is( $f7->data_type, 'float', 'Data type is "float"' );
923c7bb8 65is( $f7->size, '3,2', 'Size is "3,2"' );
dddbae2a 66
67my @indices = $table->get_indices;
68is( scalar @indices, 0, 'Correct number of indices (0)' );
69
70my @constraints = $table->get_constraints;
71is( scalar @constraints, 1, 'Correct number of constraints (1)' );
72my $c = shift @constraints;
73is( $c->type, PRIMARY_KEY, 'Constraint is a PK' );
74is( join(',', $c->fields), 'One', 'On field "One"' );