Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenLooman committed Jul 26, 2024
1 parent ba5457c commit 72109b8
Show file tree
Hide file tree
Showing 37 changed files with 421 additions and 500 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,5 @@ private void checkComment(final Token token) {
token.getColumn() + matcher.end(1),
message);
}

// this.getForbiddenWords().stream()
// .forEach(
// word -> {
// int fromIndex = 0;
// while (fromIndex != -1) {
// fromIndex = comment.indexOf(word, fromIndex);
// if (fromIndex == -1) {
// break;
// }

// final String message = String.format(MESSAGE, word);
// this.addIssue(
// token.getLine(),
// token.getColumn() + fromIndex,
// token.getLine(),
// token.getColumn() + fromIndex + word.length(),
// message);

// fromIndex += word.length();
// }
// });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ void testTooManyMethods() {
final FileMethodCountCheck check = new FileMethodCountCheck();
check.maxMethodCount = 2;
final String code =
""
+ "_method a.m1 _endmethod\n"
+ "_method a.m1 _endmethod\n"
+ "_method a.m1 _endmethod\n";
"""
_method a.m1 _endmethod
_method a.m1 _endmethod
_method a.m1 _endmethod
""";
final List<MagikIssue> issues = this.runCheck(code, check);
assertThat(issues).hasSize(1);
}
Expand All @@ -28,10 +29,11 @@ void testOk() {
final FileMethodCountCheck check = new FileMethodCountCheck();
check.maxMethodCount = 10;
final String code =
""
+ "_method a.m1 _endmethod\n"
+ "_method a.m1 _endmethod\n"
+ "_method a.m1 _endmethod\n";
"""
_method a.m1 _endmethod
_method a.m1 _endmethod
_method a.m1 _endmethod
""";
final List<MagikIssue> issues = this.runCheck(code, check);
assertThat(issues).isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void testSpaceIndentLineStrtWithSpaces() {
_endmethod
""",
})
@SuppressWarnings("java:S4144")
void testMultipleWhitelines(final String code) {
final MagikCheck check = new FormattingCheck();
final List<MagikIssue> issues = this.runCheck(code, check);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,30 @@ class HidesVariableCheckTest extends MagikCheckTestBase {
@ParameterizedTest
@ValueSource(
strings = {
""
+ "_block\n"
+ " _local a << 10\n"
+ " _block\n"
+ " _local b << 20\n"
+ " _endblock\n"
+ "_endblock\n",
""
+ "_block\n"
+ " _local a << 10\n"
+ " _proc()\n"
+ " _import a\n"
+ " _endproc\n"
+ "_endblock\n",
""
+ "_block\n"
+ " _block\n"
+ " _local a << 20\n"
+ " _endblock\n"
+ " _local a << 10\n"
+ "_endblock\n",
"""
_block
_local a << 10
_block
_local b << 20
_endblock
_endblock
""",
"""
_block
_local a << 10
_proc()
_import a
_endproc
_endblock
""",
"""
_block
_block
_local a << 20
_endblock
_local a << 10
_endblock
""",
})
void testValid(final String code) {
final MagikCheck check = new HidesVariableCheck();
Expand All @@ -45,41 +48,46 @@ void testValid(final String code) {
@ParameterizedTest
@ValueSource(
strings = {
""
+ "_block\n"
+ " _local a << 10\n"
+ " _block\n"
+ " _local a << 20\n"
+ " _endblock\n"
+ "_endblock\n",
""
+ "_block\n"
+ " _local a << 10, b << 20\n"
+ " _block\n"
+ " _local a << 20\n"
+ " _endblock\n"
+ "_endblock\n",
""
+ "_block\n"
+ " _local a << 10\n"
+ " _block\n"
+ " _local b << 20, a << 30\n"
+ " _endblock\n"
+ "_endblock\n",
""
+ "_block\n"
+ " _local (a, b) << (10, 20)\n"
+ " _block\n"
+ " _local a << 20\n"
+ " _endblock\n"
+ "_endblock\n",
""
+ "_block\n"
+ " _local a << 10\n"
+ " _block\n"
+ " _local (b, a) << (20, 30)\n"
+ " _endblock\n"
+ "_endblock\n",
"""
_block
_local a << 10
_block
_local a << 20
_endblock
_endblock
""",
"""
_block
_local a << 10, b << 20
_block
_local a << 20
_endblock
_endblock
""",
"""
_block
_local a << 10
_block
_local b << 20, a << 30
_endblock
_endblock
""",
"""
_block
_local (a, b) << (10, 20)
_block
_local a << 20
_endblock
_endblock
""",
"""
_block
_local a << 10
_block
_local (b, a) << (20, 30)
_endblock
_endblock
""",
})
void testInvalid(final String code) {
final MagikCheck check = new HidesVariableCheck();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,115 +5,80 @@
import java.util.List;
import nl.ramsolutions.sw.magik.checks.MagikCheck;
import nl.ramsolutions.sw.magik.checks.MagikIssue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/** Test ImportMissingDefinitionCheck. */
class ImportMissingDefinitionCheckTest extends MagikCheckTestBase {

@Test
void testImportOkLocal() {
@ParameterizedTest
@ValueSource(
strings = {
"""
_method a.b
_local var
_proc()
_import var
_endproc
_endmethod""",
"""
_method a.b
_if _true
_then
_local var
_proc()
_import var
_endproc
_endif
_endmethod""",
"""
_method a.b
_constant const
_proc()
_import const
_endproc
_endmethod""",
"""
_method a.b(param)
_proc()
_import param
_endproc
_endmethod""",
"""
_method a.b(param)
_for i _over 1.upto(5)
_loop
_proc()
_import i
_endproc
_endloop
_endmethod""",
})
void testImportValid(final String code) {
final MagikCheck check = new ImportMissingDefinitionCheck();
final String code =
""
+ "_method a.b\n"
+ " _local var\n"
+ " _proc()\n"
+ " _import var\n"
+ " _endproc\n"
+ "_endmethod";
final List<MagikIssue> issues = this.runCheck(code, check);
assertThat(issues).isEmpty();
}

@Test
void testImportOkLocal2() {
@ParameterizedTest
@ValueSource(
strings = {
"""
_method a.b
_proc()
_import var
_endproc
_endmethod""",
"""
_method a.b
var << 1
_proc()
_import var
_endproc
_endmethod""",
})
void testImportInvalid(final String code) {
final MagikCheck check = new ImportMissingDefinitionCheck();
final String code =
""
+ "_method a.b\n"
+ " _if _true\n"
+ " _then\n"
+ " _local var\n"
+ " _proc()\n"
+ " _import var\n"
+ " _endproc\n"
+ " _endif\n"
+ "_endmethod";
final List<MagikIssue> issues = this.runCheck(code, check);
assertThat(issues).isEmpty();
}

@Test
void testImportOkConstant() {
final MagikCheck check = new ImportMissingDefinitionCheck();
final String code =
""
+ "_method a.b\n"
+ " _constant const\n"
+ " _proc()\n"
+ " _import const\n"
+ " _endproc\n"
+ "_endmethod";
final List<MagikIssue> issues = this.runCheck(code, check);
assertThat(issues).isEmpty();
}

@Test
void testImportOkParameter() {
final MagikCheck check = new ImportMissingDefinitionCheck();
final String code =
""
+ "_method a.b(param)\n"
+ " _proc()\n"
+ " _import param\n"
+ " _endproc\n"
+ "_endmethod";
final List<MagikIssue> issues = this.runCheck(code, check);
assertThat(issues).isEmpty();
}

@Test
void testImportOkIter() {
final MagikCheck check = new ImportMissingDefinitionCheck();
final String code =
""
+ "_method a.b(param)\n"
+ " _for i _over 1.upto(5)\n"
+ " _loop\n"
+ " _proc()\n"
+ " _import i\n"
+ " _endproc\n"
+ " _endloop\n"
+ "_endmethod";
final List<MagikIssue> issues = this.runCheck(code, check);
assertThat(issues).isEmpty();
}

@Test
void testImportFailMissing() {
final MagikCheck check = new ImportMissingDefinitionCheck();
final String code =
""
+ "_method a.b\n"
+ " _proc()\n"
+ " _import var\n"
+ " _endproc\n"
+ "_endmethod";
final List<MagikIssue> issues = this.runCheck(code, check);
assertThat(issues).hasSize(1);
}

@Test
void testImportFailNonLocal() {
final MagikCheck check = new ImportMissingDefinitionCheck();
final String code =
""
+ "_method a.b\n"
+ " var << 1\n"
+ " _proc()\n"
+ " _import var\n"
+ " _endproc\n"
+ "_endmethod";
final List<MagikIssue> issues = this.runCheck(code, check);
assertThat(issues).hasSize(1);
}
Expand Down
Loading

0 comments on commit 72109b8

Please sign in to comment.