Skip to content

Adding support for String.format function #1105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
8 changes: 8 additions & 0 deletions regression/strings-smoke-tests/java_format/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
test.class
--refine-strings --string-max-length 20
^EXIT=10$
^SIGNAL=0$
^\[.*assertion.1\].* line 6.* SUCCESS$
^\[.*assertion.2\].* line 7.* FAILURE$
--
10 changes: 10 additions & 0 deletions regression/strings-smoke-tests/java_format/test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class test
{
public static String main()
{
String s = String.format("foo %s", "bar");
assert(s.equals("foo bar"));
assert(!s.equals("foo bar"));
return s;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this behave with non-constant arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test where the second argument is not constant and this works fine

public static String main(String str)
    {
        String s = String.format("foo %s", str);
        assert(s.equals("foo ".concat(str)));
        assert(!s.equals("foo ".concat(str)));
        return s;
    }

When the first argument of format (the format specifier) is not constant then the result should be non-deterministic I can add an example of that (marked as KNOWNBUG) and some others with indexes, and more than 10 arguments for example.

Binary file not shown.
8 changes: 8 additions & 0 deletions regression/strings-smoke-tests/java_format2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
test.class
--refine-strings --string-max-length 20
^EXIT=10$
^SIGNAL=0$
^\[.*assertion.1\].* line 6.* SUCCESS$
^\[.*assertion.2\].* line 7.* FAILURE$
--
10 changes: 10 additions & 0 deletions regression/strings-smoke-tests/java_format2/test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class test
{
public static String main(String str)
{
String s = String.format("foo %s", str);
assert(s.equals("foo ".concat(str)));
assert(!s.equals("foo ".concat(str)));
return s;
}
}
Binary file not shown.
8 changes: 8 additions & 0 deletions regression/strings-smoke-tests/java_format3/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
test.class
--refine-strings --string-max-length 20
^EXIT=10$
^SIGNAL=0$
^\[.*assertion.1\].* line 7.* SUCCESS$
^\[.*assertion.2\].* line 9.* FAILURE$
--
12 changes: 12 additions & 0 deletions regression/strings-smoke-tests/java_format3/test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class test
{
public static String main(int i)
{
String s = String.format("%3$sar", "a", "r", "b");
if(i==0)
assert(s.equals("bar"));
else
assert(!s.equals("bar"));
return s;
}
}
Binary file not shown.
8 changes: 8 additions & 0 deletions regression/strings-smoke-tests/java_format4/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
KNOWNBUG
test.class
--refine-strings --string-max-length 20
^EXIT=10$
^SIGNAL=0$
^\[.*assertion.1\].* line 8.* SUCCESS$
^\[.*assertion.2\].* line 13.* FAILURE$
--
17 changes: 17 additions & 0 deletions regression/strings-smoke-tests/java_format4/test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class test
{
public static String main(String str)
{
try
{
String s = String.format("%s %s", "a");
assert(false);
return s;
}
catch(java.util.IllegalFormatException e)
{
assert(false);
return str;
}
}
}
Binary file not shown.
8 changes: 8 additions & 0 deletions regression/strings-smoke-tests/java_format5/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
THOROUGH
test.class
--refine-strings --string-max-length 20
^EXIT=10$
^SIGNAL=0$
^\[.*assertion.1\].* line 7.* SUCCESS$
^\[.*assertion.2\].* line 9.* FAILURE$
--
12 changes: 12 additions & 0 deletions regression/strings-smoke-tests/java_format5/test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class test
{
public static String main(boolean b)
{
String s = String.format("%s%s%s%s%s%s%s%s", "a", "b", "c", "d", "e", "f", "g", "h");
if(b)
assert(s.equals("abcdefgh"));
else
assert(!s.equals("abcdefgh"));
return s;
}
}
Loading