diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..e0f15db
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "java.configuration.updateBuildConfiguration": "automatic"
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 1c8b051..9207918 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,52 +54,6 @@
test
-
- org.openjdk.jmh
- jmh-generator-annprocess
- 1.33
- test
-
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
- ${kotlin.version}
- test
-
-
- org.spekframework.spek2
- spek-dsl-jvm
- ${spek_version}
- test
-
-
- org.spekframework.spek2
- spek-runner-junit5
- ${spek_version}
- test
-
-
- org.jetbrains.kotlin
- kotlin-reflect
- ${kotlin.version}
- test
-
-
-
- org.jetbrains.kotlin
- kotlin-test-junit
- ${kotlin.version}
- test
-
-
-
- org.amshove.kluent
- kluent
- 1.68
- test
-
-
@@ -121,6 +75,7 @@
UTF-8
+
org.apache.maven.plugins
maven-compiler-plugin
@@ -130,6 +85,7 @@
1.8
+
maven-source-plugin
2.1.2
@@ -143,6 +99,7 @@
+
maven-javadoc-plugin
3.1.0
@@ -178,40 +135,6 @@
-
- org.jetbrains.kotlin
- kotlin-maven-plugin
- ${kotlin.version}
-
-
- test-compile
- test-compile
-
- test-compile
-
-
-
-
-
-
- org.codehaus.mojo
- build-helper-maven-plugin
- 3.0.0
-
-
- generate-test-sources
-
- add-test-source
-
-
-
- src/test/kotlin
-
-
-
-
-
-
com.diffplug.spotless
spotless-maven-plugin
@@ -227,15 +150,6 @@
-
-
- src/test/kotlin/**/*.kt
-
-
- 0.39
-
-
-
diff --git a/src/main/java/com/github/vertical_blank/sqlformatter/languages/StandardSqlFormatter.java b/src/main/java/com/github/vertical_blank/sqlformatter/languages/StandardSqlFormatter.java
index 311fa38..2f712a5 100644
--- a/src/main/java/com/github/vertical_blank/sqlformatter/languages/StandardSqlFormatter.java
+++ b/src/main/java/com/github/vertical_blank/sqlformatter/languages/StandardSqlFormatter.java
@@ -379,7 +379,7 @@ public DialectConfig dialectConfig() {
.indexedPlaceholderTypes(Collections.singletonList("?"))
.namedPlaceholderTypes(Collections.emptyList())
.lineCommentTypes(Arrays.asList("--"))
- .operators(Collections.singletonList("||"))
+ .operators(List.of("||", "!="))
.build();
}
diff --git a/src/test/java/com/github/vertical_blank/sqlformatter/Benchmark.java b/src/test/java/com/github/vertical_blank/sqlformatter/Benchmark.java
deleted file mode 100644
index 6cd595e..0000000
--- a/src/test/java/com/github/vertical_blank/sqlformatter/Benchmark.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.github.vertical_blank.sqlformatter;
-
-import java.util.concurrent.TimeUnit;
-import org.openjdk.jmh.annotations.*;
-import org.openjdk.jmh.runner.Runner;
-import org.openjdk.jmh.runner.RunnerException;
-import org.openjdk.jmh.runner.options.Options;
-import org.openjdk.jmh.runner.options.OptionsBuilder;
-
-@BenchmarkMode(Mode.AverageTime)
-@OutputTimeUnit(TimeUnit.NANOSECONDS)
-@State(Scope.Benchmark)
-public class Benchmark {
-
- public static final String SQL =
- "SELECT foo, bar, CASE baz WHEN 'one' THEN 1 WHEN 'two' THEN 2 ELSE 3 END FROM table";
-
- public static void main(String[] args) throws RunnerException {
- Options opt = new OptionsBuilder().include(Benchmark.class.getSimpleName()).forks(1).build();
-
- new Runner(opt).run();
- }
-
- @org.openjdk.jmh.annotations.Benchmark
- public void format() {
- SqlFormatter.format(SQL);
- }
-}
diff --git a/src/test/java/com/github/vertical_blank/sqlformatter/MariaDbFormatterTest.java b/src/test/java/com/github/vertical_blank/sqlformatter/MariaDbFormatterTest.java
new file mode 100644
index 0000000..bf21971
--- /dev/null
+++ b/src/test/java/com/github/vertical_blank/sqlformatter/MariaDbFormatterTest.java
@@ -0,0 +1,84 @@
+package com.github.vertical_blank.sqlformatter;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import com.github.vertical_blank.sqlformatter.languages.Dialect;
+import org.junit.jupiter.api.Test;
+
+public class MariaDbFormatterTest {
+
+ private final SqlFormatter.Formatter formatter = SqlFormatter.of(Dialect.MariaDb);
+
+ @Test
+ public void testSupportsCase() {
+ String result = formatter.format("CASE WHEN a THEN b ELSE c END");
+ String expected = "CASE\n WHEN a THEN b\n ELSE c\nEND";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsCreateTable() {
+ String result = formatter.format("CREATE TABLE foo (id INT PRIMARY KEY, name VARCHAR(100))");
+ String expected = "CREATE TABLE foo (id INT PRIMARY KEY, name VARCHAR(100))";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsAlterTable() {
+ String result = formatter.format("ALTER TABLE foo ADD COLUMN bar INT");
+ String expected = "ALTER TABLE\n foo\nADD\n COLUMN bar INT";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsStrings() {
+ String result = formatter.format("SELECT \"foo\", 'bar', `baz` FROM table");
+ String expected = "SELECT\n \"foo\",\n 'bar',\n `baz`\nFROM\n table";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsBetween() {
+ String result = formatter.format("SELECT * FROM table WHERE a BETWEEN 1 AND 10");
+ String expected = "SELECT\n *\nFROM\n table\nWHERE\n a BETWEEN 1 AND 10";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsOperators() {
+ String result =
+ formatter.format("SELECT a % b & c | d ^ e ~ f != g ! h <=> i << j >> k && l || m := n");
+ String expected = "SELECT\n a % b & c | d ^ e ~ f != g ! h <=> i << j >> k && l || m := n";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsJoin() {
+ String result =
+ formatter.format("SELECT * FROM table1 STRAIGHT_JOIN table2 NATURAL LEFT JOIN table3");
+ String expected =
+ "SELECT\n *\nFROM\n table1\n STRAIGHT_JOIN table2\n NATURAL LEFT JOIN table3";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsHashComments() {
+ String result = formatter.format("SELECT a # comment\nFROM b # comment");
+ String expected = "SELECT\n a # comment\nFROM\n b # comment";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsVariables() {
+ String result = formatter.format("SELECT @foo, @bar");
+ String expected = "SELECT\n @foo,\n @bar";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsSettingVariables() {
+ String result = formatter.format("SET @foo := (SELECT * FROM tbl);");
+ String expected = "SET\n @foo := (\n SELECT\n *\n FROM\n tbl\n );";
+ assertEquals(expected, result);
+ }
+}
diff --git a/src/test/java/com/github/vertical_blank/sqlformatter/PostgreSqlFormatterTest.java b/src/test/java/com/github/vertical_blank/sqlformatter/PostgreSqlFormatterTest.java
new file mode 100644
index 0000000..08bb122
--- /dev/null
+++ b/src/test/java/com/github/vertical_blank/sqlformatter/PostgreSqlFormatterTest.java
@@ -0,0 +1,104 @@
+package com.github.vertical_blank.sqlformatter;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import com.github.vertical_blank.sqlformatter.languages.Dialect;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+public class PostgreSqlFormatterTest {
+
+ private final SqlFormatter.Formatter formatter = SqlFormatter.of(Dialect.PostgreSql);
+
+ @Test
+ public void testSupportsCase() {
+ String result = formatter.format("CASE WHEN a THEN b ELSE c END");
+ String expected = "CASE\n WHEN a THEN b\n ELSE c\nEND";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsCreateTable() {
+ String result = formatter.format("CREATE TABLE foo (id INT PRIMARY KEY, name VARCHAR(100))");
+ String expected = "CREATE TABLE foo (id INT PRIMARY KEY, name VARCHAR(100))";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsAlterTable() {
+ String result = formatter.format("ALTER TABLE foo ADD COLUMN bar INT");
+ String expected = "ALTER TABLE\n foo\nADD\n COLUMN bar INT";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsStrings() {
+ String result = formatter.format("SELECT \"foo\", 'bar', $$baz$$ FROM table");
+ String expected = "SELECT\n \"foo\",\n 'bar',\n $$baz$$\nFROM\n table";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsBetween() {
+ String result = formatter.format("SELECT * FROM table WHERE a BETWEEN 1 AND 10");
+ String expected = "SELECT\n *\nFROM\n table\nWHERE\n a BETWEEN 1 AND 10";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsSchema() {
+ String result = formatter.format("SELECT * FROM schema.table");
+ String expected = "SELECT\n *\nFROM\n schema.table";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsOperators() {
+ String result =
+ formatter.format(
+ "SELECT a % b ^ c ! d !! e @ f != g & h | i ~ j # k << l >> m ||/ n |/ o :: p ->> q -> r ~~* s ~~ t !~~* u !~~ v ~* w !~* x !~ y @@ z @@@ aa");
+ String expected =
+ "SELECT\n a % b ^ c ! d !! e @ f != g & h | i ~ j # k << l >> m ||/ n |/ o :: p ->> q -> r ~~* s ~~ t !~~* u !~~ v ~* w !~* x !~ y @@ z @@@ aa";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsJoin() {
+ String result = formatter.format("SELECT * FROM table1 JOIN table2 ON table1.id = table2.id");
+ String expected = "SELECT\n *\nFROM\n table1\n JOIN table2 ON table1.id = table2.id";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsDollarPlaceholders() {
+ String result = formatter.format("SELECT $1, $2 FROM tbl");
+ String expected = "SELECT\n $1,\n $2\nFROM\n tbl";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testReplacesDollarPlaceholdersWithParamValues() {
+ String result =
+ formatter.format(
+ "SELECT $1, $2 FROM tbl", Map.of("1", "\"variable value\"", "2", "\"blah\""));
+ String expected = "SELECT\n \"variable value\",\n \"blah\"\nFROM\n tbl";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testSupportsNamePlaceholders() {
+ String result = formatter.format("foo = :bar");
+ String expected = "foo = :bar";
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testReplacesNamePlaceholdersWithParamValues() {
+ String result =
+ formatter.format(
+ "foo = :bar AND :\"field\" = 10 OR col = :'val'",
+ Map.of("bar", "'Hello'", "field", "some_col", "val", 7));
+ String expected = "foo = 'Hello'\nAND some_col = 10\nOR col = 7";
+ assertEquals(expected, result);
+ }
+}
diff --git a/src/test/java/com/github/vertical_blank/sqlformatter/SqlFormatterTest.java b/src/test/java/com/github/vertical_blank/sqlformatter/SqlFormatterTest.java
index 55b3b7f..9e3960e 100644
--- a/src/test/java/com/github/vertical_blank/sqlformatter/SqlFormatterTest.java
+++ b/src/test/java/com/github/vertical_blank/sqlformatter/SqlFormatterTest.java
@@ -85,4 +85,10 @@ public void withLambdasParams() {
format,
"SELECT\n" + " aggregate(array(1, 2, 3), 0, (acc, x) -> acc + x, acc -> acc * 10);");
}
+
+ @Test
+ public void withNotEquals() {
+ final String format = SqlFormatter.format("SELECT * FROM TEST WHERE ABC != '4'");
+ assertEquals(format, "SELECT\n" + " *\n" + "FROM\n" + " TEST\n" + "WHERE\n" + " ABC != '4'");
+ }
}
diff --git a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/AlterTable.kt b/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/AlterTable.kt
deleted file mode 100644
index 5128ce4..0000000
--- a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/AlterTable.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.github.vertical_blank.sqlformatter.features
-
-import com.github.vertical_blank.sqlformatter.SqlFormatter
-import com.github.vertical_blank.sqlformatter.expect
-import org.spekframework.spek2.style.specification.Suite
-
-fun Suite.supportsAlterTable(formatter: SqlFormatter.Formatter) {
- with(formatter) {
- it("formats ALTER TABLE ... ALTER COLUMN query") {
- val result = format("ALTER TABLE supplier ALTER COLUMN supplier_name VARCHAR(100) NOT NULL;")
- expect(result)
- .toBe(
- """
- ALTER TABLE
- supplier
- ALTER COLUMN
- supplier_name VARCHAR(100) NOT NULL;
- """.trimIndent()
- )
- }
- }
-}
diff --git a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/AlterTableModify.kt b/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/AlterTableModify.kt
deleted file mode 100644
index 702c719..0000000
--- a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/AlterTableModify.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.github.vertical_blank.sqlformatter.features
-
-import com.github.vertical_blank.sqlformatter.SqlFormatter
-import com.github.vertical_blank.sqlformatter.expect
-import org.spekframework.spek2.style.specification.Suite
-
-fun Suite.supportsAlterTableModify(formatter: SqlFormatter.Formatter) {
- with(formatter) {
- it("formats ALTER TABLE ... MODIFY statement") {
- val result = format("ALTER TABLE supplier MODIFY supplier_name char(100) NOT NULL;")
- expect(result)
- .toBe(
- """
- ALTER TABLE
- supplier
- MODIFY
- supplier_name char(100) NOT NULL;
- """.trimIndent()
- )
- }
- }
-}
diff --git a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Between.kt b/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Between.kt
deleted file mode 100644
index 4004bc2..0000000
--- a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Between.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.github.vertical_blank.sqlformatter.features
-
-import com.github.vertical_blank.sqlformatter.SqlFormatter
-import com.github.vertical_blank.sqlformatter.expect
-import org.spekframework.spek2.style.specification.Suite
-
-fun Suite.supportsBetween(formatter: SqlFormatter.Formatter) {
- with(formatter) {
- it("formats BETWEEN _ AND _ on single line") {
- expect(format("foo BETWEEN bar AND baz")).toBe("foo BETWEEN bar AND baz")
- }
- }
-}
diff --git a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Case.kt b/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Case.kt
deleted file mode 100644
index 77eb3bb..0000000
--- a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Case.kt
+++ /dev/null
@@ -1,123 +0,0 @@
-package com.github.vertical_blank.sqlformatter.features
-
-import com.github.vertical_blank.sqlformatter.SqlFormatter
-import com.github.vertical_blank.sqlformatter.core.FormatConfig
-import com.github.vertical_blank.sqlformatter.expect
-import org.spekframework.spek2.style.specification.Suite
-
-fun Suite.supportsCase(formatter: SqlFormatter.Formatter) {
- with(formatter) {
- it("formats CASE ... WHEN with a blank expression") {
- val result =
- format(
- "CASE WHEN option = 'foo' THEN 1 WHEN option = 'bar' THEN 2 WHEN option = 'baz' THEN 3 ELSE 4 END;"
- )
-
- expect(result)
- .toBe(
- """
- CASE
- WHEN option = 'foo' THEN 1
- WHEN option = 'bar' THEN 2
- WHEN option = 'baz' THEN 3
- ELSE 4
- END;
- """.trimIndent()
- )
- }
-
- it("formats CASE ... WHEN with an expression") {
- val result =
- format(
- "CASE toString(getNumber()) WHEN 'one' THEN 1 WHEN 'two' THEN 2 WHEN 'three' THEN 3 ELSE 4 END;"
- )
-
- expect(result)
- .toBe(
- """
- CASE
- toString(getNumber())
- WHEN 'one' THEN 1
- WHEN 'two' THEN 2
- WHEN 'three' THEN 3
- ELSE 4
- END;
- """.trimIndent()
- )
- }
-
- it("formats CASE ... WHEN inside SELECT") {
- val result =
- format(
- "SELECT foo, bar, CASE baz WHEN 'one' THEN 1 WHEN 'two' THEN 2 ELSE 3 END FROM table"
- )
-
- expect(result)
- .toBe(
- """
- SELECT
- foo,
- bar,
- CASE
- baz
- WHEN 'one' THEN 1
- WHEN 'two' THEN 2
- ELSE 3
- END
- FROM
- table
- """.trimIndent()
- )
- }
-
- it("recognizes lowercase CASE ... END") {
- val result = format("case when option = 'foo' then 1 else 2 end;")
-
- expect(result)
- .toBe(
- """
- case
- when option = 'foo' then 1
- else 2
- end;
- """.trimIndent()
- )
- }
-
- // Regression test for issue #43
- it("ignores words CASE and END inside other strings") {
- val result = format("SELECT CASEDATE, ENDDATE FROM table1;")
-
- expect(result)
- .toBe(
- """
- SELECT
- CASEDATE,
- ENDDATE
- FROM
- table1;
- """.trimIndent()
- )
- }
-
- it("properly converts to uppercase in case statements") {
- val result =
- format(
- "case toString(getNumber()) when 'one' then 1 when 'two' then 2 when 'three' then 3 else 4 end;",
- FormatConfig.builder().uppercase(true).build()
- )
- expect(result)
- .toBe(
- """
- CASE
- toString(getNumber())
- WHEN 'one' THEN 1
- WHEN 'two' THEN 2
- WHEN 'three' THEN 3
- ELSE 4
- END;
- """.trimIndent()
- )
- }
- }
-}
diff --git a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/CreateTable.kt b/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/CreateTable.kt
deleted file mode 100644
index 289d6df..0000000
--- a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/CreateTable.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.github.vertical_blank.sqlformatter.features
-
-import com.github.vertical_blank.sqlformatter.SqlFormatter
-import com.github.vertical_blank.sqlformatter.expect
-import org.spekframework.spek2.style.specification.Suite
-
-fun Suite.supportsCreateTable(formatter: SqlFormatter.Formatter) {
- with(formatter) {
- it("formats short CREATE TABLE") {
- expect(format("CREATE TABLE items (a INT PRIMARY KEY, b TEXT);"))
- .toBe("CREATE TABLE items (a INT PRIMARY KEY, b TEXT);")
- }
-
- // The decision to place it to multiple lines is made based on the length of text inside
- // BRACEs
- // ignoring the whitespace. (Which is not quite right :P)
- it("formats long CREATE TABLE") {
- expect(
- format(
- "CREATE TABLE items (a INT PRIMARY KEY, b TEXT, c INT NOT NULL, doggie INT NOT NULL);"
- )
- )
- .toBe(
- """
- CREATE TABLE items (
- a INT PRIMARY KEY,
- b TEXT,
- c INT NOT NULL,
- doggie INT NOT NULL
- );
- """.trimIndent()
- )
- }
- }
-}
diff --git a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Join.kt b/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Join.kt
deleted file mode 100644
index 8a613d8..0000000
--- a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Join.kt
+++ /dev/null
@@ -1,74 +0,0 @@
-package com.github.vertical_blank.sqlformatter.features
-
-import com.github.vertical_blank.sqlformatter.SqlFormatter
-import com.github.vertical_blank.sqlformatter.expect
-import kotlin.collections.listOf
-import org.spekframework.spek2.style.specification.Suite
-
-fun Suite.supportsJoin(
- formatter: SqlFormatter.Formatter,
- without: List = listOf(),
- additionally: List = listOf()
-) {
- with(formatter) {
- val unsupportedJoinRegex =
- if (without.isNotEmpty()) without.joinToString("|") else "^whateve_!%&$"
- val isSupportedJoin = { join: String -> unsupportedJoinRegex.toRegex().find(join) == null }
-
- listOf("CROSS JOIN", "NATURAL JOIN").filter(isSupportedJoin).forEach { join ->
- it("supports $join") {
- val result = format("SELECT * FROM tbl1 $join tbl2")
- expect(result)
- .toBe(
- """
- SELECT
- *
- FROM
- tbl1
- $join tbl2
- """.trimIndent()
- )
- }
- }
-
- // ::= [ ] JOIN
- //
- // ::= INNER | [ OUTER ]
- //
- // ::= LEFT | RIGHT | FULL
-
- (listOf(
- "JOIN",
- "INNER JOIN",
- "LEFT JOIN",
- "LEFT OUTER JOIN",
- "RIGHT JOIN",
- "RIGHT OUTER JOIN",
- "FULL JOIN",
- "FULL OUTER JOIN",
- ) + additionally)
- .filter(isSupportedJoin)
- .forEach { join ->
- it("supports $join") {
- val result =
- format(
- """
- SELECT customer_id.from, COUNT(order_id) AS total FROM customers
- $join orders ON customers.customer_id = orders.customer_id;
- """.trimIndent()
- )
- expect(result)
- .toBe(
- """
- SELECT
- customer_id.from,
- COUNT(order_id) AS total
- FROM
- customers
- $join orders ON customers.customer_id = orders.customer_id;
- """.trimIndent()
- )
- }
- }
- }
-}
diff --git a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Operators.kt b/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Operators.kt
deleted file mode 100644
index 09da5ee..0000000
--- a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Operators.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.github.vertical_blank.sqlformatter.features
-
-import com.github.vertical_blank.sqlformatter.SqlFormatter
-import com.github.vertical_blank.sqlformatter.expect
-import org.spekframework.spek2.style.specification.Suite
-
-fun Suite.supportsOperators(formatter: SqlFormatter.Formatter, operators: List) {
- with(formatter) {
- operators.forEach { op ->
- it("supports $op operator") { expect(format("foo${op}bar")).toBe("foo $op bar") }
- }
- }
-}
diff --git a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Schema.kt b/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Schema.kt
deleted file mode 100644
index d41d28e..0000000
--- a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Schema.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.github.vertical_blank.sqlformatter.features
-
-import com.github.vertical_blank.sqlformatter.SqlFormatter
-import com.github.vertical_blank.sqlformatter.expect
-import org.spekframework.spek2.style.specification.Suite
-
-fun Suite.supportsSchema(formatter: SqlFormatter.Formatter) {
- with(formatter) {
- it("formats simple SET SCHEMA statements") {
- val result = format("SET SCHEMA schema1;")
- expect(result).toBe("""
- SET SCHEMA
- schema1;
- """.trimIndent())
- }
- }
-}
diff --git a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Strings.kt b/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Strings.kt
deleted file mode 100644
index b1f9584..0000000
--- a/src/test/kotlin/com/github/vertical_blank/sqlformatter/features/Strings.kt
+++ /dev/null
@@ -1,90 +0,0 @@
-package com.github.vertical_blank.sqlformatter.features
-
-import com.github.vertical_blank.sqlformatter.SqlFormatter
-import com.github.vertical_blank.sqlformatter.expect
-import com.github.vertical_blank.sqlformatter.languages.StringLiteral
-import org.spekframework.spek2.style.specification.Suite
-
-fun Suite.supportsStrings(formatter: SqlFormatter.Formatter, stringTypes: List = listOf()) {
- with(formatter) {
- if (stringTypes.contains(StringLiteral.DOUBLE_QUOTE)) {
- it("supports double-quoted strings") {
- expect(format(""""foo JOIN bar"""")).toBe(""""foo JOIN bar"""")
- expect(format(""""foo \" JOIN bar"""")).toBe(""""foo \" JOIN bar"""")
- }
- }
-
- if (stringTypes.contains(StringLiteral.SINGLE_QUOTE)) {
- it("supports single-quoted strings") {
- expect(format("'foo JOIN bar'")).toBe("'foo JOIN bar'")
- expect(format("'foo \\' JOIN bar'")).toBe("'foo \\' JOIN bar'")
- }
- }
-
- if (stringTypes.contains(StringLiteral.BACK_QUOTE)) {
- it("supports backtick-quoted strings") {
- expect(format("`foo JOIN bar`")).toBe("`foo JOIN bar`")
- expect(format("`foo `` JOIN bar`")).toBe("`foo `` JOIN bar`")
- }
- }
-
- if (stringTypes.contains(StringLiteral.U_DOUBLE_QUOTE)) {
- it("supports unicode double-quoted strings") {
- expect(format("""U&"foo JOIN bar"""")).toBe("""U&"foo JOIN bar"""")
- expect(format("""U&"foo \" JOIN bar"""")).toBe("""U&"foo \" JOIN bar"""")
- }
- }
-
- if (stringTypes.contains(StringLiteral.U_SINGLE_QUOTE)) {
- it("supports single-quoted strings") {
- expect(format("U&'foo JOIN bar'")).toBe("U&'foo JOIN bar'")
- expect(format("U&'foo \\' JOIN bar'")).toBe("U&'foo \\' JOIN bar'")
- }
- }
-
- if (stringTypes.contains(StringLiteral.DOLLAR)) {
- it("supports DOLLAR-quoted strings") {
- expect(format("\$xxx\$foo \$\$ LEFT JOIN \$yyy\$ bar\$xxx\$"))
- .toBe("\$xxx\$foo \$\$ LEFT JOIN \$yyy\$ bar\$xxx\$")
- expect(format("\$\$foo JOIN bar\$\$")).toBe("\$\$foo JOIN bar\$\$")
- expect(format("\$\$foo \$ JOIN bar\$\$")).toBe("\$\$foo $ JOIN bar\$\$")
- expect(format("\$\$foo \n bar\$\$")).toBe("\$\$foo \n bar\$\$")
- }
- }
-
- if (stringTypes.contains(StringLiteral.BRACKET)) {
- it("supports [BRACKET-quoted identifiers]") {
- expect(format("[foo JOIN bar]")).toBe("[foo JOIN bar]")
- expect(format("[foo ]] JOIN bar]")).toBe("[foo ]] JOIN bar]")
- }
- }
-
- if (stringTypes.contains(StringLiteral.N_SINGLE_QUOTE)) {
- it("supports T-SQL unicode strings") {
- expect(format("N'foo JOIN bar'")).toBe("N'foo JOIN bar'")
- expect(format("N'foo \\' JOIN bar'")).toBe("N'foo \\' JOIN bar'")
- }
- }
-
- if (stringTypes.contains(StringLiteral.Q_SINGLE_QUOTE)) {
- it("supports Oracle quotation operator") {
- expect(format("Q'[I'm boy]',Q'{I'm boy}',Q'',Q'(I'm boy)',1"))
- .toBe(
- """Q'[I'm boy]',
- |Q'{I'm boy}',
- |Q'',
- |Q'(I'm boy)',
- |1""".trimMargin()
- )
- expect(format("NQ'[I'm boy]',NQ'{I'm boy}',NQ'',NQ'(I'm boy)',1"))
- .toBe(
- """NQ'[I'm boy]',
- |NQ'{I'm boy}',
- |NQ'',
- |NQ'(I'm boy)',
- |1""".trimMargin()
- )
- }
- }
- }
-}