summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceParser_test.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2017-03-31 18:28:14 -0700
committerAdam Lesinski <adamlesinski@google.com>2017-03-31 18:30:20 -0700
commit8049f3da712ea9c3154b57ce2276c97e749d1f2c (patch)
treecd4b22971ad876eb8421a7a5870da9e49d62c9f1 /tools/aapt2/ResourceParser_test.cpp
parent881a623e3522e3e4f0905b606ca5c77cf899b21c (diff)
AAPT2: Fix pseudolocalization (again)
Pseudolocalization didn't properly handle spans in strings like "<small><small>Hello</small></small>". The spans would be identical and when doing range checks only one of them would be updated. Switched to a more robust way of extracting the relevant chunks of a styled string. This uses a stack, which is more in line with the real representation in XML. Bug: 34088357 Test: make aapt2_tests Change-Id: Ia4e4501713e688c96a89e26e4e2b1384f4cd3889
Diffstat (limited to 'tools/aapt2/ResourceParser_test.cpp')
-rw-r--r--tools/aapt2/ResourceParser_test.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp
index eefa320a4418..8062c2e6afea 100644
--- a/tools/aapt2/ResourceParser_test.cpp
+++ b/tools/aapt2/ResourceParser_test.cpp
@@ -101,20 +101,24 @@ TEST_F(ResourceParserTest, ParseStyledString) {
// Use a surrogate pair unicode point so that we can verify that the span
// indices use UTF-16 length and not UTF-8 length.
std::string input =
- "<string name=\"foo\">This is my aunt\u2019s <b>string</b></string>";
+ "<string name=\"foo\">This is my aunt\u2019s <b>fickle <small>string</small></b></string>";
ASSERT_TRUE(TestParse(input));
StyledString* str = test::GetValue<StyledString>(&table_, "string/foo");
ASSERT_NE(nullptr, str);
- const std::string expected_str = "This is my aunt\u2019s string";
+ const std::string expected_str = "This is my aunt\u2019s fickle string";
EXPECT_EQ(expected_str, *str->value->str);
- EXPECT_EQ(1u, str->value->spans.size());
+ EXPECT_EQ(2u, str->value->spans.size());
EXPECT_TRUE(str->untranslatable_sections.empty());
EXPECT_EQ(std::string("b"), *str->value->spans[0].name);
EXPECT_EQ(17u, str->value->spans[0].first_char);
- EXPECT_EQ(23u, str->value->spans[0].last_char);
+ EXPECT_EQ(30u, str->value->spans[0].last_char);
+
+ EXPECT_EQ(std::string("small"), *str->value->spans[1].name);
+ EXPECT_EQ(24u, str->value->spans[1].first_char);
+ EXPECT_EQ(30u, str->value->spans[1].last_char);
}
TEST_F(ResourceParserTest, ParseStringWithWhitespace) {