diff --git a/python/testData/resolve/FormatDoubleStarArgument.py b/python/testData/resolve/FormatDoubleStarArgument.py new file mode 100644 index 000000000000..7d836c3ea1dd --- /dev/null +++ b/python/testData/resolve/FormatDoubleStarArgument.py @@ -0,0 +1 @@ +print "first is {fst}, second is {snd}".format(**{"fst": "f", "snd": "s"}) \ No newline at end of file diff --git a/python/testData/resolve/FormatStringWithBinExprAsArg.py b/python/testData/resolve/FormatStringWithBinExprAsArg.py new file mode 100644 index 000000000000..f2dd1d78671d --- /dev/null +++ b/python/testData/resolve/FormatStringWithBinExprAsArg.py @@ -0,0 +1 @@ +v = "first is {}, second is""{}".format(("fst", ) + ("snd", )) \ No newline at end of file diff --git a/python/testData/resolve/FormatStringWithPackedDictAsArgument.py b/python/testData/resolve/FormatStringWithPackedDictAsArgument.py new file mode 100644 index 000000000000..fc67dfaf2728 --- /dev/null +++ b/python/testData/resolve/FormatStringWithPackedDictAsArgument.py @@ -0,0 +1 @@ +v = "first is" "{fst}, second is {snd}".format(**{"fst": "f", "snd": "s"}) \ No newline at end of file diff --git a/python/testData/resolve/FormatStringWithPackedListAsArgument.py b/python/testData/resolve/FormatStringWithPackedListAsArgument.py new file mode 100644 index 000000000000..87b9dc8ee7a7 --- /dev/null +++ b/python/testData/resolve/FormatStringWithPackedListAsArgument.py @@ -0,0 +1 @@ +print "first is {}, second is {}".format(*[1, 2]) \ No newline at end of file diff --git a/python/testData/resolve/FormatStringWithPackedTupleAsArgument.py b/python/testData/resolve/FormatStringWithPackedTupleAsArgument.py new file mode 100644 index 000000000000..fb3414b5d71e --- /dev/null +++ b/python/testData/resolve/FormatStringWithPackedTupleAsArgument.py @@ -0,0 +1 @@ +v = "first is {}, second is {}".format(*("fst", "snd")) \ No newline at end of file diff --git a/python/testData/resolve/FormatStringWithRefAsArgument.py b/python/testData/resolve/FormatStringWithRefAsArgument.py new file mode 100644 index 000000000000..b5da9c3a5e87 --- /dev/null +++ b/python/testData/resolve/FormatStringWithRefAsArgument.py @@ -0,0 +1,2 @@ +reference = (1, 2) +v = "first is {}, second is {}".format(*reference) \ No newline at end of file diff --git a/python/testData/resolve/PercentKeyWordArgs.py b/python/testData/resolve/PercentKeyWordArgs.py index e7345375c532..97188523141a 100644 --- a/python/testData/resolve/PercentKeyWordArgs.py +++ b/python/testData/resolve/PercentKeyWordArgs.py @@ -1 +1 @@ -"This is my favourite number%(""kwg)d!" % {'kwg': 4181} \ No newline at end of file +"This is my favourite number%(""kwg)d!" % {'kwg': 4181} diff --git a/python/testData/resolve/PercentStringArgWithRedundantParentheses.py b/python/testData/resolve/PercentStringArgWithRedundantParentheses.py index 351908048735..eaad91f7d66e 100644 --- a/python/testData/resolve/PercentStringArgWithRedundantParentheses.py +++ b/python/testData/resolve/PercentStringArgWithRedundantParentheses.py @@ -1 +1 @@ -print("%d%s" % ((("1", " ")))) \ No newline at end of file +print("%s%s" % ((("1", " ")))) \ No newline at end of file diff --git a/python/testData/resolve/PercentStringKeyWordArgWithParentheses.py b/python/testData/resolve/PercentStringKeyWordArgWithParentheses.py new file mode 100644 index 000000000000..f869a7fad425 --- /dev/null +++ b/python/testData/resolve/PercentStringKeyWordArgWithParentheses.py @@ -0,0 +1 @@ +v = "first is %(fst)s, second is" "%(snd)s" % ({"fst": "f", "snd": "s"}) \ No newline at end of file diff --git a/python/testData/resolve/PercentStringWithRefAsArgument.py b/python/testData/resolve/PercentStringWithRefAsArgument.py new file mode 100644 index 000000000000..5f884037a27d --- /dev/null +++ b/python/testData/resolve/PercentStringWithRefAsArgument.py @@ -0,0 +1,2 @@ +tuple = (1, 2) +v = "first is" "%s, second is %s" % tuple \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyResolveTest.java b/python/testSrc/com/jetbrains/python/PyResolveTest.java index b18a7ee770b2..126892f9af5e 100644 --- a/python/testSrc/com/jetbrains/python/PyResolveTest.java +++ b/python/testSrc/com/jetbrains/python/PyResolveTest.java @@ -637,6 +637,36 @@ public class PyResolveTest extends PyResolveTestCase { assertTrue(target instanceof PyKeywordArgument); assertEquals("kwd", ((PyKeywordArgument)target).getKeyword()); } + + public void testFormatStringWithPackedDictAsArgument() { + PsiElement target = resolve(); + assertTrue(target instanceof PyStringLiteralExpression); + assertEquals("\"fst\"", target.getText()); + } + + public void testFormatStringWithPackedListAsArgument() { + PsiElement target = resolve(); + assertTrue(target instanceof PyNumericLiteralExpression); + assertEquals("1", target.getText()); + } + + public void testFormatStringWithPackedTupleAsArgument() { + PsiElement target = resolve(); + assertTrue(target instanceof PyStringLiteralExpression); + assertEquals("\"snd\"", target.getText()); + } + + public void testFormatStringWithBinExprAsArg() { + PsiElement target = resolve(); + assertTrue(target instanceof PyStringLiteralExpression); + assertEquals("\"snd\"", target.getText()); + } + + public void testFormatStringWithRefAsArgument() { + PsiElement target = resolve(); + assertEquals(null, target); + } + //PY-2478 public void testPercentPositionalArgs() { @@ -654,22 +684,36 @@ public class PyResolveTest extends PyResolveTestCase { // PY-18254 public void testFunctionTypeComment() { assertResolvesTo(PyClass.class, "MyClass"); - } - - public void testGlobalNotDefinedAtTopLevel() { - assertResolvesTo(PyTargetExpression.class, "foo"); + } + + public void testPercentStringKeyWordArgWithParentheses() { + PsiElement target = resolve(); + assertTrue(target instanceof PyStringLiteralExpression); + assertEquals("snd", ((PyStringLiteralExpression)target).getStringValue()); } //PY-2478 public void testPercentStringBinaryStatementArg() { PsiElement target = resolve(); assertTrue(target instanceof PyStringLiteralExpression); - assertTrue(((PyStringLiteralExpression)target).getStringValue().equals("1")); + assertEquals("1", ((PyStringLiteralExpression)target).getStringValue()); } + //PY-2478 public void testPercentStringArgWithRedundantParentheses() { PsiElement target = resolve(); assertTrue(target instanceof PyStringLiteralExpression); - assertTrue(((PyStringLiteralExpression)target).getStringValue().equals("1")); + assertEquals("1", ((PyStringLiteralExpression)target).getStringValue()); } + + public void testPercentStringWithRefAsArgument() { + PsiElement target = resolve(); + assertEquals(null, target); + } + + + public void testGlobalNotDefinedAtTopLevel() { + assertResolvesTo(PyTargetExpression.class, "foo"); + } + }