Fix uninitialized variable
[llvm-core.git] / unittests / LineEditor / LineEditor.cpp
blob4d9081fd5c201ee02ccefa53f16191b12ad7b407
1 //===-- LineEditor.cpp ----------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/LineEditor/LineEditor.h"
11 #include "llvm/Support/FileSystem.h"
12 #include "llvm/Support/Path.h"
13 #include "gtest/gtest.h"
15 using namespace llvm;
17 class LineEditorTest : public testing::Test {
18 public:
19 SmallString<64> HistPath;
20 LineEditor *LE;
22 LineEditorTest() {
23 init();
26 void init() {
27 sys::fs::createTemporaryFile("temp", "history", HistPath);
28 ASSERT_FALSE(HistPath.empty());
29 LE = new LineEditor("test", HistPath);
32 ~LineEditorTest() override {
33 delete LE;
34 sys::fs::remove(HistPath.str());
38 TEST_F(LineEditorTest, HistorySaveLoad) {
39 LE->saveHistory();
40 LE->loadHistory();
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,
50 size_t Pos) const {
51 EXPECT_TRUE(Buffer.empty());
52 EXPECT_EQ(0u, Pos);
53 return Completions;
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]);
74 Comps.clear();
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);