diff options
author | Jonas Herzig <me@johni0702.de> | 2022-05-24 15:15:35 +0200 |
---|---|---|
committer | Jonas Herzig <me@johni0702.de> | 2022-05-27 08:46:01 +0200 |
commit | 1cf68fed94337060df65a832d0c3c3f5588ad7cb (patch) | |
tree | 129f7862febd9b3fd349999391e6b37f2cf61ff0 /src/test | |
parent | 51cf5a796dbf3a185bb80044976dc8f32ebbf040 (diff) | |
download | Remap-1cf68fed94337060df65a832d0c3c3f5588ad7cb.tar.gz Remap-1cf68fed94337060df65a832d0c3c3f5588ad7cb.tar.bz2 Remap-1cf68fed94337060df65a832d0c3c3f5588ad7cb.zip |
Support varargs as parameters to @Pattern
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/kotlin/com/replaymod/gradle/remap/pattern/TestVarArgs.kt | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestVarArgs.kt b/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestVarArgs.kt new file mode 100644 index 0000000..a9caa15 --- /dev/null +++ b/src/test/kotlin/com/replaymod/gradle/remap/pattern/TestVarArgs.kt @@ -0,0 +1,192 @@ +package com.replaymod.gradle.remap.pattern + +import com.replaymod.gradle.remap.util.TestData +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +class TestVarArgs { + @Test + fun `should find varargs method`() { + TestData.remap(""" + class Test { + private void test() { + method(); + method("1"); + method("1", "2"); + method("1", "2", null); + method(new String[0]); + method("1", "2", 3); + } + } + """.trimIndent(), """ + @remap.Pattern + private String pattern(String...args) { + return method(args); + } + """.trimIndent(), """ + @remap.Pattern + private String pattern(String...args) { + return matched(args); + } + """.trimIndent()) shouldBe """ + class Test { + private void test() { + matched(); + matched("1"); + matched("1", "2"); + matched("1", "2", null); + matched(new String[0]); + method("1", "2", 3); + } + } + """.trimIndent() + } + + @Test + fun `should find varargs method with fixed leading argument`() { + TestData.remap(""" + class Test { + private void test() { + method(42); + method(42, "1"); + method(42, "1", "2"); + method(42, "1", "2", null); + method(42, new String[0]); + method(42, "1", "2", 3); + } + } + """.trimIndent(), """ + @remap.Pattern + private String pattern(String...args) { + return method(42, args); + } + """.trimIndent(), """ + @remap.Pattern + private String pattern(String...args) { + return matched(42, args); + } + """.trimIndent()) shouldBe """ + class Test { + private void test() { + matched(42); + matched(42, "1"); + matched(42, "1", "2"); + matched(42, "1", "2", null); + matched(42, new String[0]); + method(42, "1", "2", 3); + } + } + """.trimIndent() + } + + @Test + fun `should find varargs method with variable leading argument`() { + TestData.remap(""" + class Test { + private void test() { + method(42); + method(43, "1"); + method(44, "1", "2"); + method(45, "1", "2", null); + method(46, new String[0]); + method(47, "1", "2", 3); + } + } + """.trimIndent(), """ + @remap.Pattern + private String pattern(int i, String...args) { + return method(i, args); + } + """.trimIndent(), """ + @remap.Pattern + private String pattern(int i, String...args) { + return matched(i, args); + } + """.trimIndent()) shouldBe """ + class Test { + private void test() { + matched(42); + matched(43, "1"); + matched(44, "1", "2"); + matched(45, "1", "2", null); + matched(46, new String[0]); + method(47, "1", "2", 3); + } + } + """.trimIndent() + } + + @Test + fun `should allow leading argument to be removed`() { + TestData.remap(""" + class Test { + private void test() { + method(42); + method(42, "1"); + method(42, "1", "2"); + method(42, "1", "2", null); + method(42, new String[0]); + method(42, "1", "2", 3); + } + } + """.trimIndent(), """ + @remap.Pattern + private String pattern(String...args) { + return method(42, args); + } + """.trimIndent(), """ + @remap.Pattern + private String pattern(String...args) { + return matched(args); + } + """.trimIndent()) shouldBe """ + class Test { + private void test() { + matched(); + matched("1"); + matched("1", "2"); + matched("1", "2", null); + matched(new String[0]); + method(42, "1", "2", 3); + } + } + """.trimIndent() + } + + @Test + fun `should allow leading argument to be added`() { + TestData.remap(""" + class Test { + private void test() { + method(); + method("1"); + method("1", "2"); + method("1", "2", null); + method(new String[0]); + method("1", "2", 3); + } + } + """.trimIndent(), """ + @remap.Pattern + private String pattern(String...args) { + return method(args); + } + """.trimIndent(), """ + @remap.Pattern + private String pattern(String...args) { + return matched(42, args); + } + """.trimIndent()) shouldBe """ + class Test { + private void test() { + matched(42); + matched(42, "1"); + matched(42, "1", "2"); + matched(42, "1", "2", null); + matched(42, new String[0]); + method("1", "2", 3); + } + } + """.trimIndent() + } +}
\ No newline at end of file |