Skip to content

Commit 85f1ce5

Browse files
committed
test(ai): add tests for enums with values
1 parent 7cecce1 commit 85f1ce5

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

firebase-ai/src/test/java/com/google/firebase/ai/SchemaTests.kt

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,15 @@ internal class SchemaTests {
220220
}
221221

222222
enum class TestEnum {
223-
BASIC,
224-
INTERMEDIATE,
225-
ADVANCED
223+
RED,
224+
GREEN,
225+
BLUE
226+
}
227+
228+
enum class TestEnumWithValues(val someValue: String) {
229+
RED("FF0000"),
230+
GREEN("00FF00"),
231+
BLUE("0000FF")
226232
}
227233

228234
@Test
@@ -233,7 +239,7 @@ internal class SchemaTests {
233239
{
234240
"type": "STRING",
235241
"format": "enum",
236-
"enum": ["BASIC", "INTERMEDIATE", "ADVANCED"]
242+
"enum": ["RED", "GREEN", "BLUE"]
237243
}
238244
"""
239245
.trimIndent()
@@ -249,7 +255,39 @@ internal class SchemaTests {
249255
{
250256
"type": "STRING",
251257
"format": "enum",
252-
"enum": ["BASIC", "INTERMEDIATE", "ADVANCED"]
258+
"enum": ["RED", "GREEN", "BLUE"]
259+
}
260+
"""
261+
.trimIndent()
262+
263+
Json.encodeToString(schema.toInternal()).shouldEqualJson(expectedJson)
264+
}
265+
266+
@Test
267+
fun `Kotlin enum with values`() {
268+
val schema = Schema.fromEnum<TestEnumWithValues>()
269+
val expectedJson =
270+
"""
271+
{
272+
"type": "STRING",
273+
"format": "enum",
274+
"enum": ["RED", "GREEN", "BLUE"]
275+
}
276+
"""
277+
.trimIndent()
278+
279+
Json.encodeToString(schema.toInternal()).shouldEqualJson(expectedJson)
280+
}
281+
282+
@Test
283+
fun `Java enum with values`() {
284+
val schema = Schema.fromEnum(TestEnumWithValues::class.java)
285+
val expectedJson =
286+
"""
287+
{
288+
"type": "STRING",
289+
"format": "enum",
290+
"enum": ["RED", "GREEN", "BLUE"]
253291
}
254292
"""
255293
.trimIndent()

0 commit comments

Comments
 (0)