Skip to content

Commit 2cbd045

Browse files
moved bug fix tests to dedicated class
1 parent 6abb537 commit 2cbd045

File tree

2 files changed

+115
-89
lines changed

2 files changed

+115
-89
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
}

sqldev/src/test/java/org/utplsql/sqldev/test/parser/UtplsqlParserTest.xtend

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -130,95 +130,6 @@ class UtplsqlParserTest extends AbstractJdbcTest {
130130
Assert.assertEquals("SCOTT.PKG.p", parser.getPathAt(parser.toPosition(19,1)))
131131
setupAndTeardown
132132
}
133-
134-
@Test
135-
def issue_1() {
136-
val plsql = '''
137-
create or replace package body test_expect_not_to_be_null
138-
is
139-
gc_object_name constant varchar2(30) := 't_not_to_be_null_test';
140-
gc_nested_table_name constant varchar2(30) := 'tt_not_to_be_null_test';
141-
gc_varray_name constant varchar2(30) := 'tv_not_to_be_null_test';
142-
143-
procedure cleanup_expectations
144-
is
145-
begin
146-
ut3.ut_expectation_processor.clear_expectations();
147-
end;
148-
149-
procedure create_types
150-
is
151-
pragma autonomous_transaction;
152-
begin
153-
execute immediate 'create type '||gc_object_name||' is object (dummy number)';
154-
execute immediate ' create type '||gc_nested_table_name||' is table of number';
155-
execute immediate '
156-
create type '||gc_varray_name||' is varray(1) of number';
157-
end;
158-
159-
procedure drop_types
160-
is
161-
pragma autonomous_transaction;
162-
begin
163-
execute immediate 'drop type '||gc_object_name;
164-
execute immediate ' drop type '||gc_nested_table_name;
165-
execute immediate '
166-
drop type '||gc_varray_name;
167-
end;
168-
169-
procedure blob_not_null
170-
is
171-
begin
172-
--Act
173-
execute immediate expectations_helpers.unary_expectation_block('not_to_be_null', 'blob', 'to_blob(''abc'')');
174-
--Assert
175-
ut.expect(anydata.convertCollection(ut3.ut_expectation_processor.get_failed_expectations())).to_be_empty();
176-
end;
177-
178-
--and so on...
179-
180-
end;
181-
'''
182-
val parser = new UtplsqlParser(plsql)
183-
Assert.assertEquals("test_expect_not_to_be_null.cleanup_expectations", parser.getPathAt(parser.toPosition(7,1)))
184-
Assert.assertEquals("test_expect_not_to_be_null.create_types", parser.getPathAt(parser.toPosition(13,1)))
185-
// was: '||gc_varray_name||'.drop_types
186-
Assert.assertEquals("test_expect_not_to_be_null.drop_types", parser.getPathAt(parser.toPosition(23,1)))
187-
// was: '||gc_varray_name||'.blob_not_null
188-
Assert.assertEquals("test_expect_not_to_be_null.blob_not_null", parser.getPathAt(parser.toPosition(33,1)))
189-
}
190-
191-
@Test
192-
def issue_7() {
193-
val plsql = '''
194-
create or replace package test_expect_not_to_be_null
195-
is
196-
--%suite(expectations - not_to_be_null)
197-
--%suitepath(utplsql.core.expectations.unary)
198-
199-
--%aftereach
200-
procedure cleanup_expectations;
201-
202-
--%beforeall
203-
procedure create_types;
204-
205-
--%afterall
206-
procedure drop_types;
207-
208-
--%test(Gives success for not null blob)
209-
procedure blob_not_null;
210-
211-
--%test(Gives success for blob with length 0)
212-
procedure blob_0_length;
213-
214-
-- ...
215-
end test_expect_not_to_be_null;
216-
/
217-
'''
218-
val parser = new UtplsqlParser(plsql)
219-
// was: test_expect_not_to_be_null.create_types
220-
Assert.assertEquals("test_expect_not_to_be_null.blob_not_null", parser.getPathAt(parser.toPosition(13,26)))
221-
}
222133

223134
@Test
224135
def testProcedure() {

0 commit comments

Comments
 (0)