Skip to content

Commit 7451f85

Browse files
committed
add tests for unquoted filters cases
1 parent c51e4c4 commit 7451f85

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/commonMain/kotlin/com/algolia/search/model/filter/FilterInternals.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ internal fun Filter.Facet.Value.toLegacy(isNegated: Boolean, escape: Boolean): S
100100

101101
internal fun Filter.Facet.toLegacy(escape: Boolean): List<String> {
102102
val value = value.toLegacy(isNegated, escape)
103-
val attribute = attribute.escape()
103+
val attribute = if (escape) attribute.escape() else attribute.raw
104104
val score = if (score != null) "<score=$score>" else ""
105105

106106
return listOf("$attribute:$value$score")

src/commonTest/kotlin/model/filter/TestFilterFacetString.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ internal class TestFilterFacetString {
2828
FilterConverter.Legacy(filterSpace) shouldEqual listOf("\"attributeA\":\"value with space\"")
2929
FilterConverter.Legacy(filterScore) shouldEqual listOf("\"attributeA\":\"valueA\"<score=1>")
3030
}
31+
32+
@Test
33+
fun legacyUnquoted() {
34+
FilterConverter.Legacy.Unquoted(filter) shouldEqual listOf("attributeA:valueA")
35+
FilterConverter.Legacy.Unquoted(filterNegate) shouldEqual listOf("attributeA:-valueA")
36+
FilterConverter.Legacy.Unquoted(filterSpace) shouldEqual listOf("attributeA:value with space")
37+
FilterConverter.Legacy.Unquoted(filterScore) shouldEqual listOf("attributeA:valueA<score=1>")
38+
}
3139
}

src/commonTest/kotlin/model/filter/TestFilterNumericRange.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ internal class TestFilterNumericRange {
3030
FilterConverter.Legacy(filterDouble) shouldEqual listOf("\"attributeA\" >= 0.0", "\"attributeA\" <= 6.0")
3131
FilterConverter.Legacy(!filterDouble) shouldEqual listOf("\"attributeA\" < 0.0", "\"attributeA\" > 6.0")
3232
}
33+
34+
@Test
35+
fun legacyUnquoted() {
36+
FilterConverter.Legacy.Unquoted(filterNumericInt) shouldEqual listOf("attributeA >= 0", "attributeA <= 5")
37+
FilterConverter.Legacy.Unquoted(filterNumericLong) shouldEqual listOf("attributeA >= 0", "attributeA <= 6")
38+
FilterConverter.Legacy.Unquoted(filterFloat) shouldEqual listOf("attributeA >= 0.0", "attributeA <= 6.0")
39+
FilterConverter.Legacy.Unquoted(filterDouble) shouldEqual listOf("attributeA >= 0.0", "attributeA <= 6.0")
40+
FilterConverter.Legacy.Unquoted(!filterDouble) shouldEqual listOf("attributeA < 0.0", "attributeA > 6.0")
41+
}
3342
}

src/commonTest/kotlin/model/filter/TestFilterTag.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ internal class TestFilterTag {
2020
FilterConverter.Legacy(filter) shouldEqual listOf("_tags:\"valueA\"")
2121
FilterConverter.Legacy(!filter) shouldEqual listOf("_tags:-\"valueA\"")
2222
}
23+
24+
@Test
25+
fun legacyUnquoted() {
26+
FilterConverter.Legacy.Unquoted(filter) shouldEqual listOf("_tags:valueA")
27+
FilterConverter.Legacy.Unquoted(!filter) shouldEqual listOf("_tags:-valueA")
28+
}
2329
}

0 commit comments

Comments
 (0)