blob: 7aafd025325cb23e77d83b9de7f16e5fd431512b [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át5b8e2822022-01-14 03:19:54 +010022
Jan Kundrát4a65b012020-05-29 14:03:38 +020023 SECTION("no prefix")
Václav Kubernát57272422019-02-08 12:48:24 +010024 {
Petr Gotthard1c76dea2022-04-13 17:56:58 +020025 expectedCompletions = {"cd", "copy", "create", "delete", "set", "commit", "get", "ls", "discard", "help", "describe", "move", "dump", "prepare", "exec", "cancel", "switch", "quit"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010026 expectedContextLength = 0;
Václav Kubernátb4e5b182020-11-16 19:55:09 +010027 SECTION("no space")
28 {
Jan Kundrát4a65b012020-05-29 14:03:38 +020029 input = "";
30 }
Václav Kubernátb4e5b182020-11-16 19:55:09 +010031 SECTION("space")
32 {
Jan Kundrát4a65b012020-05-29 14:03:38 +020033 input = " ";
34 }
Václav Kubernát57272422019-02-08 12:48:24 +010035 }
36
37 SECTION("c")
38 {
39 input = "c";
Václav Kubernáte7248b22020-06-26 15:38:59 +020040 expectedCompletions = {"cd", "commit", "copy", "create", "cancel"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010041 expectedContextLength = 1;
Václav Kubernát57272422019-02-08 12:48:24 +010042 }
43
44 SECTION("d")
45 {
46 input = "d";
Václav Kubernát70d7f7a2020-06-23 14:40:40 +020047 expectedCompletions = {"delete", "discard", "describe", "dump"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010048 expectedContextLength = 1;
Václav Kubernát57272422019-02-08 12:48:24 +010049 }
50
51 SECTION("x")
52 {
53 input = "x";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010054 expectedCompletions = {};
55 expectedContextLength = 1;
Václav Kubernát57272422019-02-08 12:48:24 +010056 }
57
58 SECTION("cd")
59 {
60 input = "cd";
Václav Kubernát0165e6c2020-02-17 18:18:14 +010061 expectedCompletions = {"cd "};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010062 expectedContextLength = 2;
Václav Kubernát57272422019-02-08 12:48:24 +010063 }
64
65 SECTION("create")
66 {
67 input = "create";
Václav Kubernát0165e6c2020-02-17 18:18:14 +010068 expectedCompletions = {"create "};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010069 expectedContextLength = 6;
Václav Kubernát57272422019-02-08 12:48:24 +010070 }
71
Václav Kubernát7160a132020-04-03 02:11:01 +020072 SECTION("copy datastores")
73 {
74 input = "copy ";
75 expectedCompletions = {"running", "startup"};
76 expectedContextLength = 0;
77 }
78
Václav Kubernát162165e2021-02-22 09:46:53 +010079 SECTION("switch datastore targets")
80 {
81 input = "switch ";
82 expectedCompletions = {"running", "startup", "operational"};
83 expectedContextLength = 0;
84 }
85
Václav Kubernát3b5e6522020-06-26 18:36:09 +020086 SECTION("dump")
87 {
88 input = "dump ";
89 expectedCompletions = {"xml", "json"};
90 expectedContextLength = 0;
91 }
92
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010093 REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
Václav Kubernát57272422019-02-08 12:48:24 +010094}