Skip to content

Commit

Permalink
Merge pull request #11 from thumbtack/arrayTypes
Browse files Browse the repository at this point in the history
Support *Array types
  • Loading branch information
brian-terczynski authored Jun 25, 2024
2 parents 4630981 + aed72c3 commit 7322891
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ private fun generateValueForSimpleField(
Short::class.java -> 0.toShort()
java.lang.Short::class.java -> 0.toShort()
java.time.Instant::class.java -> Instant.EPOCH
IntArray::class.java -> intArrayOf(0, 0, 0)
FloatArray::class.java -> floatArrayOf(0f, 0f, 0f)
DoubleArray::class.java -> doubleArrayOf(0.0, 0.0, 0.0)
ShortArray::class.java -> shortArrayOf(0, 0, 0)
ByteArray::class.java -> byteArrayOf(0, 0, 0)
CharArray::class.java -> charArrayOf('a', 'a', 'a')
LongArray::class.java -> longArrayOf(0L, 0L, 0L)
BooleanArray::class.java -> booleanArrayOf(false, false, false)
else -> (type as Class<*>).kotlin.generateTestObject(
fullyQualifiedParamName,
params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.thumbtack.kotlin.test

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class GenerateTestObjectTest {
class SampleClass(
Expand All @@ -12,6 +13,13 @@ class GenerateTestObjectTest {
val booleanField: Boolean,
val charField: Char,
val listField: List<String>,
val intArray: IntArray,
val floatArray: FloatArray,
val doubleArray: DoubleArray,
val booleanArray: BooleanArray,
val charArray: CharArray,
val shortArray: ShortArray,
val byteArray: ByteArray,
)

@Test
Expand All @@ -24,5 +32,22 @@ class GenerateTestObjectTest {
assertEquals(false, testObject.booleanField)
assertEquals('a', testObject.charField)
assertEquals(3, testObject.listField.size)
testObject.listField.forEachIndexed { index, item ->
assertEquals("listField${index}Value", item)
}
assertEquals(3, testObject.intArray.size)
assertTrue(testObject.intArray.all { it == 0 })
assertEquals(3, testObject.floatArray.size)
assertTrue(testObject.floatArray.all { it == 0f })
assertEquals(3, testObject.doubleArray.size)
assertTrue(testObject.doubleArray.all { it == 0.0 })
assertEquals(3, testObject.charArray.size)
assertTrue(testObject.charArray.all { it == 'a' })
assertEquals(3, testObject.shortArray.size)
assertTrue(testObject.shortArray.all { it == 0.toShort() })
assertEquals(3, testObject.byteArray.size)
assertTrue(testObject.byteArray.all { it == 0.toByte() })
assertEquals(3, testObject.booleanArray.size)
assertTrue(testObject.booleanArray.all { !it })
}
}

0 comments on commit 7322891

Please sign in to comment.