From c0a1a3777c5fc084e73f8bbc1d2470efc87f1d66 Mon Sep 17 00:00:00 2001 From: wumpz Date: Thu, 28 Feb 2019 23:59:26 +0100 Subject: [PATCH] first start unified diff --- .../difflib/unifieddiff/UnifiedDiff.java | 44 +++++++++++++ .../difflib/unifieddiff/UnifiedDiffTest.java | 57 +++++++++++++++++ .../unifieddiff/jsqlparser_patch_1.diff | 61 +++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 src/main/java/com/github/difflib/unifieddiff/UnifiedDiff.java create mode 100644 src/test/java/com/github/difflib/unifieddiff/UnifiedDiffTest.java create mode 100644 src/test/resources/com/github/difflib/unifieddiff/jsqlparser_patch_1.diff diff --git a/src/main/java/com/github/difflib/unifieddiff/UnifiedDiff.java b/src/main/java/com/github/difflib/unifieddiff/UnifiedDiff.java new file mode 100644 index 0000000..9fb5184 --- /dev/null +++ b/src/main/java/com/github/difflib/unifieddiff/UnifiedDiff.java @@ -0,0 +1,44 @@ +/* + * Copyright 2019 java-diff-utils. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.difflib.unifieddiff; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.logging.Logger; + +/** + * + * @author Tobias Warneke (t.warneke@gmx.net) + */ +public final class UnifiedDiff { + + private UnifiedDiff(InputStream stream) throws IOException { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream));) { + while (reader.ready()) { + String line = reader.readLine(); + LOG.info(line); + } + } + + } + private static final Logger LOG = Logger.getLogger(UnifiedDiff.class.getName()); + + public static UnifiedDiff parse(InputStream stream) throws IOException { + return new UnifiedDiff(stream); + } +} diff --git a/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffTest.java b/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffTest.java new file mode 100644 index 0000000..380eb8e --- /dev/null +++ b/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffTest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2019 java-diff-utils. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.difflib.unifieddiff; + +import java.io.IOException; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author Tobias Warneke (t.warneke@gmx.net) + */ +public class UnifiedDiffTest { + + public UnifiedDiffTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Test + public void testSimpleParse() throws IOException { + UnifiedDiff diff = UnifiedDiff.parse(UnifiedDiffTest.class.getResourceAsStream("jsqlparser_patch_1.diff")); + + System.out.println(diff); + } + +} diff --git a/src/test/resources/com/github/difflib/unifieddiff/jsqlparser_patch_1.diff b/src/test/resources/com/github/difflib/unifieddiff/jsqlparser_patch_1.diff new file mode 100644 index 0000000..c868759 --- /dev/null +++ b/src/test/resources/com/github/difflib/unifieddiff/jsqlparser_patch_1.diff @@ -0,0 +1,61 @@ +From 3209a16c55c1976d5b772c607fd4b9d5fb9f9483 Mon Sep 17 00:00:00 2001 +From: wumpz +Date: Tue, 19 Feb 2019 01:35:14 +0100 +Subject: [PATCH] fixes #753 + +--- + src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt | 5 +++-- + .../net/sf/jsqlparser/statement/select/SelectTest.java | 7 +++++++ + 2 files changed, 10 insertions(+), 2 deletions(-) + +diff --git a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt +index cd9bcd1..5f4b2b7 100644 +--- a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt ++++ b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt +@@ -189,6 +189,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */ + | + | + | ++| + | + | + | +@@ -1039,7 +1040,7 @@ String RelObjectNameWithoutValue() : + | tk= | tk= | tk= | tk= + | tk= + | tk= | tk= | tk= | tk= +- | tk= | tk= | tk= ++ | tk= | tk= | tk= | tk= + /* | tk= | tk= | tk= | tk= */ + ) + +@@ -3118,7 +3119,7 @@ Function Function() #Function: + Expression expr1 = null; + } + { +- ["{fn" { retval.setEscaped(true); } ] ++ ["{" { retval.setEscaped(true); } ] + + funcName=RelObjectNameExt() + +diff --git a/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java b/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java +index 7ee9b38..d39bfd3 100644 +--- a/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java ++++ b/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java +@@ -1063,6 +1063,13 @@ public class SelectTest { + assertSqlCanBeParsedAndDeparsed("SELECT {fn concat(a, b)} AS COL"); + } + ++ @Test ++ public void testEscapedFunctionsIssue753() throws JSQLParserException { ++ Statement stmt = CCJSqlParserUtil.parse("SELECT { fn test(0)} AS COL"); ++ assertEquals("SELECT {fn test(0)} AS COL", stmt.toString()); ++ assertSqlCanBeParsedAndDeparsed("SELECT fn FROM fn"); ++ } ++ + @Test + public void testNamedParametersPR702() throws JSQLParserException { + 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"); +-- +2.17.1.windows.2 +