Skip to content

Commit

Permalink
for #2084, add QuoteCharacterTest
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Mar 25, 2019
1 parent 1cf1de8 commit 989944b
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public enum QuoteCharacter {
/**
* Get quote character.
*
* @param value value to get delimiter
* @param value value to be get quote character
* @return value of quote character
*/
public static QuoteCharacter getQuoteCharacter(final String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shardingsphere.core.parse;

import org.apache.shardingsphere.core.parse.antlr.AllAntlrTests;
import org.apache.shardingsphere.core.parse.hook.SPIParsingHookTest;
import org.apache.shardingsphere.core.parse.lexer.AllLexerTests;
import org.apache.shardingsphere.core.parse.parser.constant.AllConstantTests;
Expand All @@ -29,6 +30,7 @@

@RunWith(Suite.class)
@SuiteClasses({
AllAntlrTests.class,
AllLexerTests.class,
SQLUtilTest.class,
AllSQLTests.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.shardingsphere.core.parse.antlr;

import org.apache.shardingsphere.core.parse.antlr.constant.QuoteCharacterTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses(QuoteCharacterTest.class)
public final class AllAntlrTests {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.shardingsphere.core.parse.antlr.constant;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public final class QuoteCharacterTest {

@Test
public void assertGetStartDelimiter() {
assertThat(QuoteCharacter.BACK_QUOTE.getStartDelimiter(), is("`"));
assertThat(QuoteCharacter.SINGLE_QUOTE.getStartDelimiter(), is("'"));
assertThat(QuoteCharacter.QUOTE.getStartDelimiter(), is("\""));
assertThat(QuoteCharacter.BRACKETS.getStartDelimiter(), is("["));
assertThat(QuoteCharacter.NONE.getStartDelimiter(), is(""));
}

@Test
public void assertGetEndDelimiter() {
assertThat(QuoteCharacter.BACK_QUOTE.getEndDelimiter(), is("`"));
assertThat(QuoteCharacter.SINGLE_QUOTE.getEndDelimiter(), is("'"));
assertThat(QuoteCharacter.QUOTE.getEndDelimiter(), is("\""));
assertThat(QuoteCharacter.BRACKETS.getEndDelimiter(), is("]"));
assertThat(QuoteCharacter.NONE.getEndDelimiter(), is(""));
}

@Test
public void assertGetQuoteCharacterWithNullValue() {
assertThat(QuoteCharacter.getQuoteCharacter(null), is(QuoteCharacter.NONE));
}

@Test
public void assertGetQuoteCharacterWithEmptyValue() {
assertThat(QuoteCharacter.getQuoteCharacter(""), is(QuoteCharacter.NONE));
}

@Test
public void assertGetQuoteCharacterWithNone() {
assertThat(QuoteCharacter.getQuoteCharacter("tbl"), is(QuoteCharacter.NONE));
}

@Test
public void assertGetQuoteCharacterWithBackQuote() {
assertThat(QuoteCharacter.getQuoteCharacter("`tbl`"), is(QuoteCharacter.BACK_QUOTE));
}

@Test
public void assertGetQuoteCharacterWithSingleQuote() {
assertThat(QuoteCharacter.getQuoteCharacter("'tbl'"), is(QuoteCharacter.SINGLE_QUOTE));
}

@Test
public void assertGetQuoteCharacterWithQuote() {
assertThat(QuoteCharacter.getQuoteCharacter("\"tbl\""), is(QuoteCharacter.QUOTE));
}

@Test
public void assertGetQuoteCharacterWithBrackets() {
assertThat(QuoteCharacter.getQuoteCharacter("[tbl]"), is(QuoteCharacter.BRACKETS));
}
}

0 comments on commit 989944b

Please sign in to comment.