Skip to content

Commit

Permalink
Detects duplicate messages and channels aspects
Browse files Browse the repository at this point in the history
This commit introduces extra checks to avoid duplicate aspects for messages and channels.
Closes #714
  • Loading branch information
mhadhbir committed Feb 9, 2022
1 parent 62c0475 commit 48bef96
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
4 changes: 3 additions & 1 deletion rflx/specification/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,9 @@ def extract_aspect(aspects: lang.AspectList) -> Tuple[expr.Expr, expr.Expr]:
size: expr.Expr = expr.UNDEFINED
first: expr.Expr = expr.UNDEFINED
for aspect in aspects:
if (aspect.f_identifier.text == "Size" and size != expr.UNDEFINED) or (aspect.f_identifier.text == "First" and first != expr.UNDEFINED):
if (aspect.f_identifier.text == "Size" and size != expr.UNDEFINED) or (
aspect.f_identifier.text == "First" and first != expr.UNDEFINED
):
error.extend(
[
(
Expand Down
78 changes: 77 additions & 1 deletion tests/unit/specification/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,80 @@ def test_parse_error_duplicate_channel_aspect_readable() -> None:
r'^<stdin>:11:60: parser: error: duplicate aspect "Readable"',
)

def test_parse_error_duplicate_message_aspect_size() -> None:
assert_error_string(
"""
package Test is
type M is
message
B : Opaque
with First => 123, Size => 123, Size => 521;
end message;
end Test;
""",
r'^<stdin>:6:61: parser: error: duplicate aspect "Size"',
)


def test_parse_error_duplicate_message_aspect_first() -> None:
assert_error_string(
"""
package Test is
type M is
message
B : Opaque
with First => 123, Size => 123, First => 521;
end message;
end Test;
""",
r'^<stdin>:6:61: parser: error: duplicate aspect "First"',
)


def test_parse_error_duplicate_channel_aspect_readable() -> None:
assert_error_string(
"""
package Test is
type M is
message
B : Opaque
with Size => 8;
end message;
generic
Channel : Channel with Readable, Writable, Readable;
session Session with
Initial => Start,
Final => Terminated
is
Message : M;
begin
state Start is
begin
Channel'Read (Message);
transition
goto Reply
if Message'Valid
goto Terminated
end Start;
state Reply is
begin
Channel'Write (Message);
transition
goto Terminated
end Reply;
state Terminated is null state;
end Session;
end Test;
""",
r'^<stdin>:11:60: parser: error: duplicate aspect "Readable"',
)


def test_parse_error_duplicate_channel_aspect_writable() -> None:
assert_error_string(
"""
Expand Down Expand Up @@ -2036,7 +2110,9 @@ def test_parse_error_duplicate_channel_aspect_writable() -> None:
end Test;
""",
r'^<stdin>:11:60: parser: error: duplicate aspect "Writable"',
)
)


@pytest.mark.parametrize("spec", ["empty_file", "comment_only", "empty_package", "context"])
def test_create_model_no_messages(spec: str) -> None:
assert_messages_files([f"{SPEC_DIR}/{spec}.rflx"], [])
Expand Down

0 comments on commit 48bef96

Please sign in to comment.