franta-hg@46: /** franta-hg@46: * SQL-DK franta-hg@46: * Copyright © 2013 František Kučera (frantovo.cz) franta-hg@46: * franta-hg@46: * This program is free software: you can redistribute it and/or modify franta-hg@46: * it under the terms of the GNU General Public License as published by franta-hg@46: * the Free Software Foundation, either version 3 of the License, or franta-hg@46: * (at your option) any later version. franta-hg@46: * franta-hg@46: * This program is distributed in the hope that it will be useful, franta-hg@46: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@46: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@46: * GNU General Public License for more details. franta-hg@46: * franta-hg@46: * You should have received a copy of the GNU General Public License franta-hg@46: * along with this program. If not, see . franta-hg@46: */ franta-hg@46: package info.globalcode.sql.dk; franta-hg@46: franta-hg@46: import java.util.regex.Matcher; franta-hg@46: import java.util.regex.Pattern; franta-hg@46: import org.testng.annotations.Test; franta-hg@46: import static org.testng.Assert.*; franta-hg@46: franta-hg@46: /** franta-hg@46: * franta-hg@46: * @author Ing. František Kučera (frantovo.cz) franta-hg@46: */ franta-hg@46: public class FunctionsTest { franta-hg@46: franta-hg@46: @Test franta-hg@46: public void testEscapeRegEx() { franta-hg@46: for (String original : new String[]{"abcd", "1234", "xxx", "\\Eescape\\Q", "\\Qescape\\E", "abc\\Eescape\\Qdef.", ".", ""}) { franta-hg@51: String patternString = Pattern.quote(original); franta-hg@46: System.out.println(original + " → " + patternString); franta-hg@46: franta-hg@46: Pattern pattern = Pattern.compile(patternString); franta-hg@46: franta-hg@46: String testString; franta-hg@46: Matcher m; franta-hg@46: franta-hg@46: testString = original; franta-hg@46: m = pattern.matcher(testString); franta-hg@46: assertTrue(m.matches(), "Pattern does not match original string: " + testString); franta-hg@46: franta-hg@46: testString = original + "x"; franta-hg@46: m = pattern.matcher(testString); franta-hg@46: assertFalse(m.matches(), "Pattern matches wrong string: " + testString); franta-hg@46: franta-hg@46: testString = "x" + original; franta-hg@46: m = pattern.matcher(testString); franta-hg@46: assertFalse(m.matches(), "Pattern matches wrong string: " + testString); franta-hg@46: franta-hg@46: testString = (original + "ab").substring(1); franta-hg@46: m = pattern.matcher(testString); franta-hg@46: assertFalse(m.matches(), "Pattern matches wrong string: " + testString); franta-hg@46: } franta-hg@46: } franta-hg@46: }