From 21cb0fdd9573467e191f5bb853c0bd9fd10d8996 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Tue, 19 Oct 2021 01:01:39 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20query=20converter=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../theapache64/retrosheet/utils/TypeIdentifier.kt | 2 +- .../retrosheet/core/QueryConverterTest.kt | 13 +++++++++++++ .../theapache64/retrosheet/integration/ReadTest.kt | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/retrosheet/src/main/kotlin/com/github/theapache64/retrosheet/utils/TypeIdentifier.kt b/retrosheet/src/main/kotlin/com/github/theapache64/retrosheet/utils/TypeIdentifier.kt index f9c60e8..d13044f 100644 --- a/retrosheet/src/main/kotlin/com/github/theapache64/retrosheet/utils/TypeIdentifier.kt +++ b/retrosheet/src/main/kotlin/com/github/theapache64/retrosheet/utils/TypeIdentifier.kt @@ -31,6 +31,6 @@ object TypeIdentifier { } fun isNumber(value: String): Boolean { - return isDouble(value) + return isDouble(value) || isInteger(value) } } diff --git a/retrosheet/src/test/kotlin/com/github/theapache64/retrosheet/core/QueryConverterTest.kt b/retrosheet/src/test/kotlin/com/github/theapache64/retrosheet/core/QueryConverterTest.kt index 8f8c80b..84d785d 100644 --- a/retrosheet/src/test/kotlin/com/github/theapache64/retrosheet/core/QueryConverterTest.kt +++ b/retrosheet/src/test/kotlin/com/github/theapache64/retrosheet/core/QueryConverterTest.kt @@ -42,4 +42,17 @@ class QueryConverterTest { val actualOutput = QueryConverter(input, emptyMap(), paramMap).convert() actualOutput.should.equal("SELECT * WHERE foo = 'a' AND bar = 'b'") } + + @Test + fun `Strings are surrounded by single quotes and numbers are surrounded by nothing`() { + val input = + "SELECT * WHERE my_string = :my_string AND my_int = :my_int AND my_double = :my_double" + val paramMap = mapOf( + "my_string" to "com.truecaller", + "my_int" to "3", + "my_double" to "3.14" + ) + val actualOutput = QueryConverter(input, emptyMap(), paramMap).convert() + actualOutput.should.equal("SELECT * WHERE my_string = 'com.truecaller' AND my_int = 3 AND my_double = 3.14") + } } \ No newline at end of file diff --git a/src/test/java/com/github/theapache64/retrosheet/integration/ReadTest.kt b/src/test/java/com/github/theapache64/retrosheet/integration/ReadTest.kt index 2b3a63e..30165bf 100644 --- a/src/test/java/com/github/theapache64/retrosheet/integration/ReadTest.kt +++ b/src/test/java/com/github/theapache64/retrosheet/integration/ReadTest.kt @@ -15,7 +15,7 @@ class ReadTest { @Test fun `Reads data`() = runBlockingTest { - notesApi.getNote("Do not delete this row")?.description.should + notesApi.getNote("Do not delete this row").description.should .equal("This is custom desc") Unit }