Files
frameworks_base/tools/aapt2/java/AnnotationProcessor_test.cpp
Adam Lesinski 18dc03a9fd Cherry-pick from master: 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 , make ds-docs
Original change-Id: I8238f6a6304c9c2f92e2e576ca8962a59c2b20ea

Change-Id: Ie272d0d793d157f2a30f3ead20b2b53976661d33
2017-07-27 17:22:09 -07:00

68 lines
2.3 KiB
C++

/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "java/AnnotationProcessor.h"
#include "test/Test.h"
using ::testing::Eq;
using ::testing::HasSubstr;
using ::testing::Not;
namespace aapt {
TEST(AnnotationProcessorTest, EmitsDeprecated) {
const char* comment =
"Some comment, and it should contain a marker word, "
"something that marks this resource as nor needed. "
"{@deprecated That's the marker! }";
AnnotationProcessor processor;
processor.AppendComment(comment);
std::stringstream result;
processor.WriteToStream(&result, "");
std::string annotations = result.str();
EXPECT_THAT(annotations, HasSubstr("@Deprecated"));
}
TEST(AnnotationProcessorTest, EmitsSystemApiAnnotationAndRemovesFromComment) {
AnnotationProcessor processor;
processor.AppendComment("@SystemApi This is a system API");
std::stringstream result;
processor.WriteToStream(&result, "");
std::string annotations = result.str();
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