blob: 55b3a9acddac58b4af391a2b8bbfb8a859effb65 [file] [log] [blame]
// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.naming;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.android.tools.r8.CompilationFailedException;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.utils.SymbolGenerationUtils;
import com.android.tools.r8.utils.SymbolGenerationUtils.MixedCasing;
import com.android.tools.r8.utils.codeinspector.FoundClassSubject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class MinificationMixedCaseAndNumbersTest extends TestBase {
private static final int NUMBER_OF_MINIFIED_CLASSES = 60;
private final TestParameters parameters;
@Parameterized.Parameters(name = "{0}")
public static TestParametersCollection data() {
return getTestParameters().withAllRuntimes().build();
}
public MinificationMixedCaseAndNumbersTest(TestParameters parameters) {
this.parameters = parameters;
}
@Test
public void testNaming() throws ExecutionException, CompilationFailedException, IOException {
Set<String> allowedNames = new HashSet<>();
allowedNames.add("com.android.tools.r8.naming.MinificationMixedCaseAndNumbersTest$Main");
for (int i = 1; i < NUMBER_OF_MINIFIED_CLASSES; i++) {
String newString =
SymbolGenerationUtils.numberToIdentifier(i, MixedCasing.DONT_USE_MIXED_CASE);
assertFalse(Character.isDigit(newString.charAt(0)));
allowedNames.add("com.android.tools.r8.naming." + newString);
}
testForR8(parameters.getBackend())
.addInnerClasses(MinificationMixedCaseAndNumbersTest.class)
.addKeepMainRule(Main.class)
.noTreeShaking()
.addKeepRules("-dontusemixedcaseclassnames")
.setMinApi(parameters.getRuntime())
.run(parameters.getRuntime(), Main.class)
.inspect(
inspector -> {
List<FoundClassSubject> foundClassSubjects = new ArrayList<>(inspector.allClasses());
foundClassSubjects.forEach(
foundClazz -> {
assertTrue(allowedNames.contains(foundClazz.getFinalName()));
allowedNames.remove(foundClazz.getFinalName());
});
});
// The first identifier to use a number is 27 for MixedCasing.DONT_USE_MIXED_CASE.
assertTrue(allowedNames.isEmpty());
assertEquals(
"a0", SymbolGenerationUtils.numberToIdentifier(27, MixedCasing.DONT_USE_MIXED_CASE));
assertEquals(
"zz", SymbolGenerationUtils.numberToIdentifier(962, MixedCasing.DONT_USE_MIXED_CASE));
assertEquals(
"a00", SymbolGenerationUtils.numberToIdentifier(963, MixedCasing.DONT_USE_MIXED_CASE));
}
public static class A {}
public static class B {}
public static class C {}
public static class D {}
public static class E {}
public static class F {}
public static class G {}
public static class H {}
public static class I {}
public static class J {}
public static class K {}
public static class L {}
public static class M {}
public static class N {}
public static class O {}
public static class P {}
public static class Q {}
public static class R {}
public static class S {}
public static class T {}
public static class U {}
public static class V {}
public static class W {}
public static class X {}
public static class Y {}
public static class Z {}
public static class a {}
public static class b {}
public static class c {}
public static class d {}
public static class e {}
public static class f {}
public static class g {}
public static class h {}
public static class i {}
public static class j {}
public static class k {}
public static class l {}
public static class m {}
public static class n {}
public static class o {}
public static class p {}
public static class q {}
public static class r {}
public static class s {}
public static class t {}
public static class u {}
public static class v {}
public static class w {}
public static class x {}
public static class y {}
public static class z {}
public static class AA {}
public static class AB {}
public static class AC {}
public static class AD {}
public static class AE {}
public static class AF {}
public static class AG {}
public static class Main {
public static void main(String[] args) {
System.out.println("HELLO WORLD");
}
}
}