Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnrd committed Mar 7, 2024
1 parent 2718a02 commit 1c8fca1
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 128 deletions.
6 changes: 3 additions & 3 deletions cli/lfc/src/test/resources/org/lflang/cli/issue490.lf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# https://github.com/lf-lang/lingua-franca/issues/490
# issue is that one error ends at EOF
target Python;
main reactor R(p(3)) {
state liss(2, 3);
main reactor R(p = 3) {
state list = [2, 3];
reaction (startup) {
print(self.liss)
print(self.list)
}
}
14 changes: 7 additions & 7 deletions cli/lfc/src/test/resources/org/lflang/cli/issue490.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ lfc: error: Name of main reactor must match the file name (or be omitted).
--> %%%PATH.lf%%%:4:14
|
3 | target Python;
4 | main reactor R(p(3)) {
4 | main reactor R(p = 3) {
| ^ Name of main reactor must match the file name (or be omitted).
|
5 | state liss(2, 3);
5 | state list = [2, 3];
lfc: error: The Python target does not support reaction declarations. Please specify a reaction body.
--> %%%PATH.lf%%%:6:3
|
5 | state liss(2, 3);
5 | state list = [2, 3];
6 | reaction (startup) {
| ^^^^^^^^^^^^^^^^^^^^ The Python target does not support reaction declarations. Please specify a reaction body.
|
7 | print(self.liss)
7 | print(self.list)
lfc: error: no viable alternative at input '{'
--> %%%PATH.lf%%%:6:22
|
5 | state liss(2, 3);
5 | state list = [2, 3];
6 | reaction (startup) {
| ^ no viable alternative at input '{'
|
7 | print(self.liss)
7 | print(self.list)
lfc: error: no viable alternative at input '('
--> %%%PATH.lf%%%:7:5
|
6 | reaction (startup) {
7 | print(self.liss)
7 | print(self.list)
| ^^^^^ no viable alternative at input '('
|
8 | }
4 changes: 2 additions & 2 deletions cli/lfc/src/test/resources/org/lflang/cli/tabs.lf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
target C;

main reactor {
state foo(1);
state bar(1);
state foo = 1;
state bar = 1;
}
12 changes: 6 additions & 6 deletions cli/lfc/src/test/resources/org/lflang/cli/tabs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ lfc: error: State must have a type.
--> %%%PATH.lf%%%:4:2
|
3 | main reactor {
4 | state foo(1);
| ^^^^^^^^^^^^^ State must have a type.
4 | state foo = 1;
| ^^^^^^^^^^^^^^ State must have a type.
|
5 | state bar(1);
5 | state bar = 1;
lfc: error: State must have a type.
--> %%%PATH.lf%%%:5:2
|
4 | state foo(1);
5 | state bar(1);
| ^^^^^^^^^^^^^^^^ State must have a type.
4 | state foo = 1;
5 | state bar = 1;
| ^^^^^^^^^^^^^^^^^ State must have a type.
|
6 | }
10 changes: 5 additions & 5 deletions cli/lff/src/test/java/org/lflang/cli/LffCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ public class LffCliTest {
List.of(
"""
target C
reactor Filter(period: int = 0, b: double[](0, 0)) {}
reactor Filter(period: int = 0, b: double[] = {0, 0}) {}
main reactor {
az_f = new Filter(
period = 100,
b = (0.229019233988375, 0.421510777305010)
b = {0.229019233988375, 0.421510777305010}
)
}
""",
Expand All @@ -128,9 +128,9 @@ reactor Filter(period: int = 0, b: double[] = {0, 0}) {
"""
target Rust
reactor Snake { // q
state grid: SnakeGrid ({= /* foo */ SnakeGrid::new(grid_side, &snake) =}); // note that this one borrows snake temporarily
state grid2: SnakeGrid ({= // baz
SnakeGrid::new(grid_side, &snake) =});
state grid: SnakeGrid = {= /* foo */ SnakeGrid::new(grid_side, &snake) =}; // note that this one borrows snake temporarily
state grid2: SnakeGrid = {= // baz
SnakeGrid::new(grid_side, &snake) =};
}
""",
"""
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/org/lflang/generator/c/CTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public String getTargetParamRef(ParameterReference expr, InferredType typeOrNull

@Override
public String getTargetTimeExpr(TimeValue time) {
if (time.unit != null) {
return cMacroName(time.unit) + "(" + time.getMagnitude() + ")";
} else {
return Long.valueOf(time.getMagnitude()).toString();
}
if (time.unit != null) {
return cMacroName(time.unit) + "(" + time.getMagnitude() + ")";
} else {
return Long.valueOf(time.getMagnitude()).toString();
}
}

/**
Expand Down
13 changes: 6 additions & 7 deletions core/src/main/java/org/lflang/validation/LFValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void checkBracedExpression(BracedListExpression expr) {
if (!target.allowsBracedListExpressions()) {
var message =
"Braced expression lists are not a valid expression for the " + target + " target.";
error(message, Literals.BRACED_LIST_EXPRESSION.eContainmentFeature());
error(message, Literals.BRACED_LIST_EXPRESSION__ITEMS);
}
}

Expand All @@ -186,18 +186,16 @@ public void checkBracketExpression(BracketListExpression expr) {
if (!target.allowsBracketListExpressions()) {
var message =
"Bracketed expression lists are not a valid expression for the " + target + " target.";
error(message, Literals.BRACKET_LIST_EXPRESSION.eContainmentFeature());
error(message, Literals.BRACKET_LIST_EXPRESSION__ITEMS);
}
}

@Check(CheckType.FAST)
public void checkParenthesisExpression(ParenthesisListExpression expr) {
if (!target.allowsParenthesisListExpressions()) {
var message =
"Parenthesis expression lists are not a valid expression for the "
+ target
+ " target.";
error(message, Literals.PARENTHESIS_LIST_EXPRESSION.eContainmentFeature());
"Parenthesis expression lists are not a valid expression for the " + target + " target.";
error(message, Literals.PARENTHESIS_LIST_EXPRESSION__ITEMS);
}
}

Expand Down Expand Up @@ -1086,7 +1084,8 @@ public void checkType(Type type) {
error("Types are not allowed in the Python target", Literals.TYPE__ID);
}

if (type.getCStyleArraySpec() != null && !List.of(Target.C, Target.CCPP, Target.TS).contains(target)) {
if (type.getCStyleArraySpec() != null
&& !List.of(Target.C, Target.CCPP, Target.TS).contains(target)) {
if (target == Target.CPP) {
error(
"C style array specifications are not allowed in this target. Please use std::array or"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void testSimple() {
reactor Destination {
input ok: bool
input in: int
state last_invoked: tag_t({= NEVER_TAG_INITIALIZER =})
state last_invoked: tag_t = {= NEVER_TAG_INITIALIZER =}
}
""");
}
Expand All @@ -34,34 +34,15 @@ public void testCodeExprEqItselfModuloIndent() {
"""
target C
reactor Destination {
state s: tag_t({=
state s: tag_t = {=
NEVER_TAG_INITIALIZER
=})
=}
}
""",
"""
target C
reactor Destination {
state s: tag_t({= NEVER_TAG_INITIALIZER =})
}
""");
}

@Test
public void testInitializerParensAreIrrelevantInAssignment() {
assertEquivalent(
"""
target C
reactor A(a: int(0)) {}
main reactor {
a = new A(a = 1)
}
""",
"""
target C
reactor A(a: int(0)) {}
main reactor {
a = new A(a = (1)) // mind the parens here.
state s: tag_t = {= NEVER_TAG_INITIALIZER =}
}
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void testAssignments() {
reactor Destination {
input ok: bool
input in: int
state last_invoked: tag_t({= NEVER_TAG_INITIALIZER =})
state last_invoked: tag_t= {= NEVER_TAG_INITIALIZER =}
}
""",
"""
Expand All @@ -60,9 +60,9 @@ public void testState() {
target Python
reactor Destination {
state one_init: tag_t( {= NEVER_TAG_INITIALIZER =})
state one_init: tag_t = {=NEVER_TAG_INITIALIZER=}
state no_init: tag_t
state list_init(1,2) // this syntax is deprecated
state list_init = [1,2] // comment
}
""",
"""
Expand All @@ -71,7 +71,7 @@ state list_init(1,2) // this syntax is deprecated
reactor Destination {
state one_init: tag_t = {= NEVER_TAG_INITIALIZER =}
state no_init: tag_t
state list_init(1, 2) # this syntax is deprecated
state list_init = [1, 2] # comment
}
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.eclipse.xtext.testing.InjectWith;
Expand Down Expand Up @@ -95,13 +96,12 @@ public void uninitializedState() throws Exception {
Model model =
parser.parse(
"""
target Cpp;
target C;
main reactor Foo {
state a;
state b:int;
state c:int[];
state d:time;
state e:time[];
}
""");

Expand Down Expand Up @@ -142,12 +142,12 @@ public void initialValue() throws Exception {
parser.parse(
"""
target C;
reactor A(x:int(1)) {}
reactor B(y:int(2)) {
reactor A(x:int = 1) {}
reactor B(y:int = 2) {
a1 = new A(x = y);
a2 = new A(x = -1);
}
reactor C(z:int(3)) {
reactor C(z:int = 3) {
b1 = new B(y = z);
b2 = new B(y = -2);
}
Expand Down Expand Up @@ -178,53 +178,52 @@ reactor C(z:int(3)) {
model
.eAllContents()
.forEachRemaining(
(obj) -> {
if (obj instanceof Parameter) {
Parameter parameter = (Parameter) obj;
if (parameter.getName() == "x") {
var values = ASTUtils.initialValue(parameter, null);
Assertions.assertInstanceOf(Literal.class, values.get(0));
Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "1");

values = ASTUtils.initialValue(parameter, List.of(map.get("a1")));
Assertions.assertInstanceOf(Literal.class, values.get(0));
Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "2");

values = ASTUtils.initialValue(parameter, List.of(map.get("a2")));
Assertions.assertInstanceOf(Literal.class, values.get(0));
Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-1");

values = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b1")));
Assertions.assertInstanceOf(Literal.class, values.get(0));
Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "3");

values = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b1")));
Assertions.assertInstanceOf(Literal.class, values.get(0));
Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-1");

values = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b2")));
Assertions.assertInstanceOf(Literal.class, values.get(0));
Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-2");

values = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b2")));
Assertions.assertInstanceOf(Literal.class, values.get(0));
Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-1");
} else if (parameter.getName() == "y") {
var values = ASTUtils.initialValue(parameter, null);
Assertions.assertInstanceOf(Literal.class, values.get(0));
Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "2");
obj -> {
if (obj instanceof Parameter parameter) {
if (Objects.equals(parameter.getName(), "x")) {
var value = ASTUtils.initialValue(parameter, null);
Assertions.assertInstanceOf(Literal.class, value);
Assertions.assertEquals(((Literal) value).getLiteral(), "1");

value = ASTUtils.initialValue(parameter, List.of(map.get("a1")));
Assertions.assertInstanceOf(Literal.class, value);
Assertions.assertEquals(((Literal) value).getLiteral(), "2");

value = ASTUtils.initialValue(parameter, List.of(map.get("a2")));
Assertions.assertInstanceOf(Literal.class, value);
Assertions.assertEquals(((Literal) value).getLiteral(), "-1");

value = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b1")));
Assertions.assertInstanceOf(Literal.class, value);
Assertions.assertEquals(((Literal) value).getLiteral(), "3");

value = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b1")));
Assertions.assertInstanceOf(Literal.class, value);
Assertions.assertEquals(((Literal) value).getLiteral(), "-1");

value = ASTUtils.initialValue(parameter, List.of(map.get("a1"), map.get("b2")));
Assertions.assertInstanceOf(Literal.class, value);
Assertions.assertEquals(((Literal) value).getLiteral(), "-2");

value = ASTUtils.initialValue(parameter, List.of(map.get("a2"), map.get("b2")));
Assertions.assertInstanceOf(Literal.class, value);
Assertions.assertEquals(((Literal) value).getLiteral(), "-1");
} else if (Objects.equals(parameter.getName(), "y")) {
var value = ASTUtils.initialValue(parameter, null);
Assertions.assertInstanceOf(Literal.class, value);
Assertions.assertEquals(((Literal) value).getLiteral(), "2");

Assertions.assertThrows(
IllegalArgumentException.class,
() -> ASTUtils.initialValue(parameter, List.of(map.get("a1"))));

values = ASTUtils.initialValue(parameter, List.of(map.get("b1")));
Assertions.assertInstanceOf(Literal.class, values.get(0));
Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "3");
value = ASTUtils.initialValue(parameter, List.of(map.get("b1")));
Assertions.assertInstanceOf(Literal.class, value);
Assertions.assertEquals(((Literal) value).getLiteral(), "3");

values = ASTUtils.initialValue(parameter, List.of(map.get("b2")));
Assertions.assertInstanceOf(Literal.class, values.get(0));
Assertions.assertEquals(((Literal) values.get(0)).getLiteral(), "-2");
value = ASTUtils.initialValue(parameter, List.of(map.get("b2")));
Assertions.assertInstanceOf(Literal.class, value);
Assertions.assertEquals(((Literal) value).getLiteral(), "-2");
}
}
});
Expand Down
Loading

0 comments on commit 1c8fca1

Please sign in to comment.