From 2eed52ecc0c2fa3e96530e4b5556eaa82f7c2dfc Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Wed, 21 Feb 2018 15:55:58 -0800 Subject: 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 --- tools/aapt2/ResourceUtils_test.cpp | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tools/aapt2/ResourceUtils_test.cpp') 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 -- cgit v1.2.3