1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include "swift/IDE/CodeCompletion.h"
#include "gtest/gtest.h"
using namespace swift;
using namespace ide;
static std::string replaceAtWithNull(const std::string &S) {
std::string Result = S;
for (char &C : Result) {
if (C == '@')
C = '\0';
}
return Result;
}
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(replaceAtWithNull("@ 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(replaceAtWithNull("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(replaceAtWithNull("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(replaceAtWithNull("func zzz() {\n 1 + @\r\n}\n"), Clean);
}
|