Class FormatUtilTest
java.lang.Object
org.checkerframework.checker.formatter.util.FormatUtilTest
Tests for
FormatUtil, verifying that the relative index flag (<) takes precedence
over an explicit argument index when both appear in the same format specifier.
According to the Java Formatter specification, the < flag causes a
format specifier to reuse the argument from the previous specifier, regardless of any explicit
index. For example, String.format("%2$s %1$<s", "a", "b") produces "b b", not
"b a".
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidVerifies that%1$<sis treated as a relative index, not an explicit reference to argument 1.voidSame precedence check as above but with a higher explicit index (3$), ensuring the fix is not specific to index 1.
-
Constructor Details
-
FormatUtilTest
public FormatUtilTest()
-
-
Method Details
-
testRelativeIndex_precedenceOverExplicitIndex
public void testRelativeIndex_precedenceOverExplicitIndex()Verifies that%1$<sis treated as a relative index, not an explicit reference to argument 1.Format string:
"%2$s %1$<s"with arguments("a", "b").%2$sexplicitly references argument 2 (index 1).%1$<sshould reuse the previous argument (index 1) due to the<flag, ignoring the explicit1$.
Therefore argument 1 (index 0) is UNUSED. Before the fix, FormatUtil checked for an explicit index first, incorrectly treating
%1$<sas a reference to argument 1. -
testRelativeIndex_precedenceOverExplicitIndex_higherIndex
public void testRelativeIndex_precedenceOverExplicitIndex_higherIndex()Same precedence check as above but with a higher explicit index (3$), ensuring the fix is not specific to index 1.Format string:
"%2$s %3$<d".%2$sexplicitly references argument 2 (index 1) as GENERAL.%3$<dshould reuse the previous argument (index 1) due to the<flag, intersecting GENERAL with INT to yield INT.
Only 2 arguments are needed (index 0 is UNUSED, index 1 is INT), not 3.
-