/* * Copyright 2020-2022 JetBrains s.r.o. and respective authors and developers. * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. */ package org.jetbrains.compose.resources import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith import kotlin.test.assertNotEquals @OptIn(ExperimentalResourceApi::class) class ResourceTest { @Test fun testResourceEquals() = runBlockingTest { assertEquals(ImageResource("a"), ImageResource("a")) } @Test fun testResourceNotEquals() = runBlockingTest { assertNotEquals(ImageResource("a"), ImageResource("b")) } @Test fun testMissingResource() = runBlockingTest { assertFailsWith { readResourceBytes("missing.png") } val error = assertFailsWith { loadString(TestStringResource("unknown_id")) } assertEquals("String ID=`unknown_id` is not found!", error.message) } @Test fun testReadFileResource() = runBlockingTest { val bytes = readResourceBytes("strings.xml") assertEquals( """ Compose Resources App 😊 Hello world! Hello, %1${'$'}s! You have %2${'$'}d new messages. item 1 item 2 item 3 """.trimIndent(), bytes.decodeToString() ) } @Test fun testLoadStringResource() = runBlockingTest { assertEquals("Compose Resources App", loadString(TestStringResource("app_name"))) assertEquals( "Hello, test-name! You have 42 new messages.", loadString(TestStringResource("str_template"), "test-name", 42) ) assertEquals(listOf("item 1", "item 2", "item 3"), loadStringArray(TestStringResource("str_arr"))) } }