Skip to content

Commit

Permalink
feat: add simple csv test to LvtAssignmentSuggester
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Jul 25, 2023
1 parent 764a50d commit 8a9d107
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ dependencies {

annotationProcessor(libs.recordBuilder.processor)
compileOnly(libs.recordBuilder.core)

testImplementation(libs.junit.core)
testImplementation(libs.junit.params)
}

publishing {
Expand All @@ -41,6 +44,10 @@ publishing {
}
}

tasks.test {
useJUnitPlatform()
}

tasks.register("printVersion") {
doLast {
println(project.version)
Expand Down
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ unpick = "2.3.0"
asm = "9.5"
recordBuilder = "37"

junit = "5.9.2"

[plugins]
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
licenser = { id = "org.cadixdev.licenser", version.ref = "licenser" }
Expand Down Expand Up @@ -52,6 +54,9 @@ hypo-mappings = { module = "dev.denwav.hypo:hypo-mappings" }
recordBuilder-processor = { module = "io.soabase.record-builder:record-builder-processor", version.ref = "recordBuilder" }
recordBuilder-core = { module = "io.soabase.record-builder:record-builder-core", version.ref = "recordBuilder" }

junit-core = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junit-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit" }

[bundles]
asm = ["asm", "asm-util", "asm-tree"]
hypo = ["hypo-model", "hypo-core", "hypo-asm", "hypo-hydrate", "hypo-asm-hydrate", "hypo-mappings"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* codebook is a remapper utility for the PaperMC project.
*
* Copyright (c) 2023 Kyle Wood (DenWav)
* Contributors
*
* This library 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 only, no later versions.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/

package io.papermc.codebook.lvt;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.objectweb.asm.tree.MethodInsnNode;

class LvtAssignmentSuggesterTest {

@ParameterizedTest
@CsvFileSource(resources = "/io/papermc/codebook/lvt/LvtAssignmentSuggesterTest.csv", numLinesToSkip = 1)
public void testSuggester(
final String methodName,
final String methodOwner,
final String methodDescriptor,
final String expectedName) {
final @Nullable String result = LvtAssignmentSuggester.suggestNameFromAssignment(
methodName, new MethodInsnNode(-1, methodOwner, methodName, methodDescriptor));
assertEquals(expectedName, result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Method Name, Method Owner, Method Descriptor, Expected Name
# generic methods
hashCode,io/paper/Paper,()I,hashCode
size,java/util/List,()I,size
length,[Ljava/lang/String,()I,len
freeze,net/minecraft/core/RegistryAccess,()Lnet/minecraft/core/RegistryAccess.Frozen;,frozen
# getters
getName,io/paper/Paper,()Ljava/lang/String;,name
getSuperLongDumName,io/paper/Paper,()Ljava/lang/String;,superLongDumName
getOrCreateSomething,io/paper/Paper,()Ljava/lang/String;,something
# as
asString,io/paper/Paper,()Ljava/lang/String;,string
asLevel,io/paper/paper,()Lnet/minecraft/Level;,level
# readLine
readLine,some/stream,()Ljava/lang/String;,line
# strings
split,java/lang/String,()Ljava/lang/String;,parts
split,com/google/common/base/Splitter,()Ljava/lang/String;,parts
repeat,java/lang/String,()Ljava/lang/String;,repeated
indexOf,java/lang/String,()I,index
lastIndexOf,java/lang/String,()I,index
substring,java/lang/String,()I,sub
codePointAt,java/lang/String,()I,code
trim,java/lang/String,()Ljava/lang/String;,trimmed
strip,java/lang/String,()Ljava/lang/String;,stripped
stripLeading,java/lang/String,()Ljava/lang/String;,stripped
stripTrailing,java/lang/String,()Ljava/lang/String;,stripped
stripIndent,java/lang/String,()Ljava/lang/String;,stripped
formatted,java/lang/String,()Ljava/lang/String;,formatted
# negative cases
getOrCreate,io/paper/Paper,()Ljava/lang/String;,
gettingBetter,io/paper/Paper,()Ljava/lang/String;,
as,io/paper/paper,()Ljava/lang/String;,
ass,io/paper/paper,()Ljava/lang/String;,

0 comments on commit 8a9d107

Please sign in to comment.