Files
TheRock/compiler/amd-llvm/llvm/unittests/LineEditor/LineEditor.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

83 lines
2.5 KiB
C++

//===-- LineEditor.cpp ----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/LineEditor/LineEditor.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "gtest/gtest.h"
using namespace llvm;
class LineEditorTest : public testing::Test {
public:
SmallString<64> HistPath;
LineEditor *LE;
LineEditorTest() {
init();
}
void init() {
sys::fs::createTemporaryFile("temp", "history", HistPath);
ASSERT_FALSE(HistPath.empty());
LE = new LineEditor("test", HistPath);
}
~LineEditorTest() override {
delete LE;
sys::fs::remove(HistPath.str());
}
};
TEST_F(LineEditorTest, HistorySaveLoad) {
LE->saveHistory();
LE->loadHistory();
}
struct TestListCompleter {
std::vector<LineEditor::Completion> Completions;
TestListCompleter(const std::vector<LineEditor::Completion> &Completions)
: Completions(Completions) {}
std::vector<LineEditor::Completion> operator()(StringRef Buffer,
size_t Pos) const {
EXPECT_TRUE(Buffer.empty());
EXPECT_EQ(0u, Pos);
return Completions;
}
};
TEST_F(LineEditorTest, ListCompleters) {
std::vector<LineEditor::Completion> Comps;
Comps.push_back(LineEditor::Completion("foo", "int foo()"));
LE->setListCompleter(TestListCompleter(Comps));
LineEditor::CompletionAction CA = LE->getCompletionAction("", 0);
EXPECT_EQ(LineEditor::CompletionAction::AK_Insert, CA.Kind);
EXPECT_EQ("foo", CA.Text);
Comps.push_back(LineEditor::Completion("bar", "int bar()"));
LE->setListCompleter(TestListCompleter(Comps));
CA = LE->getCompletionAction("", 0);
EXPECT_EQ(LineEditor::CompletionAction::AK_ShowCompletions, CA.Kind);
ASSERT_EQ(2u, CA.Completions.size());
ASSERT_EQ("int foo()", CA.Completions[0]);
ASSERT_EQ("int bar()", CA.Completions[1]);
Comps.clear();
Comps.push_back(LineEditor::Completion("fee", "int fee()"));
Comps.push_back(LineEditor::Completion("fi", "int fi()"));
Comps.push_back(LineEditor::Completion("foe", "int foe()"));
Comps.push_back(LineEditor::Completion("fum", "int fum()"));
LE->setListCompleter(TestListCompleter(Comps));
CA = LE->getCompletionAction("", 0);
EXPECT_EQ(LineEditor::CompletionAction::AK_Insert, CA.Kind);
EXPECT_EQ("f", CA.Text);
}