forked from JSQLParser/JSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringValueTest.java
More file actions
114 lines (93 loc) · 3.6 KB
/
StringValueTest.java
File metadata and controls
114 lines (93 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import static org.junit.jupiter.api.Assertions.assertEquals;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.test.TestUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
*
* @author toben
*/
public class StringValueTest {
@Test
public void testGetValue() {
StringValue instance = new StringValue("'*'");
String expResult = "*";
String result = instance.getValue();
assertEquals(expResult, result);
}
@Test
public void testGetValue2_issue329() {
StringValue instance = new StringValue("*");
String expResult = "*";
String result = instance.getValue();
assertEquals(expResult, result);
}
/**
* Test of getNotExcapedValue method, of class StringValue.
*/
@Test
public void testGetNotExcapedValue() {
StringValue instance = new StringValue("'*''*'");
String expResult = "*'*";
String result = instance.getNotExcapedValue();
assertEquals(expResult, result);
}
@Test
public void testPrefixes() {
checkStringValue("E'test'", "test", "E");
checkStringValue("'test'", "test", null);
}
private void checkStringValue(String original, String expectedValue, String expectedPrefix) {
StringValue v = new StringValue(original);
assertEquals(expectedValue, v.getValue());
assertEquals(expectedPrefix, v.getPrefix());
}
@Test
public void testIssue1566EmptyStringValue() {
StringValue v = new StringValue("'");
assertEquals("'", v.getValue());
}
@Test
public void testOracleAlternativeQuoting() throws JSQLParserException {
String sqlStr = "COMMENT ON COLUMN EMP.NAME IS q'{Na'm\\e}'";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
sqlStr = "COMMENT ON COLUMN EMP.NAME IS q'(Na'm\\e)'";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
sqlStr = "COMMENT ON COLUMN EMP.NAME IS q'[Na'm\\e]'";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
sqlStr = "COMMENT ON COLUMN EMP.NAME IS q''Na'm\\e]''";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
sqlStr = "select q'{Its good!}' from dual";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
sqlStr = "select q'{It's good!}' from dual";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
@Test
public void testParseInput_BYTEA() throws Exception {
String sqlStr = "VALUES (X'', X'01FF', X'01 bc 2a', X'01' '02')";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
@Test
void testDollarQuotesIssue2267() throws JSQLParserException {
String sqlStr = "SELECT $$this is a string$$, test, 'text' FROM tbl;";
PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
Assertions.assertInstanceOf(StringValue.class, select.getSelectItem(0).getExpression());
}
@Test
void testDollarQuotesWithDollarSignsInside() throws JSQLParserException {
String sqlStr = "SELECT $$this references $1 and costs $5$$ FROM tbl;";
PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
Assertions.assertInstanceOf(StringValue.class, select.getSelectItem(0).getExpression());
}
}