summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unparse.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_unparse.py')
-rw-r--r--Lib/test/test_unparse.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py
index f5be13a..e38b335 100644
--- a/Lib/test/test_unparse.py
+++ b/Lib/test/test_unparse.py
@@ -344,7 +344,17 @@ class UnparseTestCase(ASTTestCase):
self.check_ast_roundtrip("a[i]")
self.check_ast_roundtrip("a[i,]")
self.check_ast_roundtrip("a[i, j]")
+ # The AST for these next two both look like `a[(*a,)]`
self.check_ast_roundtrip("a[(*a,)]")
+ self.check_ast_roundtrip("a[*a]")
+ self.check_ast_roundtrip("a[b, *a]")
+ self.check_ast_roundtrip("a[*a, c]")
+ self.check_ast_roundtrip("a[b, *a, c]")
+ self.check_ast_roundtrip("a[*a, *a]")
+ self.check_ast_roundtrip("a[b, *a, *a]")
+ self.check_ast_roundtrip("a[*a, b, *a]")
+ self.check_ast_roundtrip("a[*a, *a, b]")
+ self.check_ast_roundtrip("a[b, *a, *a, c]")
self.check_ast_roundtrip("a[(a:=b)]")
self.check_ast_roundtrip("a[(a:=b,c)]")
self.check_ast_roundtrip("a[()]")
@@ -543,9 +553,23 @@ class CosmeticTestCase(ASTTestCase):
self.check_src_roundtrip(f"{prefix} 1")
def test_slices(self):
+ self.check_src_roundtrip("a[()]")
self.check_src_roundtrip("a[1]")
self.check_src_roundtrip("a[1, 2]")
- self.check_src_roundtrip("a[(1, *a)]")
+ # Note that `a[*a]`, `a[*a,]`, and `a[(*a,)]` all evaluate to the same
+ # thing at runtime and have the same AST, but only `a[*a,]` passes
+ # this test, because that's what `ast.unparse` produces.
+ self.check_src_roundtrip("a[*a,]")
+ self.check_src_roundtrip("a[1, *a]")
+ self.check_src_roundtrip("a[*a, 2]")
+ self.check_src_roundtrip("a[1, *a, 2]")
+ self.check_src_roundtrip("a[*a, *a]")
+ self.check_src_roundtrip("a[1, *a, *a]")
+ self.check_src_roundtrip("a[*a, 1, *a]")
+ self.check_src_roundtrip("a[*a, *a, 1]")
+ self.check_src_roundtrip("a[1, *a, *a, 2]")
+ self.check_src_roundtrip("a[1:2, *a]")
+ self.check_src_roundtrip("a[*a, 1:2]")
def test_lambda_parameters(self):
self.check_src_roundtrip("lambda: something")