User: kyle wood Date: 27 Nov 26 06:16 Revision: e5ff5ed95e8881d95b7cb8f99b4a58ddcc0085fa Summary: Add some test cases that aren't handled correctly TeamCity URL: http://ci.mcdev.io:80/viewModification.html?tab=vcsModificationFiles&modId=10824&personal=false Index: src/test/kotlin/platform/minecraft/unpick/UnpickClassReferenceTest.kt =================================================================== --- src/test/kotlin/platform/minecraft/unpick/UnpickClassReferenceTest.kt (revision 4386bb995c4ad6c9a9fe6ce5906a6f32fab8af7a) +++ src/test/kotlin/platform/minecraft/unpick/UnpickClassReferenceTest.kt (revision e5ff5ed95e8881d95b7cb8f99b4a58ddcc0085fa) @@ -23,8 +23,11 @@ import com.demonwav.mcdev.framework.BaseMinecraftTest import com.demonwav.mcdev.framework.EdtInterceptor import com.intellij.psi.JavaPsiFacade +import com.intellij.psi.PsiMember +import com.intellij.psi.PsiModifier import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.searches.ReferencesSearch +import com.intellij.refactoring.JavaRefactoringFactory import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName @@ -71,7 +74,6 @@ unpick v4 group int com.example.Outer${'$'}Middle${'$'}Inner.INNER_VALUE - com.example.Outer.OUTER_VALUE target_field com.example.Outer${'$'}Middle${'$'}Inner INNER_VALUE I Foo """, configure = false, @@ -109,7 +111,7 @@ @Test @DisplayName("Find Usages Of Outer Class") fun findUsagesOfOuterClass() { - Assertions.assertEquals(3, usagesInUnpick("com.example.Outer").size) + Assertions.assertEquals(2, usagesInUnpick("com.example.Outer").size) } @Test @@ -120,6 +122,66 @@ Assertions.assertEquals(2, text.split("Outer\$Middle\$Renamed").size - 1, text) } + @Test + @DisplayName("Move Outer Class Keeps Nested Class Names") + fun moveOuterClass() { + val file = fixture.addFileToProject( + "move.unpick", + """ + unpick v4 + group int + com.example.Outer.OUTER_VALUE + com.example.Outer${'$'}Middle${'$'}Inner.INNER_VALUE + target_field com.example.Outer${'$'}Middle${'$'}Inner INNER_VALUE I Foo + """.trimIndent(), + ) + + val factory = JavaRefactoringFactory.getInstance(project) + val destination = factory.createSourceFolderPreservingMoveDestination("com.other") + factory.createMoveClassesOrPackages(arrayOf(findClass("com.example.Outer")), destination).run() + + Assertions.assertEquals( + """ + unpick v4 + group int + com.other.Outer.OUTER_VALUE + com.other.Outer${'$'}Middle${'$'}Inner.INNER_VALUE + target_field com.other.Outer${'$'}Middle${'$'}Inner INNER_VALUE I Foo + """.trimIndent(), + file.text, + ) + } + + @Test + @DisplayName("Move Field Updates Owner Class") + fun moveField() { + fixture.addClass("package com.example;\n\npublic class Other {\n}") + val file = fixture.addFileToProject( + "move_field.unpick", + """ + unpick v4 + group int + com.example.Outer.OUTER_VALUE + target_field com.example.Outer OUTER_VALUE I Foo + """.trimIndent(), + ) + + val field = findClass("com.example.Outer").findFieldByName("OUTER_VALUE", false)!! + JavaRefactoringFactory.getInstance(project) + .createMoveMembers(arrayOf(field), "com.example.Other", PsiModifier.PUBLIC) + .run() + + Assertions.assertEquals( + """ + unpick v4 + group int + com.example.Other.OUTER_VALUE + target_field com.example.Other OUTER_VALUE I Foo + """.trimIndent(), + file.text, + ) + } + private fun complete(text: String): List { fixture.configureByText("complete.unpick", text) return fixture.completeBasic()?.map { it.lookupString }.orEmpty() Index: src/test/kotlin/platform/minecraft/unpick/UnpickInvalidNameTest.kt =================================================================== --- src/test/kotlin/platform/minecraft/unpick/UnpickInvalidNameTest.kt (revision e5ff5ed95e8881d95b7cb8f99b4a58ddcc0085fa) +++ src/test/kotlin/platform/minecraft/unpick/UnpickInvalidNameTest.kt (revision e5ff5ed95e8881d95b7cb8f99b4a58ddcc0085fa) @@ -0,0 +1,67 @@ +/* + * Minecraft Development for IntelliJ + * + * https://mcdev.io/ + * + * Copyright (C) 2026 minecraft-dev + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, version 3.0 only. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.demonwav.mcdev.platform.minecraft.unpick + +import com.demonwav.mcdev.framework.EdtInterceptor +import com.demonwav.mcdev.framework.ProjectBuilderTest +import com.demonwav.mcdev.platform.minecraft.unpick.gen.psi.UnpickGroupDefinition +import com.demonwav.mcdev.platform.minecraft.unpick.psi.UnpickElementFactory +import com.intellij.psi.util.PsiTreeUtil +import com.intellij.refactoring.rename.RenameUtil +import com.intellij.util.IncorrectOperationException +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.api.extension.ExtendWith + +/** + * Unpick identifiers are ASCII only, but the platform and Java accept any Java identifier as a new name. + */ +@ExtendWith(EdtInterceptor::class) +@DisplayName("Unpick Invalid Name Tests") +class UnpickInvalidNameTest : ProjectBuilderTest() { + + @Test + @DisplayName("Group Rename Rejects Non-ASCII Names") + fun groupRenameRejectsNonAsciiNames() { + val file = fixture.configureByText("groups.unpick", "unpick v4\ngroup int Color\n 1\n") + val definition = PsiTreeUtil.findChildOfType(file, UnpickGroupDefinition::class.java)!! + + Assertions.assertTrue(RenameUtil.isValidName(project, definition, "Colour")) + Assertions.assertFalse(RenameUtil.isValidName(project, definition, "Colör")) + } + + @Test + @DisplayName("Element Factory Rejects Non-ASCII Names") + fun elementFactoryRejectsNonAsciiNames() { + Assertions.assertAll( + { assertThrows { UnpickElementFactory.createIdentifier(project, "Colör") } }, + { assertThrows { UnpickElementFactory.createIdentifier(project, "Écran") } }, + { + assertThrows { + UnpickElementFactory.createClassName(project, "com.example.Écran") + } + }, + { assertThrows { UnpickElementFactory.createFieldName(project, "VALÜE") } }, + ) + } +} Index: src/test/kotlin/platform/minecraft/unpick/UnpickReferenceFixturesTest.kt =================================================================== --- src/test/kotlin/platform/minecraft/unpick/UnpickReferenceFixturesTest.kt (revision 4386bb995c4ad6c9a9fe6ce5906a6f32fab8af7a) +++ src/test/kotlin/platform/minecraft/unpick/UnpickReferenceFixturesTest.kt (revision e5ff5ed95e8881d95b7cb8f99b4a58ddcc0085fa) @@ -61,7 +61,9 @@ @Test @DisplayName("Invalid Reference Fixtures") fun invalidFixtures() { - val failures = fixtures("invalid").mapNotNull { file -> + val files = fixtures("invalid") + Assertions.assertEquals(emptySet(), EXPECTED_MESSAGES.keys - files.mapTo(HashSet()) { it.name }) + val failures = files.mapNotNull { file -> val errors = errorsIn(file) val expected = EXPECTED_MESSAGES[file.name] when { @@ -76,7 +78,7 @@ private companion object { val EXPECTED_MESSAGES = mapOf( "other_missing_header.unpick" to "Missing version marker, expected 'unpick v4' on the first line", - "whitespace_before_first_line.unpick" to + "whitespace_whitespace_before_first_line.unpick" to "Missing version marker, expected 'unpick v4' on the first line", "whitespace_comment_on_first_line.unpick" to "The first line must be exactly 'unpick v3'", "syntax_target_annotation_unpick_v3.unpick" to "Target annotations require unpick v4",