Skip to content

Commit 11bb349

Browse files
authored
Fixes table command with wildcard related issues (#114)
* removes unnecessary COMMAND_TABLE_MODE, adds new syntax test and improves the existing tests * tests wildcard in the middle of the column name * updated license header year
1 parent 5aea95a commit 11bb349

4 files changed

Lines changed: 150 additions & 16 deletions

File tree

src/main/antlr4/imports/COMMAND_TABLE_MODE.g4

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ COMMAND_TABLE_MODE_BRACKET_R: ']' -> type(BRACKET_R), popMode, popMode;
6161

6262
// tokens
6363

64-
COMMAND_TABLE_MODE_WILDCARD : '*';
6564
COMMAND_TABLE_MODE_COMMA : ',';
6665
COMMAND_TABLE_MODE_SINGLE_QUOTE: '\'';
6766
COMMAND_TABLE_MODE_DQSTRING: '"' ( '\\'. | '""' | ~('"'| '\\') )* '"';

src/test/java/com/teragrep/pth_03/tests/TableSyntaxTests.java

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,45 +50,88 @@
5050

5151
import static org.junit.jupiter.api.Assertions.assertEquals;
5252

53+
import org.junit.jupiter.api.Assertions;
5354
import org.junit.jupiter.params.ParameterizedTest;
5455
import org.junit.jupiter.params.provider.ValueSource;
5556
import org.w3c.dom.NodeList;
5657

57-
public class TableSyntaxTests {
58+
public final class TableSyntaxTests {
5859
@ParameterizedTest(name = "{index} command=''{0}''")
5960
@ValueSource(strings = {
6061
"table",
62+
"tableWithComma",
63+
"tableWildcard"
6164
})
62-
public void tableSyntaxParseTest(String arg) throws Exception {
63-
String fileName = "src/test/resources/antlr4/commands/table/" + arg + ".txt";
64-
ParserSyntaxTestingUtility parserSyntaxTestingUtility
65+
void tableSyntaxParseTest(String arg) throws Exception {
66+
final String fileName = "src/test/resources/antlr4/commands/table/" + arg + ".txt";
67+
final ParserSyntaxTestingUtility parserSyntaxTestingUtility
6568
= new ParserSyntaxTestingUtility(fileName, false);
6669
parserSyntaxTestingUtility.syntaxParseTest(arg);
6770
}
6871
@ParameterizedTest
6972
@ValueSource(strings = {
7073
"table",
74+
"tableWithComma",
75+
"tableWildcard"
7176
})
72-
void xpathTest1(String arg) throws Exception {
77+
void testTableTransformationExists(String arg) throws Exception {
7378
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
74-
String fileName = "src/test/resources/antlr4/commands/table/" + arg + ".txt";
75-
String xpathExp = "/root/transformStatement/tableTransformation";
79+
final String fileName = "src/test/resources/antlr4/commands/table/" + arg + ".txt";
80+
final String xpathExp = "/root/transformStatement/tableTransformation";
7681

77-
NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false);
82+
final NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false);
7883
// Check that 1 found
7984
assertEquals(1,nodesA.getLength());
8085
}
8186
@ParameterizedTest
8287
@ValueSource(strings = {
8388
"table",
8489
})
85-
void xpathTest2(String arg) throws Exception {
86-
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
87-
String fileName = "src/test/resources/antlr4/commands/table/" + arg + ".txt";
88-
String xpathExp = "/root/transformStatement/tableTransformation/t_table_wcfieldListParameter/t_table_fieldType[1]/t_table_stringType/value";
90+
void testTableWithSpaceDelim(String arg) throws Exception {
91+
final ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
92+
final String fileName = "src/test/resources/antlr4/commands/table/" + arg + ".txt";
93+
final String xpathExp = "/root/transformStatement/tableTransformation/t_table_wcfieldListParameter/t_table_fieldType";
8994

90-
NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false);
91-
// Check that 1 found
92-
assertEquals(1,nodesA.getLength());
95+
final NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false);
96+
// Check that 3 found
97+
Assertions.assertEquals(3,nodesA.getLength());
98+
Assertions.assertEquals("fuu",nodesA.item(0).getTextContent());
99+
Assertions.assertEquals("bli",nodesA.item(1).getTextContent());
100+
Assertions.assertEquals("byr*",nodesA.item(2).getTextContent());
101+
}
102+
103+
@ParameterizedTest
104+
@ValueSource(strings = {
105+
"tableWithComma",
106+
})
107+
void testTableWithCommaDelim(String arg) throws Exception {
108+
final ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
109+
final String fileName = "src/test/resources/antlr4/commands/table/" + arg + ".txt";
110+
final String xpathExp = "/root/transformStatement/tableTransformation/t_table_wcfieldListParameter/t_table_fieldType";
111+
112+
final NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false);
113+
// Check that 3 found
114+
Assertions.assertEquals(3,nodesA.getLength());
115+
Assertions.assertEquals("fuu",nodesA.item(0).getTextContent());
116+
Assertions.assertEquals("bli",nodesA.item(1).getTextContent());
117+
Assertions.assertEquals("byr*",nodesA.item(2).getTextContent());
118+
}
119+
120+
@ParameterizedTest
121+
@ValueSource(strings = {
122+
"tableWildcard",
123+
})
124+
void testTableWithWildcard(String arg) throws Exception {
125+
final ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
126+
final String fileName = "src/test/resources/antlr4/commands/table/" + arg + ".txt";
127+
final String xpathExp = "/root/transformStatement/tableTransformation/t_table_wcfieldListParameter/t_table_fieldType";
128+
129+
final NodeList nodesA = (NodeList) pstu.xpathQueryFile(fileName, xpathExp, false);
130+
// Check that 4 found
131+
Assertions.assertEquals(4,nodesA.getLength());
132+
Assertions.assertEquals("*",nodesA.item(0).getTextContent());
133+
Assertions.assertEquals("*foo",nodesA.item(1).getTextContent());
134+
Assertions.assertEquals("foo*bar",nodesA.item(2).getTextContent());
135+
Assertions.assertEquals("ba*",nodesA.item(3).getTextContent());
93136
}
94137
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!-- /*
2+
* Teragrep Data Processing Language Parser Library PTH-03
3+
* Copyright (C) 2019-2026 Suomen Kanuuna Oy
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
17+
*
18+
*
19+
* Additional permission under GNU Affero General Public License version 3
20+
* section 7
21+
*
22+
* If you modify this Program, or any covered work, by linking or combining it
23+
* with other code, such other code is not for that reason alone subject to any
24+
* of the requirements of the GNU Affero GPL version 3 as long as this Program
25+
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
26+
* modifications.
27+
*
28+
* Supplemented terms under GNU Affero General Public License version 3
29+
* section 7
30+
*
31+
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
32+
* versions must be marked as "Modified version of" The Program.
33+
*
34+
* Names of the licensors and authors may not be used for publicity purposes.
35+
*
36+
* No rights are granted for use of trade names, trademarks, or service marks
37+
* which are in The Program if any.
38+
*
39+
* Licensee must indemnify licensors and authors for any liability that these
40+
* contractual assumptions impose on licensors and authors.
41+
*
42+
* To the extent this program is licensed as part of the Commercial versions of
43+
* Teragrep, the applicable Commercial License may apply to this file if you as
44+
* a licensee so wish it.
45+
*/ -->
46+
| table * *foo foo*bar ba*
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!-- /*
2+
* Teragrep Data Processing Language Parser Library PTH-03
3+
* Copyright (C) 2019-2026 Suomen Kanuuna Oy
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
17+
*
18+
*
19+
* Additional permission under GNU Affero General Public License version 3
20+
* section 7
21+
*
22+
* If you modify this Program, or any covered work, by linking or combining it
23+
* with other code, such other code is not for that reason alone subject to any
24+
* of the requirements of the GNU Affero GPL version 3 as long as this Program
25+
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
26+
* modifications.
27+
*
28+
* Supplemented terms under GNU Affero General Public License version 3
29+
* section 7
30+
*
31+
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
32+
* versions must be marked as "Modified version of" The Program.
33+
*
34+
* Names of the licensors and authors may not be used for publicity purposes.
35+
*
36+
* No rights are granted for use of trade names, trademarks, or service marks
37+
* which are in The Program if any.
38+
*
39+
* Licensee must indemnify licensors and authors for any liability that these
40+
* contractual assumptions impose on licensors and authors.
41+
*
42+
* To the extent this program is licensed as part of the Commercial versions of
43+
* Teragrep, the applicable Commercial License may apply to this file if you as
44+
* a licensee so wish it.
45+
*/ -->
46+
| table fuu , bli , byr*

0 commit comments

Comments
 (0)