From 2154c9410064bd171c62126e8225ab8db745d377 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Mon, 14 Sep 2020 22:43:09 +0700 Subject: [PATCH] [Native] Add tests for resolvable properties --- compiler/util-io/build.gradle.kts | 3 +- .../properties/ResolvablePropertiesTests.kt | 74 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 compiler/util-io/test/org/jetbrains/kotlin/konan/properties/ResolvablePropertiesTests.kt diff --git a/compiler/util-io/build.gradle.kts b/compiler/util-io/build.gradle.kts index 1389a367926..2c6453178c6 100644 --- a/compiler/util-io/build.gradle.kts +++ b/compiler/util-io/build.gradle.kts @@ -7,11 +7,12 @@ description = "Kotlin/Native utils" dependencies { compile(kotlinStdlib()) + testImplementation(commonDep("junit:junit")) } sourceSets { "main" { projectDefault() } - "test" { none() } + "test" { projectDefault() } } publish() diff --git a/compiler/util-io/test/org/jetbrains/kotlin/konan/properties/ResolvablePropertiesTests.kt b/compiler/util-io/test/org/jetbrains/kotlin/konan/properties/ResolvablePropertiesTests.kt new file mode 100644 index 00000000000..bad1a5725a4 --- /dev/null +++ b/compiler/util-io/test/org/jetbrains/kotlin/konan/properties/ResolvablePropertiesTests.kt @@ -0,0 +1,74 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan.properties + +import org.junit.Assert.assertEquals +import org.junit.Test + +class ResolvablePropertiesTests { + + @Test + fun `trivial symbol resolve`() { + val props = propertiesOf( + "key1" to "value1", + "key2" to "\$key1" + ) + assertEquals("value1", props.resolvablePropertyString("key2")) + } + + @Test(expected = IllegalStateException::class) + fun `trivial circular dependency`() { + val props = propertiesOf( + "key1" to "\$key2", + "key2" to "\$key1" + ) + props.resolvablePropertyString("key2") + } + + @Test + fun `list and string should have the same behavior`() { + val props = propertiesOf( + "k1" to "v1", + "k2" to "v2 \$k1" + ) + assertEquals("v2 v1", props.resolvablePropertyString("k2")) + assertEquals("v2 v1", props.resolvablePropertyList("k2").joinToString(separator = " ")) + } + + @Test + fun `list expansion`() { + val props = propertiesOf( + "k1" to "v1 v2", + "k2" to "\$k1 v3", + "k3" to "\$k2" + ) + assertEquals(listOf("v1", "v2", "v3"), props.resolvablePropertyList("k3")) + } + + @Test + fun `double list expansion`() { + val props = propertiesOf( + "k1" to "v1 v2", + "k2" to "\$k1 \$k1" + ) + assertEquals(listOf("v1", "v2", "v1", "v2"), props.resolvablePropertyList("k2")) + } + + @Test(expected = IllegalStateException::class) + fun `self-reference`() { + val props = propertiesOf( + "k1" to "\$k1" + ) + props.resolvablePropertyString("k1") + } + + companion object { + private fun propertiesOf(vararg pairs: Pair): Properties = + Properties().also { + it.putAll(mapOf(*pairs)) + } + } +} \ No newline at end of file