示例#1
0
def assert_specifications_files(
    filenames: Sequence[str], specifications: Dict[str, Specification]
) -> None:
    p = Parser()
    for filename in filenames:
        p.parse(Path(filename))
    assert p.specifications == specifications, filenames
示例#2
0
def test_parsed_field_locations() -> None:
    p = Parser()
    p.parse_string(
        """
           package Test is
              type T is mod 2**8;
              type M is
                 message
                    F1 : T;
                    F2 : T;
                 end message;
           end Test;
        """
    )
    m = p.create_model()
    assert m.messages[0].fields == (
        Field(ID("F1", Location((6, 21), end=(6, 22)))),
        Field(ID("F2", Location((7, 21), end=(7, 22)))),
    )
示例#3
0
def test_unexpected_exception_in_parser(monkeypatch: Any) -> None:
    p = Parser()
    with pytest.raises(RecordFluxError, match=r"parser: error: TEST"):
        monkeypatch.setattr(parser, "check_naming", lambda x, e: raise_parser_error())
        p.parse_string(
            """
                package Test is
                   type T is mod 256;
                end Test;
            """
        )
        p.create_model()
示例#4
0
def test_message_with_two_length_fields() -> None:
    p = Parser()
    p.parse_string(
        """
           package Test is
              type Length is mod 2**8;
              type Packet is
                 message
                    Length_1 : Length;
                    Length_2 : Length
                       then Payload
                          with Length => 8 * (Length_1 + Length_2);
                    Payload : Opaque;
                 end message;
           end Test;
        """
    )
    p.create_model()
示例#5
0
def test_array_with_imported_element_type() -> None:
    p = Parser()
    p.parse_string(
        """
           with Test;
           package Array_Test is
              type T is array of Test.T;
           end Array_Test;
        """
    )
    p.parse_string(
        """
           package Test is
              type T is mod 256;
           end Test;
        """
    )
    m = p.create_model()
    arrays = [t for t in m.types if isinstance(t, Array)]
    assert len(arrays) == 1
    assert arrays[0].identifier == ID("Array_Test.T")
    assert arrays[0].element_type == ModularInteger("Test.T", Number(256))
示例#6
0
def assert_messages_string(string: str, messages: Sequence[Message]) -> None:
    p = Parser()
    p.parse_string(string)
    model = p.create_model()
    assert_messages(model.messages, messages)
示例#7
0
def assert_messages_files(filenames: Sequence[str], messages: Sequence[Message]) -> None:
    p = Parser()
    for filename in filenames:
        p.parse(Path(filename))
    model = p.create_model()
    assert_messages(model.messages, messages)
示例#8
0
def assert_specifications_string(string: str, specifications: Dict[str, Specification]) -> None:
    p = Parser()
    p.parse_string(string)
    assert p.specifications == specifications
示例#9
0
def test_feature_integration() -> None:
    p = Parser()
    p.parse(Path(f"{TESTDIR}/feature_integration.rflx"))
    p.create_model()
示例#10
0
def assert_error_string(string: str, regex: str) -> None:
    p = Parser()
    with pytest.raises(RecordFluxError, match=regex):
        p.parse_string(string)
        p.create_model()
示例#11
0
def test_tls() -> None:
    p = Parser()
    for f in ["tls_alert.rflx", "tls_handshake.rflx", "tls_heartbeat.rflx", "tls_record.rflx"]:
        p.parse(Path(f"{SPECDIR}/{f}"))
    p.create_model()
示例#12
0
def assert_error_files(filenames: Sequence[str], regex: str) -> None:
    with pytest.raises(RecordFluxError, match=regex):
        p = Parser()
        for filename in filenames:
            p.parse(Path(filename))
        p.create_model()
示例#13
0
def assert_refinements_string(string: str, refinements: Sequence[Refinement]) -> None:
    p = Parser()
    p.parse_string(string)
    model = p.create_model()
    assert model.refinements == refinements