diff --git a/src/fandango/language/grammar.py b/src/fandango/language/grammar.py index ea3dec8..5d2a2a7 100644 --- a/src/fandango/language/grammar.py +++ b/src/fandango/language/grammar.py @@ -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 diff --git a/tests/resources/b.txt b/tests/resources/b.txt new file mode 100644 index 0000000..63d8dbd --- /dev/null +++ b/tests/resources/b.txt @@ -0,0 +1 @@ +b \ No newline at end of file diff --git a/tests/resources/bitstream-a.fan b/tests/resources/bitstream-a.fan new file mode 100644 index 0000000..5ee33e3 --- /dev/null +++ b/tests/resources/bitstream-a.fan @@ -0,0 +1,2 @@ + ::= + + ::= 0 1 1 0 0 0 0 1 # Encodes b'a' diff --git a/tests/resources/rgb.fan b/tests/resources/rgb.fan index 444491c..25fbdb5 100644 --- a/tests/resources/rgb.fan +++ b/tests/resources/rgb.fan @@ -1,5 +1,5 @@ ::= - ::= * + ::= + ::= ::= b'r' ::= diff --git a/tests/test_cli.py b/tests/test_cli.py index daab381..8b38190 100755 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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" diff --git a/tests/test_parsing.py b/tests/test_parsing.py index fcf33f3..933f824 100755 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -273,7 +273,7 @@ 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) @@ -281,3 +281,28 @@ def test_bitstream(self): # 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) +