Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #10548: Migrate to Inline Config Parser in MagicNumberCheckTest #10645

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,6 @@

<exclude>**/NoCodeInFileCheckTest.class</exclude>

<exclude>**/MagicNumberCheckTest.class</exclude>

<exclude>**/HexFloatsTest.class</exclude>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public void testDefault()
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"236:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_1.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_1.java"), expected);
}

@Test
Expand Down Expand Up @@ -136,7 +137,8 @@ public void testIgnoreSome()
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_2.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_2.java"), expected);
}

@Test
Expand Down Expand Up @@ -214,7 +216,8 @@ public void testIgnoreNone()
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"245:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_3.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_3.java"), expected);
}

@Test
Expand Down Expand Up @@ -263,7 +266,8 @@ public void testIntegersOnly()
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_4.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_4.java"), expected);
}

@Test
Expand Down Expand Up @@ -308,7 +312,8 @@ public void testIgnoreNegativeOctalHex() throws Exception {
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_5.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_5.java"), expected);
}

@Test
Expand Down Expand Up @@ -359,7 +364,8 @@ public void testIgnoreHashCodeMethod() throws Exception {
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_6.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_6.java"), expected);
}

@Test
Expand Down Expand Up @@ -402,7 +408,8 @@ public void testIgnoreFieldDeclaration()
"211:48: " + getCheckMessage(MSG_KEY, "-45"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_7.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_7.java"), expected);
}

@Test
Expand Down Expand Up @@ -465,7 +472,8 @@ public void testWaiverParentToken()
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber.java"), expected);
}

@Test
Expand All @@ -480,7 +488,7 @@ public void testMagicNumberRecordsDefault()
"29:29: " + getCheckMessage(MSG_KEY, "8"),
"33:20: " + getCheckMessage(MSG_KEY, "10"),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputMagicNumberRecordsDefault.java"), expected);
}

Expand All @@ -496,7 +504,7 @@ public void testMagicNumberIgnoreFieldDeclarationRecords()
"29:29: " + getCheckMessage(MSG_KEY, "8"),
"33:20: " + getCheckMessage(MSG_KEY, "10"),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputMagicNumberIgnoreFieldDeclarationRecords.java"),
expected);
}
Expand All @@ -510,6 +518,7 @@ public void testIgnoreInAnnotationElementDefault() throws Exception {
"18:29: " + getCheckMessage(MSG_KEY, "10"),
"19:33: " + getCheckMessage(MSG_KEY, "11"),
};
verify(checkConfig, getPath("InputMagicNumberAnnotationElement.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumberAnnotationElement.java"), expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0; // violation
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5; // violation

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down Expand Up @@ -154,7 +154,7 @@ class InputComplexButNotFlagged
public final Integer DefaultInit = new Integer(27); // violation
public final int SpecsPerDay = 24 * 60 * 60, SpecialRatio = 4 / 3;
public final javax.swing.border.Border StdBorder =
javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3); // violation
javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3); // 4 violations
}

enum MyEnum2
Expand Down Expand Up @@ -189,7 +189,7 @@ public int hashcode() {
}

{
int y=37;
int y=37; // violation
}

public TestHashCodeMethod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0; // violation
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5; // violation

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
MagicNumber
ignoreNumbers = 0,1,3.0,8,16,3000
ignoreNumbers = 0, 1, 3.0, 8, 16, 3000
ignoreHashCodeMethod = (default)false
ignoreAnnotation = true
ignoreFieldDeclaration = (default)false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,32 @@ public void magicMethod() {
int int_var2 = (2); // violation
long long_var1 = 0L; // violation
long long_var2 = 0l; // violation
double double_var1 = 0D; // ok
double double_var2 = 0d; // ok
double double_var1 = 0D; // ok // violation
double double_var2 = 0d; // ok // violation

int[] int_array = new int[2]; // violation

int_var1 = 1 + 2; // violation
int_var1 = 1 + 2; // 2 violations
int_var1 += 1; // violation
double_var1 = 1.0 + 2.0; // violation
double_var1 = 1.0 + 2.0; // 2 violations

for (int i = 0; i < 2; i++); // violation
for (int i = 0; i < 2; i++); // 2 violations

if (1 < 2); // violation
if (1 < 2); // 2 violations

if (1.0 < 2.0); // violation
if (1.0 < 2.0); // 2 violations


int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0; // violation
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5; // violation

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0;
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5;

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0;
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5;

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down Expand Up @@ -112,7 +112,7 @@ class Signed_5
public static final int CONST_PLUS_THREE = +3;
public static final int CONST_MINUS_TWO = -2;
private int mPlusThree = +3; // violation
private int mMinusTwo = -2; // violation
private int mMinusTwo = -2;
private double mPlusDecimal = +3.5;
private double mMinusDecimal = -2.5;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0; // violation
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5; // violation

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0; // violation
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5; // violation

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down