|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * JSQLParser library |
| 4 | + * %% |
| 5 | + * Copyright (C) 2004 - 2019 JSQLParser |
| 6 | + * %% |
| 7 | + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 |
| 8 | + * #L% |
| 9 | + */ |
| 10 | +package net.sf.jsqlparser.parser; |
| 11 | + |
| 12 | +import static org.junit.jupiter.api.Assertions.*; |
| 13 | +import net.sf.jsqlparser.parser.AbstractJSqlParser.Dialect; |
| 14 | +import net.sf.jsqlparser.parser.feature.Feature; |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | + |
| 17 | +class DialectPresetIsolationTest { |
| 18 | + @Test |
| 19 | + void callersCannotMutateSharedPresets() { |
| 20 | + for (Dialect dialect : Dialect.values()) { |
| 21 | + assertThrows(UnsupportedOperationException.class, |
| 22 | + () -> dialect.getLexerFeatures().add(Feature.allowHashLineComments)); |
| 23 | + assertThrows(UnsupportedOperationException.class, |
| 24 | + () -> dialect.getLexerFeatures().clear()); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + void explicitParserOverridesAreLocalAndDoNotModifyPresetDefaults() { |
| 30 | + CCJSqlParser first = CCJSqlParserUtil.newParser("SELECT 1").withDialect(Dialect.MYSQL) |
| 31 | + .withHashLineComments(false); |
| 32 | + CCJSqlParser second = CCJSqlParserUtil.newParser("SELECT 1").withDialect(Dialect.MYSQL); |
| 33 | + assertFalse(first.getAsBoolean(Feature.allowHashLineComments)); |
| 34 | + assertTrue(second.getAsBoolean(Feature.allowHashLineComments)); |
| 35 | + assertTrue(Dialect.MYSQL.getLexerFeatures().contains(Feature.allowHashLineComments)); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + void preservesAdditivePresetApplicationAndExplicitOverrideOrder() { |
| 40 | + CCJSqlParser parser = CCJSqlParserUtil.newParser("SELECT 1").withDialect(Dialect.SQLSERVER) |
| 41 | + .withDialect(Dialect.POSTGRESQL); |
| 42 | + assertTrue(parser.getAsBoolean(Feature.allowSquareBracketQuotation)); |
| 43 | + parser.withSquareBracketQuotation(false); |
| 44 | + assertFalse(parser.getAsBoolean(Feature.allowSquareBracketQuotation)); |
| 45 | + assertFalse(CCJSqlParserUtil.newParser("SELECT 1").withDialect(Dialect.POSTGRESQL) |
| 46 | + .getAsBoolean(Feature.allowSquareBracketQuotation)); |
| 47 | + } |
| 48 | +} |
0 commit comments