Skip to content

Commit 0df25ee

Browse files
committed
Adicionados 2 testes unitários e 1 teste de integração
1 parent 35ed33f commit 0df25ee

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package rj.grammar;
2+
3+
import org.antlr.v4.runtime.*;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
import org.junit.jupiter.api.Test;
6+
7+
public class RJParserIntegrationTest {
8+
9+
@Test
10+
void testFullProgramParsing() {
11+
String input = """
12+
type MyAlias(int x) {
13+
!(x < 5)
14+
}
15+
ghost int myGhost(int y)
16+
""";
17+
18+
RJLexer lexer = new RJLexer(CharStreams.fromString(input));
19+
CommonTokenStream tokens = new CommonTokenStream(lexer);
20+
RJParser parser = new RJParser(tokens);
21+
22+
RJParser.ProgContext ctx = parser.prog();
23+
24+
assertNotNull(ctx, "O contexto do programa não deve ser nulo");
25+
assertNotNull(ctx.start(), "Deve conter uma regra start válida");
26+
assertEquals(0, parser.getNumberOfSyntaxErrors(), "O parser não deve gerar erros");
27+
}
28+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package rj.grammar;
2+
3+
import org.antlr.v4.runtime.*;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
import org.junit.jupiter.api.Test;
6+
7+
public class RJParserLiteralTest {
8+
9+
@Test
10+
void testIntegerLiteral() {
11+
String input = "123";
12+
RJLexer lexer = new RJLexer(CharStreams.fromString(input));
13+
CommonTokenStream tokens = new CommonTokenStream(lexer);
14+
RJParser parser = new RJParser(tokens);
15+
16+
RJParser.LiteralContext ctx = parser.literal();
17+
18+
assertNotNull(ctx);
19+
assertEquals("123", ctx.getText());
20+
}
21+
22+
@Test
23+
void testBooleanLiteral() {
24+
String input = "true";
25+
RJLexer lexer = new RJLexer(CharStreams.fromString(input));
26+
CommonTokenStream tokens = new CommonTokenStream(lexer);
27+
RJParser parser = new RJParser(tokens);
28+
29+
RJParser.LiteralContext ctx = parser.literal();
30+
31+
assertNotNull(ctx);
32+
assertEquals("true", ctx.getText());
33+
}
34+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package rj.grammar;
2+
3+
import org.antlr.v4.runtime.*;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
import org.junit.jupiter.api.Test;
6+
7+
public class RJParserTest {
8+
9+
@Test
10+
void testLiteralParsing() {
11+
String input = "42";
12+
RJLexer lexer = new RJLexer(CharStreams.fromString(input));
13+
CommonTokenStream tokens = new CommonTokenStream(lexer);
14+
RJParser parser = new RJParser(tokens);
15+
16+
RJParser.LiteralContext context = parser.literal();
17+
18+
assertNotNull(context);
19+
assertEquals("42", context.getText());
20+
}
21+
}

0 commit comments

Comments
 (0)