blob: 607b8ab4b4f50a3b82f2e9c4e735a073eefe36f7 [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
Václav Kubernát26b56082020-02-03 18:28:56 +01009#include "trompeloeil_doctest.hpp"
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át7160a132020-04-03 02:11:01 +020025 expectedCompletions = {"cd", "copy", "create", "delete", "set", "commit", "get", "ls", "discard", "help", "describe"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010026 expectedContextLength = 0;
Václav Kubernát57272422019-02-08 12:48:24 +010027 }
28
29 SECTION(" ")
30 {
31 input = " ";
Václav Kubernát7160a132020-04-03 02:11:01 +020032 expectedCompletions = {"cd", "copy", "create", "delete", "set", "commit", "get", "ls", "discard", "help", "describe"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010033 expectedContextLength = 0;
Václav Kubernát57272422019-02-08 12:48:24 +010034 }
35
36 SECTION("c")
37 {
38 input = "c";
Václav Kubernát7160a132020-04-03 02:11:01 +020039 expectedCompletions = {"cd", "commit", "copy", "create"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010040 expectedContextLength = 1;
Václav Kubernát57272422019-02-08 12:48:24 +010041 }
42
43 SECTION("d")
44 {
45 input = "d";
Václav Kubernát9cfcd872020-02-18 12:34:02 +010046 expectedCompletions = {"delete", "discard", "describe"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010047 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";
Václav Kubernát0165e6c2020-02-17 18:18:14 +010060 expectedCompletions = {"cd "};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010061 expectedContextLength = 2;
Václav Kubernát57272422019-02-08 12:48:24 +010062 }
63
64 SECTION("create")
65 {
66 input = "create";
Václav Kubernát0165e6c2020-02-17 18:18:14 +010067 expectedCompletions = {"create "};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010068 expectedContextLength = 6;
Václav Kubernát57272422019-02-08 12:48:24 +010069 }
70
Václav Kubernát7160a132020-04-03 02:11:01 +020071 SECTION("copy datastores")
72 {
73 input = "copy ";
74 expectedCompletions = {"running", "startup"};
75 expectedContextLength = 0;
76 }
77
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010078 REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
Václav Kubernát57272422019-02-08 12:48:24 +010079}