Skip to content

Commit

Permalink
- t assert transformed types
Browse files Browse the repository at this point in the history
manual type checking in our loosely typed language
how:   use the wrapper on all the parameters passed to the lambda

Co-Authored-By: 4dsherwood <4dsherwood@users.noreply.github.com>
Co-Authored-By: Nitsan Avni <nitsanav@gmail.com>
Co-Authored-By: Susan Fung <38925660+susanfung@users.noreply.github.com>
Co-Authored-By: T. E. Green <78671457+Tegsy@users.noreply.github.com>
  • Loading branch information
5 people committed Apr 14, 2024
1 parent 1b29ba6 commit dc968ab
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/test_parse_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,19 @@ def test_with_3_parameters():
def to_int(s: str, t: type = str):
assert type(s) is t
return int(s)

counter = 0
def to(tin: type, tout: type):
def wrapped(input):
nonlocal counter
counter += 1
assert type(input) is tin
return tout(input)
return wrapped

parse = Parse.doc_string(auto_approve=True)
parse.transform3(str, int, int).verify_all(lambda s, i1, i2: s * (to_int(i1, int) + to_int(i2, int)))
parse.transform3(str, str, str).verify_all(lambda s, i1, i2: s * (to_int(i1,) + to_int(i2)))
parse.transform3( to(str, str), to(str, int), to(str, int)).verify_all(lambda a, b, c: to(str, str)(a) * (to(int, int)(b) + to(int, int)(c)))

assert counter == 6

# assert on all the paramaters

0 comments on commit dc968ab

Please sign in to comment.