1#!/usr/bin/perl 2# vim: set ft=perl: 3 4# 5# Tests for xSV parser 6# 7use strict; 8use SQL::Translator; 9use SQL::Translator::Schema; 10use SQL::Translator::Schema::Constants; 11use Test::More; 12use Test::SQL::Translator qw(maybe_plan); 13 14BEGIN { 15 maybe_plan(25, 'SQL::Translator::Parser::xSV'); 16 SQL::Translator::Parser::xSV->import('parse'); 17} 18 19my $tr = SQL::Translator->new; 20my $s = SQL::Translator::Schema->new; 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|; 25 26$tr->parser_args( trim_fields => 1, scan_fields => 1 ); 27my $val = parse($tr, $data, $s); 28 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"' ); 65is( $f7->size, '3,2', 'Size is "3,2"' ); 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"' ); 75