Skip to content

Commit c0a1a37

Browse files
committed
first start unified diff
1 parent 2787a2d commit c0a1a37

File tree

3 files changed

+162
-0
lines changed

3 files changed

+162
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2019 java-diff-utils.
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 com.github.difflib.unifieddiff;
17+
18+
import java.io.BufferedReader;
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.io.InputStreamReader;
22+
import java.util.logging.Logger;
23+
24+
/**
25+
*
26+
* @author Tobias Warneke (t.warneke@gmx.net)
27+
*/
28+
public final class UnifiedDiff {
29+
30+
private UnifiedDiff(InputStream stream) throws IOException {
31+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream));) {
32+
while (reader.ready()) {
33+
String line = reader.readLine();
34+
LOG.info(line);
35+
}
36+
}
37+
38+
}
39+
private static final Logger LOG = Logger.getLogger(UnifiedDiff.class.getName());
40+
41+
public static UnifiedDiff parse(InputStream stream) throws IOException {
42+
return new UnifiedDiff(stream);
43+
}
44+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2019 java-diff-utils.
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 com.github.difflib.unifieddiff;
17+
18+
import java.io.IOException;
19+
import org.junit.After;
20+
import org.junit.AfterClass;
21+
import org.junit.Before;
22+
import org.junit.BeforeClass;
23+
import org.junit.Test;
24+
25+
/**
26+
*
27+
* @author Tobias Warneke (t.warneke@gmx.net)
28+
*/
29+
public class UnifiedDiffTest {
30+
31+
public UnifiedDiffTest() {
32+
}
33+
34+
@BeforeClass
35+
public static void setUpClass() {
36+
}
37+
38+
@AfterClass
39+
public static void tearDownClass() {
40+
}
41+
42+
@Before
43+
public void setUp() {
44+
}
45+
46+
@After
47+
public void tearDown() {
48+
}
49+
50+
@Test
51+
public void testSimpleParse() throws IOException {
52+
UnifiedDiff diff = UnifiedDiff.parse(UnifiedDiffTest.class.getResourceAsStream("jsqlparser_patch_1.diff"));
53+
54+
System.out.println(diff);
55+
}
56+
57+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
From 3209a16c55c1976d5b772c607fd4b9d5fb9f9483 Mon Sep 17 00:00:00 2001
2+
From: wumpz <t.warneke@gmx.net>
3+
Date: Tue, 19 Feb 2019 01:35:14 +0100
4+
Subject: [PATCH] fixes #753
5+
6+
---
7+
src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt | 5 +++--
8+
.../net/sf/jsqlparser/statement/select/SelectTest.java | 7 +++++++
9+
2 files changed, 10 insertions(+), 2 deletions(-)
10+
11+
diff --git a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
12+
index cd9bcd1..5f4b2b7 100644
13+
--- a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
14+
+++ b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
15+
@@ -189,6 +189,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
16+
| <K_JOIN:"JOIN">
17+
| <K_KEEP:"KEEP">
18+
| <K_KEY:"KEY">
19+
+| <K_FN:"FN">
20+
| <K_LAST: "LAST">
21+
| <K_LATERAL:"LATERAL">
22+
| <K_LEADING:"LEADING">
23+
@@ -1039,7 +1040,7 @@ String RelObjectNameWithoutValue() :
24+
| tk=<K_INSERT> | tk=<K_INDEX> | tk=<K_PRIMARY> | tk=<K_ENABLE>
25+
| tk=<K_UNSIGNED>
26+
| tk=<K_TEMP> | tk=<K_TEMPORARY> | tk=<K_TYPE> | tk=<K_ISNULL>
27+
- | tk=<K_ZONE> | tk=<K_COLUMNS> | tk=<K_DESCRIBE>
28+
+ | tk=<K_ZONE> | tk=<K_COLUMNS> | tk=<K_DESCRIBE> | tk=<K_FN>
29+
/* | tk=<K_PLACING> | tk=<K_BOTH> | tk=<K_LEADING> | tk=<K_TRAILING> */
30+
)
31+
32+
@@ -3118,7 +3119,7 @@ Function Function() #Function:
33+
Expression expr1 = null;
34+
}
35+
{
36+
- ["{fn" { retval.setEscaped(true); } ]
37+
+ ["{" <K_FN> { retval.setEscaped(true); } ]
38+
39+
funcName=RelObjectNameExt()
40+
41+
diff --git a/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java b/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java
42+
index 7ee9b38..d39bfd3 100644
43+
--- a/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java
44+
+++ b/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java
45+
@@ -1063,6 +1063,13 @@ public class SelectTest {
46+
assertSqlCanBeParsedAndDeparsed("SELECT {fn concat(a, b)} AS COL");
47+
}
48+
49+
+ @Test
50+
+ public void testEscapedFunctionsIssue753() throws JSQLParserException {
51+
+ Statement stmt = CCJSqlParserUtil.parse("SELECT { fn test(0)} AS COL");
52+
+ assertEquals("SELECT {fn test(0)} AS COL", stmt.toString());
53+
+ assertSqlCanBeParsedAndDeparsed("SELECT fn FROM fn");
54+
+ }
55+
+
56+
@Test
57+
public void testNamedParametersPR702() throws JSQLParserException {
58+
assertSqlCanBeParsedAndDeparsed("SELECT substring(id, 2, 3), substring(id from 2 for 3), substring(id from 2), trim(BOTH ' ' from 'foo bar '), trim(LEADING ' ' from 'foo bar '), trim(TRAILING ' ' from 'foo bar '), trim(' ' from 'foo bar '), position('foo' in 'bar'), overlay('foo' placing 'bar' from 1), overlay('foo' placing 'bar' from 1 for 2) FROM my table");
59+
--
60+
2.17.1.windows.2
61+

0 commit comments

Comments
 (0)