blob: d43939414c04847256affd1f565c0d9798b8456d [file] [log] [blame]
Václav Kubernát57272422019-02-08 12:48:24 +01001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
3 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
4 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
8
Jan Kundráta33cf082019-03-28 11:55:57 +01009#include "trompeloeil_doctest.h"
Václav Kubernát57272422019-02-08 12:48:24 +010010#include "parser.hpp"
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010011#include "pretty_printers.hpp"
Václav Kubernát57272422019-02-08 12:48:24 +010012#include "static_schema.hpp"
13
14TEST_CASE("command completion")
15{
16 auto schema = std::make_shared<StaticSchema>();
17 Parser parser(schema);
18 std::string input;
19 std::ostringstream errorStream;
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010020 std::set<std::string> expectedCompletions;
21 int expectedContextLength;
Václav Kubernát57272422019-02-08 12:48:24 +010022 SECTION("")
23 {
24 input = "";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010025 expectedCompletions = {"cd", "create", "delete", "set", "commit", "get", "ls", "discard", "help"};
26 expectedContextLength = 0;
Václav Kubernát57272422019-02-08 12:48:24 +010027 }
28
29 SECTION(" ")
30 {
31 input = " ";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010032 expectedCompletions = {"cd", "create", "delete", "set", "commit", "get", "ls", "discard", "help"};
33 expectedContextLength = 0;
Václav Kubernát57272422019-02-08 12:48:24 +010034 }
35
36 SECTION("c")
37 {
38 input = "c";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010039 expectedCompletions = {"cd", "commit", "create"};
40 expectedContextLength = 1;
Václav Kubernát57272422019-02-08 12:48:24 +010041 }
42
43 SECTION("d")
44 {
45 input = "d";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010046 expectedCompletions = {"delete", "discard"};
47 expectedContextLength = 1;
Václav Kubernát57272422019-02-08 12:48:24 +010048 }
49
50 SECTION("x")
51 {
52 input = "x";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010053 expectedCompletions = {};
54 expectedContextLength = 1;
Václav Kubernát57272422019-02-08 12:48:24 +010055 }
56
57 SECTION("cd")
58 {
59 input = "cd";
60 // TODO: depending on how Readline works, this will have to be changed to include a space
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010061 expectedCompletions = {"cd"};
62 expectedContextLength = 2;
Václav Kubernát57272422019-02-08 12:48:24 +010063 }
64
65 SECTION("create")
66 {
67 input = "create";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010068 expectedCompletions = {"create"};
69 expectedContextLength = 6;
Václav Kubernát57272422019-02-08 12:48:24 +010070 }
71
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010072 REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
Václav Kubernát57272422019-02-08 12:48:24 +010073}