Skip to content

Commit

Permalink
Merge pull request #224 from amaanq/tests
Browse files Browse the repository at this point in the history
feat: add tests
  • Loading branch information
amaanq committed Jul 10, 2023
2 parents 36f9e33 + 64cf905 commit aa16a37
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 21 deletions.
13 changes: 0 additions & 13 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,6 @@ static inline void set_end_character(Delimiter *delimiter, int32_t character) {
}
}

static inline const char *delimiter_string(Delimiter *delimiter) {
if (delimiter->flags & SingleQuote) {
return "\'";
}
if (delimiter->flags & DoubleQuote) {
return "\"";
}
if (delimiter->flags & BackQuote) {
return "`";
}
return "";
}

typedef struct {
uint32_t len;
uint32_t cap;
Expand Down
86 changes: 82 additions & 4 deletions test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ Await expressions

await i(j, 5)
return await i(j, 5)
async def region_exists(region: str) -> bool:
return region in await all_regions()

--------------------------------------------------------------------------------

Expand All @@ -112,7 +114,24 @@ return await i(j, 5)
(identifier)
(argument_list
(identifier)
(integer))))))
(integer)))))
(function_definition
(identifier)
(parameters
(typed_parameter
(identifier)
(type
(identifier))))
(type
(identifier))
(block
(return_statement
(comparison_operator
(identifier)
(await
(call
(identifier)
(argument_list))))))))

================================================================================
Call expressions
Expand Down Expand Up @@ -918,6 +937,32 @@ Tuples with yield
(identifier)
(identifier))))))

================================================================================
Default Tuple Arguments
================================================================================

def comp_args((a, b)=(3, 4)):
return a, b

--------------------------------------------------------------------------------

(module
(function_definition
(identifier)
(parameters
(default_parameter
(tuple_pattern
(identifier)
(identifier))
(tuple
(integer)
(integer))))
(block
(return_statement
(expression_list
(identifier)
(identifier))))))

================================================================================
Conditional if expressions
================================================================================
Expand Down Expand Up @@ -984,9 +1029,9 @@ async with a as b:
left: (identifier)
right: (identifier)))))))))

===========================================
================================================================================
Arbitrary indentation between brackets
==========================================
================================================================================

def a():
b(
Expand All @@ -998,7 +1043,7 @@ def a():
3
]

---
--------------------------------------------------------------------------------

(module
(function_definition
Expand All @@ -1016,3 +1061,36 @@ def a():
(identifier)
(list
(integer)))))))

================================================================================
Splat Inside of Expression List
================================================================================

a,c = [1,2],3
w, x, y, z = 0, *a, c

--------------------------------------------------------------------------------

(module
(expression_statement
(assignment
(pattern_list
(identifier)
(identifier))
(expression_list
(list
(integer)
(integer))
(integer))))
(expression_statement
(assignment
(pattern_list
(identifier)
(identifier)
(identifier)
(identifier))
(expression_list
(integer)
(list_splat
(identifier))
(identifier)))))
43 changes: 42 additions & 1 deletion test/corpus/literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ string"
b"\x12\u12\U12\x13\N{WINKING FACE}"
"\xab\123\'\"\a\b\f\r\n\t\v\\"
"\xgh\o123\p\q\c\d\e\u12\U1234"
f'\N{GREEK CAPITAL LETTER DELTA}'

--------------------------------------------------------------------------------

Expand Down Expand Up @@ -213,6 +214,12 @@ b"\x12\u12\U12\x13\N{WINKING FACE}"
(string
(string_start)
(string_content)
(string_end)))
(expression_statement
(string
(string_start)
(string_content
(escape_sequence))
(string_end))))

================================================================================
Expand Down Expand Up @@ -311,6 +318,12 @@ f"a {{b}}"
f"a {{{b}}}"
f"{c,}"
f"{yield d}"
f"{*a,}"

def function():
return f"""
{"string1" if True else
"string2"}"""

--------------------------------------------------------------------------------

Expand Down Expand Up @@ -395,7 +408,35 @@ f"{yield d}"
(interpolation
(yield
(identifier)))
(string_end))))
(string_end)))
(expression_statement
(string
(string_start)
(interpolation
(expression_list
(list_splat
(identifier))))
(string_end)))
(function_definition
(identifier)
(parameters)
(block
(return_statement
(string
(string_start)
(string_content)
(interpolation
(conditional_expression
(string
(string_start)
(string_content)
(string_end))
(true)
(string
(string_start)
(string_content)
(string_end))))
(string_end))))))

================================================================================
Format strings with format specifiers
Expand Down
35 changes: 32 additions & 3 deletions test/corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ print a
print b, c
print 0 or 1, 1 or 0,
print 0 or 1
print not True

--------------------------------------------------------------------------------

Expand All @@ -143,7 +144,10 @@ print 0 or 1
(print_statement
(boolean_operator
(integer)
(integer))))
(integer)))
(print_statement
(not_operator
(true))))

================================================================================
Print statements with redirection
Expand Down Expand Up @@ -808,6 +812,11 @@ def h(*a):
i((*a))
j(((*a)))

def foo():
pass \
\
\

--------------------------------------------------------------------------------

(module
Expand Down Expand Up @@ -889,7 +898,15 @@ def h(*a):
(parenthesized_expression
(parenthesized_expression
(list_splat
(identifier))))))))))
(identifier)))))))))
(function_definition
name: (identifier)
parameters: (parameters)
body: (block
(pass_statement)))
(line_continuation)
(line_continuation)
(line_continuation))

================================================================================
Empty blocks
Expand Down Expand Up @@ -1270,6 +1287,8 @@ Exec statements
exec '1+1'
exec 'x+=1' in None
exec 'x+=1' in a, b
func = "print"
exec func in {}

--------------------------------------------------------------------------------

Expand All @@ -1291,7 +1310,17 @@ exec 'x+=1' in a, b
(string_content)
(string_end))
(identifier)
(identifier)))
(identifier))
(expression_statement
(assignment
(identifier)
(string
(string_start)
(string_content)
(string_end))))
(exec_statement
(identifier)
(dictionary)))

================================================================================
Extra newlines
Expand Down

0 comments on commit aa16a37

Please sign in to comment.