mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Documentation comment says that it should return a 0-based offset, but it actually returns a 1-based offest. Code completion tests did not catch this bug because the only consequence is that the code completion token is shifted one character to the right, and in all code completion tests we had a space after the code completion token. Swift SVN r6566
66 lines
1.8 KiB
C++
66 lines
1.8 KiB
C++
#include "swift/IDE/CodeCompletion.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace swift;
|
|
using namespace code_completion;
|
|
|
|
TEST(CodeCompletionToken, FindInEmptyFile) {
|
|
std::string Source = "";
|
|
unsigned Offset;
|
|
std::string Clean = removeCodeCompletionTokens(Source, "A", &Offset);
|
|
EXPECT_EQ(~0U, Offset);
|
|
EXPECT_EQ("", Clean);
|
|
}
|
|
|
|
TEST(CodeCompletionToken, FindNonExistent) {
|
|
std::string Source = "func zzz() {}";
|
|
unsigned Offset;
|
|
std::string Clean = removeCodeCompletionTokens(Source, "A", &Offset);
|
|
EXPECT_EQ(~0U, Offset);
|
|
EXPECT_EQ(Source, Clean);
|
|
}
|
|
|
|
TEST(CodeCompletionToken, RemovesOtherTokens) {
|
|
std::string Source = "func zzz() {#^B^#}";
|
|
unsigned Offset;
|
|
std::string Clean = removeCodeCompletionTokens(Source, "A", &Offset);
|
|
EXPECT_EQ(~0U, Offset);
|
|
EXPECT_EQ("func zzz() {}", Clean);
|
|
}
|
|
|
|
TEST(CodeCompletionToken, FindBegin) {
|
|
std::string Source = "#^A^# func";
|
|
unsigned Offset;
|
|
std::string Clean = removeCodeCompletionTokens(Source, "A", &Offset);
|
|
EXPECT_EQ(0U, Offset);
|
|
EXPECT_EQ(" func", Clean);
|
|
}
|
|
|
|
TEST(CodeCompletionToken, FindEnd) {
|
|
std::string Source = "func #^A^#";
|
|
unsigned Offset;
|
|
std::string Clean = removeCodeCompletionTokens(Source, "A", &Offset);
|
|
EXPECT_EQ(5U, Offset);
|
|
EXPECT_EQ("func ", Clean);
|
|
}
|
|
|
|
TEST(CodeCompletionToken, FindSingleLine) {
|
|
std::string Source = "func zzz() {#^A^#}";
|
|
unsigned Offset;
|
|
std::string Clean = removeCodeCompletionTokens(Source, "A", &Offset);
|
|
EXPECT_EQ(12U, Offset);
|
|
EXPECT_EQ("func zzz() {}", Clean);
|
|
}
|
|
|
|
TEST(CodeCompletionToken, FindMultiline) {
|
|
std::string Source =
|
|
"func zzz() {\n"
|
|
" 1 + #^A^#\r\n"
|
|
"}\n";
|
|
unsigned Offset;
|
|
std::string Clean = removeCodeCompletionTokens(Source, "A", &Offset);
|
|
EXPECT_EQ(19U, Offset);
|
|
EXPECT_EQ("func zzz() {\n 1 + \r\n}\n", Clean);
|
|
}
|
|
|