Skip to content

Commit

Permalink
parser testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
lyxal committed Aug 1, 2021
1 parent e64f852 commit ceefdc0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
68 changes: 66 additions & 2 deletions tests/test_parser.py
Expand Up @@ -8,9 +8,73 @@
from vyxal.parser import *


def fully_parse(program: str) -> list[Structure]:
"""
Essentially, wrap tokenise(program) in parse
Parameters
----------
program : str
The program to tokenise and then parse
Returns
-------
list[Structure]
Quite literally parse(tokenise(program))
"""

return parse(tokenise(program)) # see what I mean?


def test_basic():
assert (
str(fully_parse("1 1+"))
== "[['none', ['number', '1']], ['none', ['number', '1']], "
+ "['none', ['general', '+']]]"
)

assert (
str(fully_parse("`Hello, World!`"))
== "[['none', ['string', " + "'Hello, World!']]]"
)


def test_fizzbuzz():
assert eval(str(fully_parse("₁ƛ₍₃₅kF½*∑∴"))) == [
["none", ["general", "₁"]],
[
"lambda",
[
"1",
[
[
"dyadic_modifier",
[
"₍",
[
["none", ["general", "₃"]],
["none", ["general", "₅"]],
],
],
],
["none", ["general", "kF"]],
["none", ["general", "½"]],
["none", ["general", "*"]],
["none", ["general", "∑"]],
["none", ["general", "∴"]],
],
],
],
["none", ["general", "M"]],
]


if __name__ == "__main__": # For testing outside of the workflow
print(tokenise("1 1+"))
print(parse(tokenise("1 1 +")))

print(tokenise("₁ƛ₍₃₅kF½*∑∴"))
print(parse(tokenise("₁ƛ₍₃₅kF½*∑∴")))
print
test_basic()
test_fizzbuzz()
1 change: 0 additions & 1 deletion vyxal/parser.py
Expand Up @@ -272,7 +272,6 @@ def parse(tokens: list[lexer.Token]) -> list[Structure]:
# next value isn't the closing character for the
# structure (i.e. isn't Token(TokenType.GENERAL, "x"))
# where x = the corresponding closing character).
print(bracket_stack, tokens)
token: lexer.Token = tokens.popleft()
if token.value in OPENING_CHARACTERS:
branches[-1].append(token)
Expand Down

0 comments on commit ceefdc0

Please sign in to comment.