1
//===-- LineEditor.cpp ----------------------------------------------------===//
3
// The LLVM Compiler Infrastructure
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
8
//===----------------------------------------------------------------------===//
10
#include "llvm/LineEditor/LineEditor.h"
11
#include "llvm/Support/FileSystem.h"
12
#include "llvm/Support/Path.h"
13
#include "gtest/gtest.h"
17
class LineEditorTest : public testing::Test {
19
SmallString<64> HistPath;
27
sys::fs::createTemporaryFile("temp", "history", HistPath);
28
ASSERT_FALSE(HistPath.empty());
29
LE = new LineEditor("test", HistPath);
32
~LineEditorTest() override {
34
sys::fs::remove(HistPath.str());
38
TEST_F(LineEditorTest, HistorySaveLoad) {
43
struct TestListCompleter {
44
std::vector<LineEditor::Completion> Completions;
46
TestListCompleter(const std::vector<LineEditor::Completion> &Completions)
47
: Completions(Completions) {}
49
std::vector<LineEditor::Completion> operator()(StringRef Buffer,
51
EXPECT_TRUE(Buffer.empty());
57
TEST_F(LineEditorTest, ListCompleters) {
58
std::vector<LineEditor::Completion> Comps;
60
Comps.push_back(LineEditor::Completion("foo", "int foo()"));
61
LE->setListCompleter(TestListCompleter(Comps));
62
LineEditor::CompletionAction CA = LE->getCompletionAction("", 0);
63
EXPECT_EQ(LineEditor::CompletionAction::AK_Insert, CA.Kind);
64
EXPECT_EQ("foo", CA.Text);
66
Comps.push_back(LineEditor::Completion("bar", "int bar()"));
67
LE->setListCompleter(TestListCompleter(Comps));
68
CA = LE->getCompletionAction("", 0);
69
EXPECT_EQ(LineEditor::CompletionAction::AK_ShowCompletions, CA.Kind);
70
ASSERT_EQ(2u, CA.Completions.size());
71
ASSERT_EQ("int foo()", CA.Completions[0]);
72
ASSERT_EQ("int bar()", CA.Completions[1]);
75
Comps.push_back(LineEditor::Completion("fee", "int fee()"));
76
Comps.push_back(LineEditor::Completion("fi", "int fi()"));
77
Comps.push_back(LineEditor::Completion("foe", "int foe()"));
78
Comps.push_back(LineEditor::Completion("fum", "int fum()"));
79
LE->setListCompleter(TestListCompleter(Comps));
80
CA = LE->getCompletionAction("", 0);
81
EXPECT_EQ(LineEditor::CompletionAction::AK_Insert, CA.Kind);
82
EXPECT_EQ("f", CA.Text);