Skip to content

Commit

Permalink
Merge pull request #332 from fandango-fuzzer/andreas
Browse files Browse the repository at this point in the history
Andreas
  • Loading branch information
joszamama authored Feb 10, 2025
2 parents c0cc30e + 2516aba commit e214e95
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/fandango/language/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,10 @@ def scan_bit(
byte = ord(word[w]) if isinstance(word, str) else word[w]
bit = (byte >> bit_count) & 1

if not state.dot.check(bit):
# LOGGER.debug(f"Checking {state.dot} against {bit}")
match, match_length = state.dot.check(bit)
if not match:
# LOGGER.debug(f"No match")
return False

# Found a match
Expand Down
1 change: 1 addition & 0 deletions tests/resources/b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b
2 changes: 2 additions & 0 deletions tests/resources/bitstream-a.fan
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<start> ::= <bit>+
<bit> ::= 0 1 1 0 0 0 0 1 # Encodes b'a'
2 changes: 1 addition & 1 deletion tests/resources/rgb.fan
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<start> ::= <rgb> <end>
<rgb> ::= <RGB>*
<rgb> ::= <RGB>+
<RGB> ::= <R> <G> <B>
<R> ::= b'r'
<G> ::= <g7> <g6> <g5> <g4> <g3> <g2> <g1> <g0>
Expand Down
9 changes: 0 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,6 @@ def test_unsat(self):
self.assertEqual("", out)
self.assertEqual(expected, err)

def test_parse(self):
command = shlex.split(
"fandango parse -f tests/resources/rgb.fan tests/resources/rgb.txt"
)
out, err, code = self.run_command(command)
self.assertEqual(0, code)
self.assertEqual("", out)
self.assertEqual("", err)

def test_binfinity(self):
command = shlex.split(
"fandango fuzz -f docs/binfinity.fan -n 1 --format=none --validate --random-seed 426912"
Expand Down
27 changes: 26 additions & 1 deletion tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,36 @@ def test_gif(self):
self.assertEqual("", out)
self.assertEqual(0, code)

class TestEntryParsing(TestCLIParsing):
class TestBitstreamParsing(TestCLIParsing):
def test_bitstream(self):
command = shlex.split("fandango parse -f tests/resources/bitstream.fan tests/resources/abcd.txt --validate")
out, err, code = self.run_command(command)
# Warns that the number of bits (1..5) may not be a multiple of eight, # which is correct
# self.assertEqual("", err)
self.assertEqual("", out)
self.assertEqual(0, code)

def test_bitstream_a(self):
command = shlex.split("fandango parse -f tests/resources/bitstream-a.fan tests/resources/a.txt --validate")
out, err, code = self.run_command(command)
self.assertEqual("", err)
self.assertEqual("", out)
self.assertEqual(0, code)

def test_bitstream_b(self):
command = shlex.split("fandango parse -f tests/resources/bitstream-a.fan tests/resources/b.txt --validate")
out, err, code = self.run_command(command)
# This should fail
self.assertNotEqual("", err)
self.assertEqual("", out)
self.assertEqual(1, code)

def test_rgb(self):
command = shlex.split(
"fandango parse -f tests/resources/rgb.fan tests/resources/rgb.txt --validate"
)
out, err, code = self.run_command(command)
self.assertEqual(0, code)
self.assertEqual("", out)
self.assertEqual("", err)

0 comments on commit e214e95

Please sign in to comment.