-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle colons in ghdl sim parsing
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
def parse(text): | ||
lines = text.split("\n")[:-1] | ||
|
||
def split_first_five_colons(line): | ||
all_split = line.split(":") | ||
reassembled = all_split[0:5] + [":".join(all_split[5:])] | ||
return reassembled | ||
|
||
separated = [split_first_five_colons(line) for line in lines] | ||
fields = ("source", "line", "column", "time", "type", "content") | ||
|
||
def parse_line(line): | ||
parsed = dict(zip(fields, line)) | ||
parsed["type"] = parsed["type"][1:-1] | ||
parsed["time"] = parsed["time"][1:] | ||
parsed["line"] = int(parsed["line"]) | ||
parsed["column"] = int(parsed["column"]) | ||
return parsed | ||
|
||
return [parse_line(line) for line in separated] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from ._ghdl_report_parsing import parse | ||
|
||
|
||
def test_parse_ghdl_simulation_results_one_liner(): | ||
simulation_output = "my_test_bench.vhd:64:17:@4ps:(report note):my report message\n" | ||
expected = [ | ||
{ | ||
"source": "my_test_bench.vhd", | ||
"line": 64, | ||
"column": 17, | ||
"time": "4ps", | ||
"type": "report note", | ||
"content": "my report message", | ||
} | ||
] | ||
assert expected == parse(simulation_output) | ||
|
||
|
||
def test_parse_ghdl_another_line(): | ||
simulation_output = "A:1:2:@B:(C):D\n" | ||
expected = [ | ||
{ | ||
"source": "A", | ||
"line": 1, | ||
"column": 2, | ||
"time": "B", | ||
"type": "C", | ||
"content": "D", | ||
} | ||
] | ||
assert expected == parse(simulation_output) | ||
|
||
|
||
def test_parse_two_lines(): | ||
simulation_output = ( | ||
"source:1:1:@time:(type):content\nsource:1:1:@time:(type):content\nignored last" | ||
" line" | ||
) | ||
expected = [ | ||
{ | ||
"source": "source", | ||
"line": 1, | ||
"column": 1, | ||
"time": "time", | ||
"type": "type", | ||
"content": "content", | ||
} | ||
] * 2 | ||
assert expected == parse(simulation_output) | ||
|
||
|
||
def test_put_colon_content_in_content_field(): | ||
simulation_output = "A:1:2:@B:(C):D:e:f\n" | ||
assert "D:e:f" == parse(simulation_output)[0]["content"] |