diff options
author | Tor Norbye <tnorbye@google.com> | 2011-10-03 09:15:23 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-10-03 14:19:02 -0700 |
commit | 9d1535a9108bb1c00579ed41d26cf99f8fcf6ea2 (patch) | |
tree | d2837a6b973067f0f0d611546528b6a0010e04d1 /eclipse/plugins/com.android.ide.eclipse.tests | |
parent | 0ceec0d0fb84c9fa00fb7971998e9adbbceae657 (diff) | |
download | sdk-9d1535a9108bb1c00579ed41d26cf99f8fcf6ea2.zip sdk-9d1535a9108bb1c00579ed41d26cf99f8fcf6ea2.tar.gz sdk-9d1535a9108bb1c00579ed41d26cf99f8fcf6ea2.tar.bz2 |
XML Comment Formatting Fixes
This changeset fixes issue 20452 related to XML comment
handling. There are several changes.
First it fixes a truncation bug where the last character in a comment
could get erased.
Second it makes sure we don't end up with double blank lines, since
there were cases where the comment formatter would insert a newline
(to preserve newlines after comments in the original document) and a
subsequent element or close tag would also insert a newline (which is
where the normal blank lines are added). Now the code will peek at the
write buffer to make sure we haven't already added a blank line.
Third, it attempts to handle multiline comments a bit better such that
the code which preserves indentation of the first comment line will
dedent down to the minimum indentation level of the block comment.
This means that we will format
<!-- First
Second -->
into
<!--
First
Second
-->
instead of
<!--
First
Second
-->
as the code did up until now. (The current handling was there to make
<!-- This is
a comment -->
format into
<!--
This is
a comment
-->
)
Unit tests.
Change-Id: Id98faadf3731b82880b37ff852c7c0787bb196f8
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.tests')
2 files changed, 67 insertions, 1 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinterTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinterTest.java index 0d6c19d..7436b2f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinterTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/formatting/XmlPrettyPrinterTest.java @@ -446,7 +446,7 @@ public class XmlPrettyPrinterTest extends TestCase { "\n" + " <!--\n" + " Deprecated strings - Move the identifiers to this section, mark as DO NOT TRANSLATE,\n" + - " and remove the actual text. These will be removed in a bulk operation\n" + + " and remove the actual text. These will be removed in a bulk operation.\n" + " -->\n" + " <!-- Do Not Translate. Unused string. -->\n" + " <string name=\"meeting_invitation\"></string>\n" + @@ -490,4 +490,47 @@ public class XmlPrettyPrinterTest extends TestCase { "</resources>"); } + public void testCommentHandling() throws Exception { + checkFormat( + XmlFormatPreferences.create(), XmlFormatStyle.LAYOUT, + "<foo >\n" + + "\n" + + " <!-- abc\n" + + " def\n" + + " ghi -->\n" + + "\n" + + " <!-- abc\n" + + " def\n" + + " ghi -->\n" + + " \n" + + "<!-- abc\n" + + "def\n" + + "ghi -->\n" + + "\n" + + "</foo>", + + "<foo >\n" + + "\n" + + " <!--\n" + + " abc\n" + + " def\n" + + " ghi\n" + + " -->\n" + + "\n" + + "\n" + + " <!--\n" + + " abc\n" + + " def\n" + + " ghi\n" + + " -->\n" + + "\n" + + "\n" + + " <!--\n" + + "abc\n" + + "def\n" + + "ghi\n" + + " -->\n" + + "\n" + + "</foo>"); + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java index 1d203b0..65b374b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/AdtUtilsTest.java @@ -31,6 +31,29 @@ public class AdtUtilsTest extends TestCase { assertFalse(AdtUtils.endsWithIgnoreCase("foo", "fo")); } + public void testEndsWith() { + assertTrue(AdtUtils.endsWith("foo", "foo")); + assertTrue(AdtUtils.endsWith("foobar", "obar")); + assertTrue(AdtUtils.endsWith("foobar", "bar")); + assertTrue(AdtUtils.endsWith("foobar", "ar")); + assertTrue(AdtUtils.endsWith("foobar", "r")); + assertTrue(AdtUtils.endsWith("foobar", "")); + + assertTrue(AdtUtils.endsWith(new StringBuilder("foobar"), "bar")); + assertTrue(AdtUtils.endsWith(new StringBuilder("foobar"), new StringBuffer("obar"))); + assertTrue(AdtUtils.endsWith("foobar", new StringBuffer("obar"))); + + assertFalse(AdtUtils.endsWith("foo", "fo")); + assertFalse(AdtUtils.endsWith("foobar", "Bar")); + assertFalse(AdtUtils.endsWith("foobar", "longfoobar")); + } + + public void testEndsWith2() { + assertTrue(AdtUtils.endsWith("foo", "foo".length(), "foo")); + assertTrue(AdtUtils.endsWith("foo", "fo".length(), "fo")); + assertTrue(AdtUtils.endsWith("foo", "f".length(), "f")); + } + public void testStripWhitespace() { assertEquals("foo", AdtUtils.stripWhitespace("foo")); assertEquals("foobar", AdtUtils.stripWhitespace("foo bar")); |