From 8049f3da712ea9c3154b57ce2276c97e749d1f2c Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Fri, 31 Mar 2017 18:28:14 -0700 Subject: AAPT2: Fix pseudolocalization (again) Pseudolocalization didn't properly handle spans in strings like "Hello". 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 --- tools/aapt2/ResourceParser_test.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'tools/aapt2/ResourceParser_test.cpp') 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 = - "This is my aunt\u2019s string"; + "This is my aunt\u2019s fickle string"; ASSERT_TRUE(TestParse(input)); StyledString* str = test::GetValue(&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) { -- cgit v1.2.3