Update Trigger to insist on a valid table for on_table
[dbsrgits/SQL-Translator.git] / t / 38-filter-names.t
CommitLineData
6cedfc23 1#!/usr/bin/perl -w
2# vim:filetype=perl
3
4# Before `make install' is performed this script should be runnable with
5# `make test'. After `make install' it should work as `perl test.pl'
6
6cedfc23 7use strict;
8use Test::More;
9use Test::Exception;
10use Test::SQL::Translator qw(maybe_plan);
11
12use Data::Dumper;
13
14BEGIN {
15 maybe_plan(4, 'YAML', 'Test::Differences')
16}
17use Test::Differences;
18use SQL::Translator;
19
20my $in_yaml = qq{---
21schema:
22 tables:
23 Person:
24 name: Person
25 fields:
26 first_name:
27 data_type: foovar
28 name: first_name
29};
30
6cedfc23 31my $ans_yaml = qq{---
32schema:
33 procedures: {}
34 tables:
35 person:
36 comments: ''
37 constraints: []
38 fields:
39 First_name:
a4fb1ddc 40 comments: ''
6cedfc23 41 data_type: foovar
42 default_value: ~
43 extra: {}
44 is_nullable: 1
45 is_primary_key: 0
46 is_unique: 0
47 name: First_name
48 order: 1
49 size:
50 - 0
51 indices: []
52 name: person
53 options: []
54 order: 1
55 triggers: {}
56 views: {}
57translator:
58 add_drop_table: 0
59 filename: ~
60 no_comments: 0
61 parser_args: {}
62 parser_type: SQL::Translator::Parser::YAML
63 producer_args: {}
64 producer_type: SQL::Translator::Producer::YAML
65 show_warnings: 1
66 trace: 0
8ce5d615 67 version: SUPPRESSED
6cedfc23 68};
69
0e452694 70# Parse the test schema
6cedfc23 71my $obj;
72$obj = SQL::Translator->new(
73 debug => 0,
74 show_warnings => 1,
75 from => "YAML",
76 to => "YAML",
77 data => $in_yaml,
78 filters => [
79 # Filter from SQL::Translator::Filter::*
80 [ 'Names', {
81 tables => 'lc',
82 fields => 'ucfirst',
83 } ],
84 ],
85
86) or die "Failed to create translator object: ".SQL::Translator->error;
87
6cedfc23 88my $out;
89lives_ok { $out = $obj->translate; } "Translate ran";
90is $obj->error, '' ,"No errors";
91ok $out ne "" ,"Produced something!";
8ce5d615 92# Somewhat hackishly modify the yaml with a regex to avoid
93# failing randomly on every change of version.
94$out =~ s/version: .*/version: SUPPRESSED/;
6cedfc23 95eq_or_diff $out, $ans_yaml ,"Output looks right";