Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
PiTheGuy committed Feb 25, 2025
1 parent e1c9d89 commit e72ab83
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.quiltmc.enigma;

import org.junit.jupiter.api.Test;
import org.quiltmc.enigma.api.Enigma;
import org.quiltmc.enigma.api.EnigmaProject;
import org.quiltmc.enigma.api.ProgressListener;
import org.quiltmc.enigma.api.class_provider.JarClassProvider;
import org.quiltmc.enigma.api.source.DecompiledClassSource;
import org.quiltmc.enigma.api.source.Decompiler;
import org.quiltmc.enigma.api.source.Decompilers;
import org.quiltmc.enigma.api.source.SourceSettings;
import org.quiltmc.enigma.api.source.Token;
import org.quiltmc.enigma.api.source.TokenType;
import org.quiltmc.enigma.api.translation.representation.entry.ClassEntry;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;

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

public class TestTokensSimilarClassNames {
private static final Path JAR = TestUtil.obfJar("similar_class_names");

@Test
public void testSimilarClassNames() throws IOException {
EnigmaProject project = openProject();
ClassEntry alpha = TestEntryFactory.newClass(getClassName("Alpha"));
Decompiler decompiler = Decompilers.VINEFLOWER.create(new JarClassProvider(JAR), new SourceSettings(false, false));
DecompiledClassSource decomp = new DecompiledClassSource(alpha, decompiler.getUndocumentedSource(getClassName("Alpha")).index());
DecompiledClassSource source = decomp.remapSource(project, project.getRemapper().getDeobfuscator());
Collection<Token> tokens = source.getHighlightedTokens().get(TokenType.OBFUSCATED);
for (Token token : tokens) {
assertFalse(token.text.startsWith("Alphabet"));
}
}

private static String getClassName(String className) {
return "org/quiltmc/enigma/input/similar_class_names/" + className;
}

private static EnigmaProject openProject() {
try {
Enigma enigma = Enigma.create();
return enigma.openJar(JAR, new JarClassProvider(JAR), ProgressListener.createEmpty());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.quiltmc.enigma.input.similar_class_names;

public interface Alpha {
char get(int n);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.quiltmc.enigma.input.similar_class_names;

public class Alphabet {
public static class Inner {
public Alpha get() {
return new Alpha() {
@Override
public char get(int n) {
return 0;
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.quiltmc.enigma.input.similar_class_names;

public class Caller {
public void call() {
new Alphabet.Inner().get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-repackageclasses
-allowaccessmodification
-dontoptimize
-dontshrink
-keepparameternames
-keepattributes
-keep class org.quiltmc.enigma.input.Keep
-keep class org.quiltmc.enigma.input.similar_class_names.*

0 comments on commit e72ab83

Please sign in to comment.