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