Search in sources :

Example 96 with AstNode

use of com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.

the class NewDocParserTest method testParameterEmpty.

@Test
void testParameterEmpty() throws IOException {
    final String code = "" + "_method a.b(param1, param2) << param3\n" + "    ## @param \n" + "    ## @param param1\n" + "    ## @param {integer} param2\n" + "    ## @param {integer} param3 \n" + "    ## @param {integer|float} param4\n" + "_endmethod";
    final AstNode topNode = this.parseMagik(code);
    final AstNode methodNode = topNode.getFirstChild(MagikGrammar.METHOD_DEFINITION);
    final NewDocParser docParser = new NewDocParser(methodNode);
    final Map<String, String> parameterTypes = docParser.getParameterTypes();
    assertThat(parameterTypes).containsOnly(Map.entry("param1", ""), Map.entry("param2", "integer"), Map.entry("param3", "integer"), Map.entry("param4", "integer|float"));
}
Also used : AstNode(com.sonar.sslr.api.AstNode) Test(org.junit.jupiter.api.Test)

Example 97 with AstNode

use of com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.

the class NewDocParserTest method testReturnEmpty.

@Test
void testReturnEmpty() throws IOException {
    final String code = "" + "_method a.b\n" + "    ## @return \n" + "    ## @return {sw:integer}\n" + "    ## @return {sw:integer} \n" + "    ## @return {sw:integer|sw:float}\n" + "_endmethod";
    final AstNode topNode = this.parseMagik(code);
    final AstNode methodNode = topNode.getFirstChild(MagikGrammar.METHOD_DEFINITION);
    final NewDocParser docParser = new NewDocParser(methodNode);
    final List<String> returnTypes = docParser.getReturnTypes();
    assertThat(returnTypes).containsExactly("", "sw:integer", "sw:integer", "sw:integer|sw:float");
}
Also used : AstNode(com.sonar.sslr.api.AstNode) Test(org.junit.jupiter.api.Test)

Example 98 with AstNode

use of com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.

the class NewDocParserTest method testReturnSelf.

@Test
void testReturnSelf() throws IOException {
    final String code = "" + "_method a.b\n" + "    ## @return {_self}\n" + "_endmethod";
    final AstNode topNode = this.parseMagik(code);
    final AstNode methodNode = topNode.getFirstChild(MagikGrammar.METHOD_DEFINITION);
    final NewDocParser docParser = new NewDocParser(methodNode);
    final List<String> returnTypes = docParser.getReturnTypes();
    assertThat(returnTypes).containsExactly("_self");
}
Also used : AstNode(com.sonar.sslr.api.AstNode) Test(org.junit.jupiter.api.Test)

Example 99 with AstNode

use of com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.

the class NewDocParserTest method testReturn.

@Test
void testReturn() throws IOException {
    final String code = "" + "_method a.b\n" + "    ## @return {sw:integer} An Integer.\n" + "_endmethod";
    final AstNode topNode = this.parseMagik(code);
    final AstNode methodNode = topNode.getFirstChild(MagikGrammar.METHOD_DEFINITION);
    final NewDocParser docParser = new NewDocParser(methodNode);
    final List<String> returnTypes = docParser.getReturnTypes();
    assertThat(returnTypes).containsExactly("sw:integer");
}
Also used : AstNode(com.sonar.sslr.api.AstNode) Test(org.junit.jupiter.api.Test)

Example 100 with AstNode

use of com.sonar.sslr.api.AstNode in project magik-tools by StevenLooman.

the class NewDocParserTest method testSlotTypes.

@Test
void testSlotTypes() throws IOException {
    final String code = "" + "## @slot slot1 Slot 1.\n" + "## @slot {integer} slot2 Slot 2.\n" + "def_slotted_exemplar(:example,\n" + "    {\n" + "        {:slot1, _unset}\n" + "    })\n";
    final AstNode topNode = this.parseMagik(code);
    final AstNode definitionNode = topNode.getFirstChild(MagikGrammar.STATEMENT);
    final NewDocParser docParser = new NewDocParser(definitionNode);
    final Map<String, String> slotTypes = docParser.getSlotTypes();
    assertThat(slotTypes).containsOnly(Map.entry("slot1", ""), Map.entry("slot2", "integer"));
}
Also used : AstNode(com.sonar.sslr.api.AstNode) Test(org.junit.jupiter.api.Test)

Aggregations

AstNode (com.sonar.sslr.api.AstNode)492 Test (org.junit.Test)108 Test (org.junit.jupiter.api.Test)91 ExpressionResult (nl.ramsolutions.sw.magik.analysis.typing.types.ExpressionResult)71 Token (com.sonar.sslr.api.Token)50 AbstractType (nl.ramsolutions.sw.magik.analysis.typing.types.AbstractType)49 Token (org.sonar.plugins.python.api.tree.Token)46 MagikTypedFile (nl.ramsolutions.sw.magik.MagikTypedFile)41 YieldExpression (org.sonar.plugins.python.api.tree.YieldExpression)40 FormattedExpression (org.sonar.plugins.python.api.tree.FormattedExpression)39 QualifiedExpression (org.sonar.plugins.python.api.tree.QualifiedExpression)39 AssignmentExpression (org.sonar.plugins.python.api.tree.AssignmentExpression)38 ComprehensionExpression (org.sonar.plugins.python.api.tree.ComprehensionExpression)38 ConditionalExpression (org.sonar.plugins.python.api.tree.ConditionalExpression)38 Expression (org.sonar.plugins.python.api.tree.Expression)38 LambdaExpression (org.sonar.plugins.python.api.tree.LambdaExpression)38 List (java.util.List)35 RuleTest (org.sonar.python.parser.RuleTest)34 ArrayList (java.util.ArrayList)33 MagikType (nl.ramsolutions.sw.magik.analysis.typing.types.MagikType)33