Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions liquidjava-verifier/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,45 @@
<build>
<finalName>${jar.finalName}</finalName>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.14</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.40</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
Expand Down Expand Up @@ -77,7 +116,8 @@
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>liquidjava.api.CommandLineLauncher</mainClass>
</transformer>
</transformers>
Expand Down Expand Up @@ -206,4 +246,5 @@
</dependency>
</dependencies>
</dependencyManagement>
</project>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import liquidjava.rj_language.ast.BinaryExpression;
import liquidjava.rj_language.ast.LiteralInt;
import liquidjava.rj_language.opt.ConstantFolding;
import liquidjava.rj_language.opt.derivation_node.ValDerivationNode;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class TestOptimization {
@Test
public void testBinaryFold() {
BinaryExpression b = new BinaryExpression(new LiteralInt(1), "+", new LiteralInt(2));

ValDerivationNode r = ConstantFolding.fold(new ValDerivationNode(b, null));
assertEquals(r.getValue(), new LiteralInt(3));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package liquidjava.diagnostics.errors;

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import spoon.reflect.declaration.CtElement;

public class LJErrorTest {

static class ConcreteLJError extends LJError {
ConcreteLJError(String message, String details, CtElement element) {
super(message, details, element);
}

@Override
public String toString() {
return "ConcreteLJError: " + super.getMessage() + " | " + "Details field tested";
}
}

@Test
void testLJErrorMessage() {
LJError error = new ConcreteLJError("Test error message", "Details", null);
assertEquals("Details", error.getMessage());
}

@Test
void testToStringContainsMessage() {
LJError error = new ConcreteLJError("Invalid syntax", "Details", null);
String s = error.toString();

assertTrue(s.contains("ConcreteLJError"));
assertTrue(s.contains("Details"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package liquidjava.rj_language;

import static org.junit.Assert.assertNotEquals;
import org.junit.Test;
import liquidjava.rj_language.ast.LiteralString;

public class TestLiteralString {
@Test
public void testLiteralString() {
LiteralString s1 = new LiteralString("hello");
LiteralString s2 = new LiteralString("world");
assertNotEquals(s1.hashCode(), s2.hashCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package rj.grammar;

import org.antlr.v4.runtime.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

public class RJParserIntegrationTest {

@Test
void testFullProgramParsing() {
String input = """
type MyAlias(int x) {
!(x < 5)
}
ghost int myGhost(int y)
""";

RJLexer lexer = new RJLexer(CharStreams.fromString(input));
CommonTokenStream tokens = new CommonTokenStream(lexer);
RJParser parser = new RJParser(tokens);

RJParser.ProgContext ctx = parser.prog();

assertNotNull(ctx, "O contexto do programa não deve ser nulo");
assertNotNull(ctx.start(), "Deve conter uma regra start válida");
assertEquals(0, parser.getNumberOfSyntaxErrors(), "O parser não deve gerar erros");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package rj.grammar;

import org.antlr.v4.runtime.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

public class RJParserLiteralTest {

@Test
void testIntegerLiteral() {
String input = "123";
RJLexer lexer = new RJLexer(CharStreams.fromString(input));
CommonTokenStream tokens = new CommonTokenStream(lexer);
RJParser parser = new RJParser(tokens);

RJParser.LiteralContext ctx = parser.literal();

assertNotNull(ctx);
assertEquals("123", ctx.getText());
}

@Test
void testBooleanLiteral() {
String input = "true";
RJLexer lexer = new RJLexer(CharStreams.fromString(input));
CommonTokenStream tokens = new CommonTokenStream(lexer);
RJParser parser = new RJParser(tokens);

RJParser.LiteralContext ctx = parser.literal();

assertNotNull(ctx);
assertEquals("true", ctx.getText());
}
}
21 changes: 21 additions & 0 deletions liquidjava-verifier/src/test/java/rj/grammar/RJParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package rj.grammar;

import org.antlr.v4.runtime.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

public class RJParserTest {

@Test
void testLiteralParsing() {
String input = "42";
RJLexer lexer = new RJLexer(CharStreams.fromString(input));
CommonTokenStream tokens = new CommonTokenStream(lexer);
RJParser parser = new RJParser(tokens);

RJParser.LiteralContext context = parser.literal();

assertNotNull(context);
assertEquals("42", context.getText());
}
}