Pg views and sqlite views, patch from wreis
[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:
6cedfc23 36 constraints: []
37 fields:
38 First_name:
39 data_type: foovar
40 default_value: ~
41 extra: {}
42 is_nullable: 1
43 is_primary_key: 0
44 is_unique: 0
45 name: First_name
46 order: 1
47 size:
48 - 0
49 indices: []
50 name: person
51 options: []
52 order: 1
53 triggers: {}
54 views: {}
55translator:
56 add_drop_table: 0
57 filename: ~
58 no_comments: 0
59 parser_args: {}
60 parser_type: SQL::Translator::Parser::YAML
61 producer_args: {}
62 producer_type: SQL::Translator::Producer::YAML
63 show_warnings: 1
64 trace: 0
8ce5d615 65 version: SUPPRESSED
6cedfc23 66};
67
0e452694 68# Parse the test schema
6cedfc23 69my $obj;
70$obj = SQL::Translator->new(
71 debug => 0,
72 show_warnings => 1,
73 from => "YAML",
74 to => "YAML",
75 data => $in_yaml,
76 filters => [
77 # Filter from SQL::Translator::Filter::*
78 [ 'Names', {
79 tables => 'lc',
80 fields => 'ucfirst',
81 } ],
82 ],
83
84) or die "Failed to create translator object: ".SQL::Translator->error;
85
6cedfc23 86my $out;
87lives_ok { $out = $obj->translate; } "Translate ran";
88is $obj->error, '' ,"No errors";
89ok $out ne "" ,"Produced something!";
8ce5d615 90# Somewhat hackishly modify the yaml with a regex to avoid
91# failing randomly on every change of version.
92$out =~ s/version: .*/version: SUPPRESSED/;
6cedfc23 93eq_or_diff $out, $ans_yaml ,"Output looks right";