Init Commit: Moved bproto to seperate repo

This commit is contained in:
AlexanderHD27
2025-04-14 14:43:03 +02:00
commit 45bfc724fc
125 changed files with 10822 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import sys
import pytest
from typing import Any
sys.path.append('src/')
from protocol_components.dtypes import BprotoFieldBaseType
from parser.parser import create_ast_parser, bproto_ErrorListener
from parser.ast_visitor import BprotoASTVisitor
@pytest.mark.parametrize("source_text,expected_output", [
("uint64\n", (BprotoFieldBaseType.UINT64, 1, None)),
("float32\n", (BprotoFieldBaseType.FLOAT32, 1, None)),
("float32[8]\n", (BprotoFieldBaseType.FLOAT32, 8, None)),
])
def test_ast_field_dtype_defintion(
source_text: str,
expected_output: tuple[BprotoFieldBaseType, int, Any]):
err_listner = bproto_ErrorListener()
parser = create_ast_parser(source_text, err_listner)
ast = parser.dtype()
vinterp = BprotoASTVisitor()
assert len(err_listner.syntax_error_list) == 0
res = vinterp.visit(ast)
assert isinstance(res, tuple)
assert len(res) == 3
# Correct dtype
assert res[0] == expected_output[0].value
# Correct array size
assert res[1] == expected_output[1]
# Correct refrerence; Should normally be None be Non
assert res[2] == expected_output[2]

View File

@@ -0,0 +1,23 @@
import sys
sys.path.append('src/')
from parser.parser import create_ast_parser, bproto_ErrorListener
from parser.ast_visitor import BprotoASTVisitor
def test_ast_tag_line():
source = "protocol HCP version 25\n"
err_listner = bproto_ErrorListener()
parser = create_ast_parser(source, err_listner)
ast = parser.protocol_header()
vinterp = BprotoASTVisitor()
assert len(err_listner.syntax_error_list) == 0
res = vinterp.visit(ast)
assert isinstance(res, tuple)
assert len(res) == 2
name, version = res
assert name == "HCP"
assert version == 25