diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-06-27 12:24:24 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-06-27 12:24:24 -0700 |
commit | 05568fe9381b1685890f74d9ac91651ff0c0de2c (patch) | |
tree | c853c1fb4a00bedf0b7aad097c6f5dab83e1f3e6 | |
parent | bef2768278784550d8364a701d877887457f4dc1 (diff) | |
download | txr-05568fe9381b1685890f74d9ac91651ff0c0de2c.tar.gz txr-05568fe9381b1685890f74d9ac91651ff0c0de2c.tar.bz2 txr-05568fe9381b1685890f74d9ac91651ff0c0de2c.zip |
regex-from-trie: correctly handle empty trie.
* filter.c (regex_from_trie): An empty trie matches nothing,
so we must return the t regex syntax (match nothing), not
nil (match empty string). A hash-based trie matches nothing
if it is empty; but if it has user data, then it matches
the empty string.
* tests/015/trie.tl: Test cases added.
-rw-r--r-- | filter.c | 4 | ||||
-rw-r--r-- | tests/015/trie.tl | 4 |
2 files changed, 6 insertions, 2 deletions
@@ -121,7 +121,7 @@ static val regex_from_trie(val trie) { switch (type(trie)) { case NIL: - return nil; + return t; case CONS: { val a = car(trie); @@ -145,7 +145,7 @@ static val regex_from_trie(val trie) case COBJ: if (trie->co.cls == hash_s) { if (zerop(hash_count(trie))) { - return nil; + return tnil(!get_hash_userdata(trie)); } else { val out = nil; val cell; diff --git a/tests/015/trie.tl b/tests/015/trie.tl index de88a797..c145c060 100644 --- a/tests/015/trie.tl +++ b/tests/015/trie.tl @@ -52,3 +52,7 @@ (mvtest (build (each ((d dat)) (add [rx1 d]))) dat (build (each ((n ndt)) (add [rx1 n]))) (repeat '(nil) (len dat))) + +(mtest + (regex-from-trie (make-trie)) t + (regex-from-trie (trie-compress (make-trie))) t) |