Skip to content

Commit

Permalink
feat: Allow empty BU_: nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxDevon committed Mar 16, 2024
1 parent 00df6ba commit 9d42141
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,6 @@ jobs:
- name: Make build directory
run: cmake -Bbuild -H$GITHUB_WORKSPACE

- name: Run clang-tidy check
- name: Run build
run: cmake --build build

2 changes: 1 addition & 1 deletion src/dbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ DbcParser::DbcParser()
: version_re("^(VERSION)\\s\"(.*)\"")
, bit_timing_re("^(BS_:)")
, name_space_re("^(NS_)\\s\\:")
, node_re("^(BU_:)\\s((?:[\\w]+?\\s?)*)")
, node_re("^(BU_:)\\s?((?:[\\w]+?\\s?)*)?")
, message_re("^(BO_)\\s(\\d+)\\s(\\w+)\\:\\s(\\d+)\\s(\\w+|Vector__XXX)")
, value_re("^(VAL_)\\s(\\d+)\\s(\\w+)((?:\\s(\\d+)\\s\"([^\"]*)\")+)\\s;$")
,
Expand Down
27 changes: 27 additions & 0 deletions test/test_dbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,30 @@ VAL_ 123 State1 123 "Description 3" 0 "Description 4" ;)";
REQUIRE(signal2.value_descriptions.at(1).value == 0);
REQUIRE(signal2.value_descriptions.at(1).description == "Description 4");
}

TEST_CASE("Should parse DBC with empty BU_") {
std::string contents = R"(VERSION ""
NS_ :
BS_:
BU_:
BO_ 293 Msg1: 2 Vector__XXX
SG_ Wert7 : 0|16@1- (1,0) [0|0] "" Vector__XXX
BO_ 292 Msg2: 8 Vector__XXX
SG_ Wert8 : 56|8@1- (1,0) [0|0] "" Vector__XXX
)";
const auto filename = create_temporary_dbc_with(contents.c_str());

auto parser = Libdbc::DbcParser();
parser.parse_file(filename.c_str());

REQUIRE(parser.get_messages().size() == 2);
REQUIRE(parser.get_messages().at(0).name() == "Msg1");
REQUIRE(parser.get_messages().at(1).name() == "Msg2");
}

0 comments on commit 9d42141

Please sign in to comment.