X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F14postgres-parser.t;h=c11d6162aa6afcc0fdffebddac300aa4473f7cf6;hb=9c05d806e51cf7e81870cf0d022593fe212a03e4;hp=55482582da0f6eb208cf4df6fe73b8f0f829c83a;hpb=84ef6e4e04d8beed11b86c54a3a7759cb772bcae;p=dbsrgits%2FSQL-Translator.git diff --git a/t/14postgres-parser.t b/t/14postgres-parser.t index 5548258..c11d616 100644 --- a/t/14postgres-parser.t +++ b/t/14postgres-parser.t @@ -71,6 +71,10 @@ my $sql = q{ FOR EACH ROW EXECUTE PROCEDURE foo(); + CREATE INDEX test_index1 ON t_test1 (f_varchar); + CREATE INDEX test_index2 ON t_test1 USING hash (f_char, f_bool); + CREATE INDEX test_index3 ON t_test1 USING hash (f_bigint, f_tz) WHERE f_bigint = '1' AND f_tz IS NULL; + alter table t_test1 add f_fk2 integer; alter table only t_test1 add constraint c_u1 unique (f_varchar); @@ -380,4 +384,27 @@ is( $trigger->perform_action_when, 'before', "Correct time for trigger"); is( $trigger->scope, 'row', "Correct scope for trigger"); is( $trigger->action, 'EXECUTE PROCEDURE foo()', "Correct action for trigger"); +# test index +my @indices = $t1->get_indices; +is(scalar @indices, 3, 'got three indexes'); + +my $t1_i1 = $indices[0]; +is( $t1_i1->name, 'test_index1', 'First index is "test_index1"' ); +is( join(',', $t1_i1->fields), 'f_varchar', 'Index is on field "f_varchar"' ); +is_deeply( [ $t1_i1->options ], [], 'Index is has no options' ); + +my $t1_i2 = $indices[1]; +is( $t1_i2->name, 'test_index2', 'Second index is "test_index2"' ); +is( join(',', $t1_i2->fields), 'f_char,f_bool', 'Index is on fields "f_char, f_bool"' ); +is_deeply( [ $t1_i2->options ], [ { using => 'hash' } ], 'Index is using hash method' ); + +my $t1_i3 = $indices[2]; +is( $t1_i3->name, 'test_index3', 'Third index is "test_index3"' ); +is( join(',', $t1_i3->fields), 'f_bigint,f_tz', 'Index is on fields "f_bigint, f_tz"' ); +is_deeply( + [ $t1_i3->options ], + [ { using => 'hash' }, { where => "f_bigint = '1' AND f_tz IS NULL" } ], + 'Index is using hash method and has predicate right' +); + done_testing;