/* * Copyright (c) 2016 Tada AB and other contributors, as listed below. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the The BSD 3-Clause License * which accompanies this distribution, and is available at * http://opensource.org/licenses/BSD-3-Clause * * Contributors: * Chapman Flack */ package org.postgresql.pljava; import java.util.regex.Matcher; import junit.framework.TestCase; import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.*; import static org.postgresql.pljava.sqlgen.Lexicals.ISO_AND_PG_IDENTIFIER_CAPTURING; import static org.postgresql.pljava.sqlgen.Lexicals.identifierFrom; import org.postgresql.pljava.sqlgen.Lexicals.Identifier; public class LexicalsTest extends TestCase { public LexicalsTest(String name) { super(name); } public void testIdentifierFrom() throws Exception { Matcher m = ISO_AND_PG_IDENTIFIER_CAPTURING.matcher("anIdentifier"); assertTrue("i", m.matches()); assertEquals("anIdentifier", identifierFrom(m).nonFolded()); m.reset("\"an\"\"Identifier\"\"\""); assertTrue("xd", m.matches()); assertEquals("an\"Identifier\"", identifierFrom(m).nonFolded()); m.reset("u&\"an\\0049dent\"\"if\\+000069er\""); assertTrue("xui2", m.matches()); assertEquals("anIdent\"ifier", identifierFrom(m).nonFolded()); m.reset("u&\"an@@\"\"@0049dent@+000069fier\"\"\" uescape '@'"); assertTrue("xui3", m.matches()); assertEquals("an@\"Identifier\"", identifierFrom(m).nonFolded()); } public void testIdentifierEquivalence() throws Exception { Identifier baà = Identifier.from("baÃ", false); Identifier Baà = Identifier.from("BaÃ", false); Identifier bass = Identifier.from("bass", false); Identifier BASS = Identifier.from("BASS", false); Identifier qbaà = Identifier.from("baÃ", true); Identifier qBaà = Identifier.from("BaÃ", true); Identifier qbass = Identifier.from("bass", true); Identifier qBASS = Identifier.from("BASS", true); Identifier sab = Identifier.from("sopran alt baÃ", true); Identifier SAB = Identifier.from("Sopran Alt BaÃ", true); /* DESERET SMALL LETTER OW */ Identifier ow = Identifier.from("\uD801\uDC35", false); /* DESERET CAPITAL LETTER OW */ Identifier OW = Identifier.from("\uD801\uDC0D", false); assertEquals("hash1", baÃ.hashCode(), BaÃ.hashCode()); assertEquals("hash2", baÃ.hashCode(), bass.hashCode()); assertEquals("hash3", baÃ.hashCode(), BASS.hashCode()); assertEquals("hash4", baÃ.hashCode(), qbaÃ.hashCode()); assertEquals("hash5", baÃ.hashCode(), qBaÃ.hashCode()); assertEquals("hash6", baÃ.hashCode(), qbass.hashCode()); assertEquals("hash7", baÃ.hashCode(), qBASS.hashCode()); assertEquals("hash8", ow.hashCode(), OW.hashCode()); assertEquals("eq1", baÃ, BaÃ); assertEquals("eq2", baÃ, bass); assertEquals("eq3", baÃ, BASS); assertEquals("eq4", BaÃ, qbaÃ); assertEquals("eq5", BaÃ, qBASS); assertEquals("eq6", ow, OW); assertThat("ne1", BaÃ, not(equalTo(qBaÃ))); assertThat("ne2", BaÃ, not(equalTo(qbass))); assertThat("ne3", sab, not(equalTo(SAB))); } }