diff options
author | Adam Lesinski <adamlesinski@google.com> | 2018-02-21 15:55:58 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2018-02-27 11:39:10 -0800 |
commit | 2eed52ecc0c2fa3e96530e4b5556eaa82f7c2dfc (patch) | |
tree | 4e0a49770f684a2ca823d958c0f1a2b3adabcab9 /tools/aapt2/ResourceUtils_test.cpp | |
parent | e1094a2e232277a719025aa5c97c492502c34f5b (diff) |
AAPT2: Fix styled string whitespace processing
Change styled string whitespace processing to be like AAPT's was.
Main changes:
- whitespace around tags is preserved.
- tags start exactly where they are supposed to, not off by one.
Bug: 72406283
Test: make aapt2_tests
Change-Id: I4d12728c493efd8c978e2e3d2718b56534ff52ef
Diffstat (limited to 'tools/aapt2/ResourceUtils_test.cpp')
-rw-r--r-- | tools/aapt2/ResourceUtils_test.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/aapt2/ResourceUtils_test.cpp b/tools/aapt2/ResourceUtils_test.cpp index cb786d3794c2..11f3fa3bc6cd 100644 --- a/tools/aapt2/ResourceUtils_test.cpp +++ b/tools/aapt2/ResourceUtils_test.cpp @@ -212,4 +212,48 @@ TEST(ResourceUtilsTest, ItemsWithWhitespaceAreParsedCorrectly) { Pointee(ValueEq(BinaryPrimitive(Res_value::TYPE_FLOAT, expected_float_flattened)))); } +TEST(ResourceUtilsTest, StringBuilderWhitespaceRemoval) { + EXPECT_THAT(ResourceUtils::StringBuilder() + .AppendText(" hey guys ") + .AppendText(" this is so cool ") + .to_string(), + Eq(" hey guys this is so cool ")); + EXPECT_THAT(ResourceUtils::StringBuilder() + .AppendText(" \" wow, so many \t ") + .AppendText("spaces. \"what? ") + .to_string(), + Eq(" wow, so many \t spaces. what? ")); + EXPECT_THAT(ResourceUtils::StringBuilder() + .AppendText(" where \t ") + .AppendText(" \nis the pie?") + .to_string(), + Eq(" where is the pie?")); +} + +TEST(ResourceUtilsTest, StringBuilderEscaping) { + EXPECT_THAT(ResourceUtils::StringBuilder() + .AppendText("hey guys\\n ") + .AppendText(" this \\t is so\\\\ cool") + .to_string(), + Eq("hey guys\n this \t is so\\ cool")); + EXPECT_THAT(ResourceUtils::StringBuilder().AppendText("\\@\\?\\#\\\\\\'").to_string(), + Eq("@?#\\\'")); +} + +TEST(ResourceUtilsTest, StringBuilderMisplacedQuote) { + ResourceUtils::StringBuilder builder; + EXPECT_FALSE(builder.AppendText("they're coming!")); +} + +TEST(ResourceUtilsTest, StringBuilderUnicodeCodes) { + EXPECT_THAT(ResourceUtils::StringBuilder().AppendText("\\u00AF\\u0AF0 woah").to_string(), + Eq("\u00AF\u0AF0 woah")); + EXPECT_FALSE(ResourceUtils::StringBuilder().AppendText("\\u00 yo")); +} + +TEST(ResourceUtilsTest, StringBuilderPreserveSpaces) { + EXPECT_THAT(ResourceUtils::StringBuilder(true /*preserve_spaces*/).AppendText("\"").to_string(), + Eq("\"")); +} + } // namespace aapt |