use of nl.ramsolutions.sw.magik.analysis.typing.types.MagikType in project magik-tools by StevenLooman.
the class MethodArgumentParameterTypeCheckTest method testArgumentTypeMatches.
@Test
void testArgumentTypeMatches() {
final String code = "integer.m1(:symbol)";
final ITypeKeeper typeKeeper = new TypeKeeper();
final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
final AbstractType symbolType = typeKeeper.getType(GlobalReference.of("sw:symbol"));
final Parameter param1 = new Parameter("p1", Parameter.Modifier.NONE, symbolType);
integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), null, "m1()", List.of(param1), null, ExpressionResult.UNDEFINED);
final MagikTypedCheck check = new MethodArgumentParameterTypedCheck();
final List<MagikIssue> checkResults = this.runCheck(code, typeKeeper, check);
assertThat(checkResults).isEmpty();
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.MagikType in project magik-tools by StevenLooman.
the class MethodArgumentParameterTypeCheckTest method testArgumentTypeNotMatches.
@Test
void testArgumentTypeNotMatches() {
final String code = "integer.m1(1)";
final ITypeKeeper typeKeeper = new TypeKeeper();
final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
final AbstractType symbolType = typeKeeper.getType(GlobalReference.of("sw:symbol"));
final Parameter param1 = new Parameter("p1", Parameter.Modifier.NONE, symbolType);
integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), null, "m1()", List.of(param1), null, ExpressionResult.UNDEFINED);
final MagikTypedCheck check = new MethodArgumentParameterTypedCheck();
final List<MagikIssue> checkResults = this.runCheck(code, typeKeeper, check);
assertThat(checkResults).hasSize(1);
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.MagikType in project magik-tools by StevenLooman.
the class HoverProviderTest method testProvideHoverMethodDefinitionExemplar.
@Test
void testProvideHoverMethodDefinitionExemplar() {
// Set up a method.
final ITypeKeeper typeKeeper = new TypeKeeper();
final MagikType hoverMeType = new SlottedType(GlobalReference.of("user:hover_me_type"));
hoverMeType.setDoc("type_doc");
typeKeeper.addType(hoverMeType);
final String code = "" + "_method hover_me_type.method()\n" + "_endmethod";
// On 'hover_me_type'.
final Position position = new Position(0, 10);
// Hover and test.
final Hover hover = this.provideHover(code, position, typeKeeper);
final MarkupContent content = hover.getContents().getRight();
assertThat(content.getKind()).isEqualTo(MarkupKind.MARKDOWN);
assertThat(content.getValue()).contains("hover_me_type");
assertThat(content.getValue()).contains("type_doc");
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.MagikType in project magik-tools by StevenLooman.
the class HoverProviderTest method testProvideHoverType.
@Test
void testProvideHoverType() {
// Set up a method.
final ITypeKeeper typeKeeper = new TypeKeeper();
final MagikType symbolType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:symbol"));
symbolType.setDoc("type_doc");
final String code = "" + "_method a.b\n" + " _local var << :symbol\n" + " var.hover_me()\n" + "_endmethod";
// On `var`.
final Position position = new Position(2, 4);
// Hover and test.
final Hover hover = this.provideHover(code, position, typeKeeper);
final MarkupContent content = hover.getContents().getRight();
assertThat(content.getKind()).isEqualTo(MarkupKind.MARKDOWN);
assertThat(content.getValue()).contains("symbol");
assertThat(content.getValue()).contains("type_doc");
}
use of nl.ramsolutions.sw.magik.analysis.typing.types.MagikType in project magik-tools by StevenLooman.
the class ImplementationProviderTest method testProvideImplementation.
@Test
void testProvideImplementation() {
final ITypeKeeper typeKeeper = new TypeKeeper();
final MagikType integerType = (MagikType) typeKeeper.getType(GlobalReference.of("sw:integer"));
integerType.addMethod(EnumSet.noneOf(Method.Modifier.class), EMPTY_LOCATION, "implementation()", Collections.emptyList(), null, ExpressionResult.UNDEFINED);
final URI uri = URI.create("tests://unittest");
final String code = "" + "_method object.b\n" + " 1.implementation()\n" + "_endmethod";
final MagikTypedFile magikFile = new MagikTypedFile(uri, code, typeKeeper);
final org.eclipse.lsp4j.Position position = new org.eclipse.lsp4j.Position(1, 10);
final ImplementationProvider provider = new ImplementationProvider();
final List<org.eclipse.lsp4j.Location> implementations = provider.provideImplementations(magikFile, position);
assertThat(implementations).containsOnly(Lsp4jConversion.locationToLsp4j(EMPTY_LOCATION));
}
Aggregations