From 204e750dd5d736276ffb03a6d79aad00fb1688fb Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 25 Aug 2017 09:47:24 +0200 Subject: [PATCH] Add more f-string tests. --- test/test_fstring.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/test/test_fstring.py b/test/test_fstring.py index 1b06743..979708d 100644 --- a/test/test_fstring.py +++ b/test/test_fstring.py @@ -1,6 +1,6 @@ import pytest -from parso import load_grammar +from parso import load_grammar, ParserSyntaxError @pytest.fixture @@ -16,9 +16,38 @@ def grammar(): '{1!a:1}', '{1:1}', '{1:1.{32}}', + '{1::>4}', + '{foo} {bar}', + + # Invalid, but will be checked, later. + '{}', + '{1:}', + '{:}', + '{:1}', + '{!:}', + '{!}', + '{!a}', + '{1:{}}', + '{1:{:}}', ] ) def test_valid(code, grammar): fstring = grammar.parse(code, error_recovery=False) assert fstring.type == 'fstring' assert fstring.get_code() == code + + +@pytest.mark.parametrize( + 'code', [ + '}', + '{', + '{1!{a}}', + '{!{a}}', + ] +) +def test_invalid(code, grammar): + with pytest.raises(ParserSyntaxError): + grammar.parse(code, error_recovery=False) + + # It should work with error recovery. + grammar.parse(code, error_recovery=True)