From e967d3f6ac2e1e1f612f99b9c76abcb9e13bb7a2 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Mon, 24 Jul 2017 18:19:36 -0700 Subject: AAPT2: Fix JavaDoc first sentence extraction. The old algorithm for detecting the first sentence of a JavaDoc comment looked for the first occurence of '.'. This does not work when code or a {@link android.R.styleable} link is encountered in the first sentence. Switch to checking for whitespace characters after the '.' character. Bug: 62900335 Test: make aapt2_tests Change-Id: I8238f6a6304c9c2f92e2e576ca8962a59c2b20ea --- tools/aapt2/java/AnnotationProcessor_test.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'tools/aapt2/java/AnnotationProcessor_test.cpp') diff --git a/tools/aapt2/java/AnnotationProcessor_test.cpp b/tools/aapt2/java/AnnotationProcessor_test.cpp index 3e43c4295c07..9ccac8888426 100644 --- a/tools/aapt2/java/AnnotationProcessor_test.cpp +++ b/tools/aapt2/java/AnnotationProcessor_test.cpp @@ -18,6 +18,10 @@ #include "test/Test.h" +using ::testing::Eq; +using ::testing::HasSubstr; +using ::testing::Not; + namespace aapt { TEST(AnnotationProcessorTest, EmitsDeprecated) { @@ -33,7 +37,7 @@ TEST(AnnotationProcessorTest, EmitsDeprecated) { processor.WriteToStream(&result, ""); std::string annotations = result.str(); - EXPECT_NE(std::string::npos, annotations.find("@Deprecated")); + EXPECT_THAT(annotations, HasSubstr("@Deprecated")); } TEST(AnnotationProcessorTest, EmitsSystemApiAnnotationAndRemovesFromComment) { @@ -44,10 +48,20 @@ TEST(AnnotationProcessorTest, EmitsSystemApiAnnotationAndRemovesFromComment) { processor.WriteToStream(&result, ""); std::string annotations = result.str(); - EXPECT_NE(std::string::npos, - annotations.find("@android.annotation.SystemApi")); - EXPECT_EQ(std::string::npos, annotations.find("@SystemApi")); - EXPECT_NE(std::string::npos, annotations.find("This is a system API")); + EXPECT_THAT(annotations, HasSubstr("@android.annotation.SystemApi")); + EXPECT_THAT(annotations, Not(HasSubstr("@SystemApi"))); + EXPECT_THAT(annotations, HasSubstr("This is a system API")); +} + +TEST(AnnotationProcessor, ExtractsFirstSentence) { + EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence("This is the only sentence"), + Eq("This is the only sentence")); + EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence( + "This is the\n first sentence. This is the rest of the paragraph."), + Eq("This is the\n first sentence.")); + EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence( + "This is the first sentence with a {@link android.R.styleable.Theme}."), + Eq("This is the first sentence with a {@link android.R.styleable.Theme}.")); } } // namespace aapt -- cgit v1.2.3