|
| 1 | +/* |
| 2 | + * Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com> |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.utplsql.sqldev.test.parser |
| 17 | + |
| 18 | +import org.junit.Assert |
| 19 | +import org.junit.Test |
| 20 | +import org.utplsql.sqldev.parser.UtplsqlParser |
| 21 | + |
| 22 | +class UtplsqlParserBugFixTest { |
| 23 | + |
| 24 | + @Test |
| 25 | + // https://github.com/utPLSQL/utPLSQL-SQLDeveloper/issues/1 |
| 26 | + def issue_1_matching_expr_in_string_literals() { |
| 27 | + val plsql = ''' |
| 28 | + create or replace package body test_expect_not_to_be_null |
| 29 | + is |
| 30 | + gc_object_name constant varchar2(30) := 't_not_to_be_null_test'; |
| 31 | + gc_nested_table_name constant varchar2(30) := 'tt_not_to_be_null_test'; |
| 32 | + gc_varray_name constant varchar2(30) := 'tv_not_to_be_null_test'; |
| 33 | + |
| 34 | + procedure cleanup_expectations |
| 35 | + is |
| 36 | + begin |
| 37 | + ut3.ut_expectation_processor.clear_expectations(); |
| 38 | + end; |
| 39 | + |
| 40 | + procedure create_types |
| 41 | + is |
| 42 | + pragma autonomous_transaction; |
| 43 | + begin |
| 44 | + execute immediate 'create type '||gc_object_name||' is object (dummy number)'; |
| 45 | + execute immediate ' create type '||gc_nested_table_name||' is table of number'; |
| 46 | + execute immediate ' |
| 47 | + create type '||gc_varray_name||' is varray(1) of number'; |
| 48 | + end; |
| 49 | + |
| 50 | + procedure drop_types |
| 51 | + is |
| 52 | + pragma autonomous_transaction; |
| 53 | + begin |
| 54 | + execute immediate 'drop type '||gc_object_name; |
| 55 | + execute immediate ' drop type '||gc_nested_table_name; |
| 56 | + execute immediate ' |
| 57 | + drop type '||gc_varray_name; |
| 58 | + end; |
| 59 | + |
| 60 | + procedure blob_not_null |
| 61 | + is |
| 62 | + begin |
| 63 | + --Act |
| 64 | + execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'blob', 'to_blob(''abc'')'); |
| 65 | + --Assert |
| 66 | + ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty(); |
| 67 | + end; |
| 68 | + |
| 69 | + --and so on... |
| 70 | + |
| 71 | + end; |
| 72 | + ''' |
| 73 | + val parser = new UtplsqlParser(plsql) |
| 74 | + Assert.assertEquals("test_expect_not_to_be_null.cleanup_expectations", parser.getPathAt(parser.toPosition(7,1))) |
| 75 | + Assert.assertEquals("test_expect_not_to_be_null.create_types", parser.getPathAt(parser.toPosition(13,1))) |
| 76 | + // was: '||gc_varray_name||'.drop_types |
| 77 | + Assert.assertEquals("test_expect_not_to_be_null.drop_types", parser.getPathAt(parser.toPosition(23,1))) |
| 78 | + // was: '||gc_varray_name||'.blob_not_null |
| 79 | + Assert.assertEquals("test_expect_not_to_be_null.blob_not_null", parser.getPathAt(parser.toPosition(33,1))) |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + // https://github.com/utPLSQL/utPLSQL-SQLDeveloper/issues/7 |
| 84 | + def issue_7_platform_specific_line_terminators() { |
| 85 | + val plsql = ''' |
| 86 | + create or replace package test_expect_not_to_be_null |
| 87 | + is |
| 88 | + --%suite(expectations - not_to_be_null) |
| 89 | + --%suitepath(utplsql.core.expectations.unary) |
| 90 | + |
| 91 | + --%aftereach |
| 92 | + procedure cleanup_expectations; |
| 93 | + |
| 94 | + --%beforeall |
| 95 | + procedure create_types; |
| 96 | + |
| 97 | + --%afterall |
| 98 | + procedure drop_types; |
| 99 | + |
| 100 | + --%test(Gives success for not null blob) |
| 101 | + procedure blob_not_null; |
| 102 | + |
| 103 | + --%test(Gives success for blob with length 0) |
| 104 | + procedure blob_0_length; |
| 105 | + |
| 106 | + -- ... |
| 107 | + end test_expect_not_to_be_null; |
| 108 | + / |
| 109 | + ''' |
| 110 | + val parser = new UtplsqlParser(plsql) |
| 111 | + // was: test_expect_not_to_be_null.create_types |
| 112 | + Assert.assertEquals("test_expect_not_to_be_null.blob_not_null", parser.getPathAt(parser.toPosition(13,26))) |
| 113 | + } |
| 114 | + |
| 115 | +} |
0 commit comments