-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from cassandra-scala/feature/127-cql3.3-specs
Adds specs for case insensitivity
- Loading branch information
Showing
4 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
cql-parser/src/test/scala/troy/cql3_3/lexical/CaseSensitivityParsingSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package troy.cql3_3.lexical | ||
|
||
import org.scalatest.{ FlatSpec, Matchers } | ||
import troy.cql.ast.dml.Select.{ ColumnName, SelectionClauseItem, SelectClause } | ||
import troy.cql.parser.ParserTestUtils._ | ||
|
||
// http://docs.datastax.com/en/cql/3.3/cql/cql_reference/ucase-lcase_r.html | ||
class CaseSensitivityParsingSpec extends FlatSpec with Matchers { | ||
// TODO: https://github.com/cassandra-scala/troy/issues/128 | ||
"lower case columns in queries" should "be parsed" in { | ||
parseSelect("SELECT foo FROM test;").selection shouldBe SelectClause(Seq(SelectionClauseItem(ColumnName("foo"), None))) | ||
} | ||
|
||
"capitalized columns in queries" should "be parsed as lowercase" ignore { | ||
parseSelect("SELECT Foo FROM test;").selection shouldBe SelectClause(Seq(SelectionClauseItem(ColumnName("foo"), None))) | ||
} | ||
|
||
"uppercase columns in queries" should "be parsed as lowercase" ignore { | ||
parseSelect("SELECT FOO FROM test;").selection shouldBe SelectClause(Seq(SelectionClauseItem(ColumnName("foo"), None))) | ||
} | ||
|
||
"quoted capitalized columns in queries" should "be parsed as capitalized" ignore { | ||
parseSelect("""SELECT "Bar" FROM test;""").selection shouldBe SelectClause(Seq(SelectionClauseItem(ColumnName("Bar"), None))) | ||
} | ||
|
||
"quoted uppercase columns in queries" should "be parsed as uppercase" ignore { | ||
parseSelect("""SELECT "BAR" FROM test;""").selection shouldBe SelectClause(Seq(SelectionClauseItem(ColumnName("BAR"), None))) | ||
} | ||
|
||
"quoted lowercase columns in queries" should "be parsed as lowercase" ignore { | ||
parseSelect("""SELECT "bar" FROM test;""").selection shouldBe SelectClause(Seq(SelectionClauseItem(ColumnName("bar"), None))) | ||
} | ||
|
||
"quoted lowercase columns in schema" should "be parsed as lowercase" ignore { | ||
val columns = parseCreateTable( | ||
""" | ||
| CREATE TABLE test ( | ||
| Foo int PRIMARY KEY, | ||
| "Bar" TEXT, | ||
| "baR" UUID, | ||
| "baz" timestamp | ||
| ); | ||
""".stripMargin).columns | ||
|
||
columns(0).name shouldBe "foo" | ||
columns(1).name shouldBe "Bar" | ||
columns(2).name shouldBe "baR" | ||
columns(3).name shouldBe "baz" | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
troy-schema/src/test/scala/troy/cql3_3/lexical/CaseSensitivitySchemaSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package troy.cql3_3.lexical | ||
|
||
import org.scalatest._ | ||
import troy.cql.ast.DataType | ||
import troy.schema.SchemaTestUtils._ | ||
|
||
// http://docs.datastax.com/en/cql/3.3/cql/cql_reference/ucase-lcase_r.html | ||
class CaseSensitivitySchemaSpec extends FlatSpec with Matchers { | ||
// TODO: https://github.com/cassandra-scala/troy/issues/128 | ||
|
||
implicit lazy val schema = buildSchema( | ||
""" | ||
| CREATE TABLE test ( | ||
| Foo int PRIMARY KEY, | ||
| "Bar" TEXT, | ||
| "baR" UUID, | ||
| "baz" timestamp | ||
| ); | ||
""".stripMargin | ||
) | ||
|
||
"lower case query" should "work with non-quoted capitalised schema" ignore { | ||
columnsOf("SELECT foo FROM test;").head shouldBe DataType.Int | ||
} | ||
|
||
"quoted capitalised query" should "not work with non-quoted capitalised schema" ignore { | ||
errorOf("""SELECT "Foo" FROM test;""") shouldBe "Undefined name Foo in selection clause" | ||
} | ||
|
||
"non-quoted capitalised query" should "work with non-quoted capitalised schema" ignore { | ||
columnsOf("SELECT Foo FROM test;").head shouldBe DataType.Int | ||
} | ||
|
||
"non-quoted uppercase query" should "work with non-quoted capitalised schema" ignore { | ||
columnsOf("SELECT FOO FROM test;").head shouldBe DataType.Int | ||
} | ||
|
||
"quoted capitalised query" should "work with quoted capitalised schema" ignore { | ||
columnsOf("""SELECT "Bar" FROM test;""").head shouldBe DataType.Text | ||
} | ||
|
||
"quoted uppercase query" should "not work with quoted capitalised schema" ignore { | ||
errorOf("""SELECT "BAR" FROM test;""") shouldBe "Undefined name BAR in selection clause" | ||
} | ||
|
||
"non-quoted capitalised query" should "not work with quoted capitalised schema" ignore { | ||
errorOf("SELECT Bar FROM test;") shouldBe "Undefined name bar in selection clause" | ||
} | ||
|
||
"quoted lowercase query" should "not work with quoted capitalised schema" ignore { | ||
errorOf("""SELECT "bar" FROM test;""") shouldBe "Undefined name bar in selection clause" | ||
} | ||
|
||
"quoted query" should "not mix similar columns but different case" ignore { | ||
columnsOf("""SELECT "baR" FROM test;""").head shouldBe DataType.Uuid | ||
} | ||
|
||
"non-quoted lowercase query" should "work with quoted lowercase column" ignore { | ||
columnsOf("""SELECT baz FROM test;""").head shouldBe DataType.Timestamp | ||
} | ||
|
||
"non-quoted capitalised query" should "work with quoted lowercase column" ignore { | ||
columnsOf("""SELECT Baz FROM test;""").head shouldBe DataType.Timestamp | ||
} | ||
|
||
"non-quoted uppercase query" should "work with quoted lowercase column" ignore { | ||
columnsOf("""SELECT BAZ FROM test;""").head shouldBe DataType.Timestamp | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
troy-schema/src/test/scala/troy/schema/SchemaTestUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package troy.schema | ||
|
||
import org.scalatest.{ FlatSpec, Matchers } | ||
import troy.cql.parser.ParserTestUtils.{ parseSchema, parseQuery } | ||
import VTestUtils._ | ||
import troy.schema.SchemaEngine.Columns | ||
|
||
object SchemaTestUtils extends FlatSpec with Matchers { | ||
def buildSchema(versionedStatements: String*) = | ||
VersionedSchemaEngine(versionedStatements.map(parseSchema)).get | ||
|
||
def analyse(query: String)(implicit schema: VersionedSchemaEngine) = | ||
schema(parseQuery(query)) | ||
|
||
def columnsOf(query: String)(implicit schema: VersionedSchemaEngine) = | ||
analyse(query).get._1.asInstanceOf[Columns].types | ||
|
||
def errorsOf(query: String)(implicit schema: VersionedSchemaEngine) = | ||
analyse(query).getErrors | ||
|
||
def errorOf(query: String)(implicit schema: VersionedSchemaEngine) = | ||
analyse(query).getError.message | ||
} |