|
| 1 | +import pytest |
| 2 | + |
| 3 | + |
| 4 | +from wasm.sexpressions import ( |
| 5 | + sexp_parser, |
| 6 | +) |
| 7 | + |
| 8 | +# Test vectors from: http://www.ccp4.ac.uk/dist/checkout/pyparsing-2.0.1/examples/sexpParser.py |
| 9 | + |
| 10 | +test00 = """(snicker "abc" (#03# |YWJj|))""" |
| 11 | +test01 = """(certificate |
| 12 | + (issuer |
| 13 | + (name |
| 14 | + (public-key |
| 15 | + rsa-with-md5 |
| 16 | + (e 15 |NFGq/E3wh9f4rJIQVXhS|) |
| 17 | + (n |d738/4ghP9rFZ0gAIYZ5q9y6iskDJwASi5rEQpEQq8ZyMZeIZzIAR2I5iGE=|)) |
| 18 | + aid-committee)) |
| 19 | + (subject |
| 20 | + (ref |
| 21 | + (public-key |
| 22 | + rsa-with-md5 |
| 23 | + (e |NFGq/E3wh9f4rJIQVXhS|) |
| 24 | + (n |d738/4ghP9rFZ0gAIYZ5q9y6iskDJwASi5rEQpEQq8ZyMZeIZzIAR2I5iGE=|)) |
| 25 | + tom |
| 26 | + mother)) |
| 27 | + (not-before "1997-01-01_09:00:00") |
| 28 | + (not-after "1998-01-01_09:00:00") |
| 29 | + (tag |
| 30 | + (spend (account "12345678") (* numeric range "1" "1000")))) |
| 31 | +""" |
| 32 | +test02 = """(lambda (x) (* x x))""" |
| 33 | +test03 = """(def length |
| 34 | + (lambda (x) |
| 35 | + (cond |
| 36 | + ((not x) 0) |
| 37 | + ( t (+ 1 (length (cdr x)))) |
| 38 | + ) |
| 39 | + ) |
| 40 | +) |
| 41 | +""" |
| 42 | +test04 = """(2:XX "abc" (#03# |YWJj|))""" |
| 43 | +test05 = """(if (is (window_name) "XMMS") (set_workspace 2))""" |
| 44 | +test06 = """(if |
| 45 | + (and |
| 46 | + (is (application_name) "Firefox") |
| 47 | + (or |
| 48 | + (contains (window_name) "Enter name of file to save to") |
| 49 | + (contains (window_name) "Save As") |
| 50 | + (contains (window_name) "Save Image") |
| 51 | + () |
| 52 | + ) |
| 53 | + ) |
| 54 | + (geometry "+140+122") |
| 55 | +) |
| 56 | +""" |
| 57 | +test07 = """(defun factorial (x) |
| 58 | + (if (zerop x) 1 |
| 59 | + (* x (factorial (- x 1))))) |
| 60 | + """ |
| 61 | +test51 = """(2:XX "abc" (#30# |YWJj|))""" |
| 62 | +test51error = """(3:XX "abc" (#30# |YWJj|))""" |
| 63 | + |
| 64 | +test52 = """ |
| 65 | + (and |
| 66 | + (or (> uid 1000) |
| 67 | + (!= gid 20) |
| 68 | + ) |
| 69 | + (> quota 5.0e+03) |
| 70 | + ) |
| 71 | + """ |
| 72 | + |
| 73 | + |
| 74 | +@pytest.mark.parametrize( |
| 75 | + 'value', |
| 76 | + ( |
| 77 | + test00, |
| 78 | + ), |
| 79 | +) |
| 80 | +def test_base_sexpression_parser(value): |
| 81 | + sexp = sexp_parser.parseString(value, parseAll=True) |
| 82 | + assert sexp |
0 commit comments