From 16d94a6e50eb81de9d9d438e1cce0746928597f3 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Sat, 11 Nov 2017 01:51:06 -0500 Subject: Introduce input ports. Ports are the lisp abstraction of files and streams. Actinide ports additionally guarantee a peek operation. This makes ``tokenize`` (now ``read_token``) callable as a lisp function, as it takes a port and reads one token from it. This is a substantial refactoring. As most of the state is now captured by closures, it's no longer practical to test individual states as readily. However, the top-level tokenizer tests exercise the full state space. --- tests/test_ports.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/test_ports.py (limited to 'tests/test_ports.py') diff --git a/tests/test_ports.py b/tests/test_ports.py new file mode 100644 index 0000000..c2d1e06 --- /dev/null +++ b/tests/test_ports.py @@ -0,0 +1,29 @@ +from hypothesis import given +from hypothesis.strategies import integers, text + +from actinide.ports import * + +@given(text(), integers(min_value=1, max_value=2**32 - 1)) +def test_read(input, n): + port = string_to_input_port(input) + output = read(port, n) + + assert input.startswith(output) + assert (len(output) == 0 and len(input) == 0) != (0 < len(output) <= n) + assert output + read_fully(port) == input + +@given(text(), integers(min_value=1, max_value=2**32 - 1)) +def test_peek(input, n): + port = string_to_input_port(input) + output = peek(port, n) + + assert input.startswith(output) + assert (len(output) == 0 and len(input) == 0) != (0 < len(output) <= n) + assert read_fully(port) == input + +@given(text(), integers(min_value=1, max_value=2**32 - 1)) +def test_read_fully(input, n): + port = string_to_input_port(input) + output = read_fully(port) + + assert output == input -- cgit v1.2.3