Skip to content

Commit

Permalink
Implement formatting of assert statements
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Nov 22, 2024
1 parent 5ea3d04 commit 7f4bd64
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,10 @@ function comments()

function no_comments()
{ }

# Assert.
function foo()
{
assert 1 == 2, "One is not two";
assert 1 == 1;
}
5 changes: 5 additions & 0 deletions tests/samples/test1.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,9 @@ function no_comments()
{
}

# Assert.
function foo() {
assert 1 == 2, "One is not two";
assert 1 == 1;
}

10 changes: 10 additions & 0 deletions zeekscript/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,12 @@ def format(self):
self._format_child() # <preproc_directive>
self._write_nl()

elif start_token == "assert":
self._format_child() # 'assert'
self._write_sp()
self._format_children()
self._write_nl()

elif start_token == ";":
self._format_child(hints=Hint.NO_LB_BEFORE) # ';'
self._write_nl()
Expand Down Expand Up @@ -1087,6 +1093,10 @@ def format(self):
self._format_child(hints=Hint.NO_LB_BEFORE) # ')'


class AssertMsgFormatter(SpaceSeparatedFormatter):
pass


class ExprFormatter(SpaceSeparatedFormatter, ComplexSequenceFormatterMixin):
# Like statments, expressions aren't currently broken into specific symbol
# types, so we use helpers or parse into them to identify what particular
Expand Down

0 comments on commit 7f4bd64

Please sign in to comment.