Skip to content

Commit 9527693

Browse files
committed
LocalDateSerializerUnitTest.kt: fix unparseableDash() to not include numbers as "invalid" characters because they become "valid" when adjacent to other numeric digits.
1 parent a0a02a7 commit 9527693

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

firebase-dataconnect/src/test/kotlin/com/google/firebase/dataconnect/serializers/LocalDateSerializerUnitTest.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ class LocalDateSerializerUnitTest {
101101
@Test
102102
fun `deserialize() should throw IllegalArgumentException when given unparseable strings`() =
103103
runTest {
104-
checkAll(propTestConfig, Arb.unparseableDate()) { encodedDate ->
104+
val seededPropTestConfig = propTestConfig.copy(seed=-7108070269336260794)
105+
checkAll(seededPropTestConfig, Arb.unparseableDate()) { encodedDate ->
105106
val decoder: Decoder = mockk { every { decodeString() } returns encodedDate }
106-
shouldThrow<IllegalArgumentException> { LocalDateSerializer.deserialize(decoder) }
107+
shouldThrow<IllegalArgumentException> {
108+
val deserializedDate = LocalDateSerializer.deserialize(decoder)
109+
println("zzyzx deserializedDate=$deserializedDate")
110+
}
107111
}
108112
}
109113

@@ -205,7 +209,11 @@ class LocalDateSerializerUnitTest {
205209
}
206210

207211
fun Arb.Companion.unparseableDash(): Arb<String> {
208-
val invalidString = string(1..5, codepoints.filterNot { it.value == '-'.code })
212+
val invalidString =
213+
string(
214+
1..5,
215+
codepoints.filterNot { it.value == '-'.code || it.value in '0'.code..'9'.code }
216+
)
209217
return arbitrary { rs ->
210218
val flags = Array(3) { rs.random.nextBoolean() }
211219
if (!flags[0]) {
@@ -225,7 +233,10 @@ class LocalDateSerializerUnitTest {
225233
val unparseableNumber = unparseableNumber()
226234
val unparseableDash = unparseableDash()
227235
val booleanArray = booleanArray(Arb.constant(5), Arb.boolean())
236+
var count = 0
228237
return arbitrary(edgecases = listOf("", "-", "--", "---")) { rs ->
238+
count++
239+
println("count=$count")
229240
val invalidCharFlags = booleanArray.bind()
230241
if (invalidCharFlags.count { it } == 0) {
231242
invalidCharFlags[rs.random.nextInt(invalidCharFlags.indices)] = true

0 commit comments

Comments
 (0)