summaryrefslogtreecommitdiff
path: root/tests/test_ports.py
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2017-11-11 01:51:06 -0500
committerOwen Jacobson <owen@grimoire.ca>2017-11-11 15:42:13 -0500
commit16d94a6e50eb81de9d9d438e1cce0746928597f3 (patch)
treee1cb628d34c49690128722a33cc1d19d7dcffb23 /tests/test_ports.py
parente4fb8604aa2fc572a3aeeace1c32de7339d346b5 (diff)
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.
Diffstat (limited to 'tests/test_ports.py')
-rw-r--r--tests/test_ports.py29
1 files changed, 29 insertions, 0 deletions
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