Skip to content

Commit

Permalink
Simplify ExprIoEofBits, adjust Python test specs
Browse files Browse the repository at this point in the history
  • Loading branch information
generalmimon committed Jul 22, 2023
1 parent fca4f1d commit 77090c3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 49 deletions.
25 changes: 7 additions & 18 deletions formats/expr_io_eof_bits.ksy
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,12 @@ seq:
- id: bar
type: b4
if: not _io.eof
# `_io.eof` is expected to be true, so we "assert" it like this - if `_io.eof`
# is false, it will attempt to consume 8 bytes, which would trigger a EOF
# exception.
- id: assert_io_eof_before_baz
size: '_io.eof ? 0 : 8'

# 0 bits available at this point. When parsing, this is basically guaranteed
# to fail with EOF exception immediately (because it would translate to
# requesting more bytes, which are not available). But when writing, it
# would succeed until an attempt to align the stream to a byte position is
# done - which should happen at the latest when the stream is closed.
# EOF reached here
- id: baz
type: b3

# `_io.eof` is expected to be true, so we "assert" it like this - if `_io.eof`
# is false, it will attempt to consume 8 bytes, which would trigger a EOF
# exception.
- id: assert_io_eof_after_baz
size: 8
type: b16
if: not _io.eof
- id: align
size: 0
- id: qux
type: b16
if: not _io.eof
17 changes: 11 additions & 6 deletions spec/ks/expr_io_eof_bits.kst
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
id: expr_io_eof_bits
data: nav_parent_switch.bin
exception: EndOfStreamError
# asserts:
# - actual: foo
# expected: 0x01_42_f
# - actual: bar
# expected: 0xf
asserts:
- actual: foo
expected: 0x01_42_f
- actual: bar
expected: 0xf
- actual: baz
expected: 'null'
- actual: align
expected: '[].as<bytes>'
- actual: qux
expected: 'null'
9 changes: 4 additions & 5 deletions spec/python/spec/test_expr_io_eof_bits.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 2 additions & 20 deletions spec/python/specwrite/test_expr_io_eof_bits.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 77090c3

Please sign in to comment.