blob: 8e8570f1103db944cd123660ab6db3d486af0769 [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;
Jan Kundrát4a65b012020-05-29 14:03:38 +020022 SECTION("no prefix")
Václav Kubernát57272422019-02-08 12:48:24 +010023 {
Václav Kubernát162165e2021-02-22 09:46:53 +010024 expectedCompletions = {"cd", "copy", "create", "delete", "set", "commit", "get", "ls", "discard", "help", "describe", "move", "dump", "prepare", "exec", "cancel", "switch"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010025 expectedContextLength = 0;
Václav Kubernátb4e5b182020-11-16 19:55:09 +010026 SECTION("no space")
27 {
Jan Kundrát4a65b012020-05-29 14:03:38 +020028 input = "";
29 }
Václav Kubernátb4e5b182020-11-16 19:55:09 +010030 SECTION("space")
31 {
Jan Kundrát4a65b012020-05-29 14:03:38 +020032 input = " ";
33 }
Václav Kubernát57272422019-02-08 12:48:24 +010034 }
35
36 SECTION("c")
37 {
38 input = "c";
Václav Kubernáte7248b22020-06-26 15:38:59 +020039 expectedCompletions = {"cd", "commit", "copy", "create", "cancel"};
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át70d7f7a2020-06-23 14:40:40 +020046 expectedCompletions = {"delete", "discard", "describe", "dump"};
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át162165e2021-02-22 09:46:53 +010078 SECTION("switch datastore targets")
79 {
80 input = "switch ";
81 expectedCompletions = {"running", "startup", "operational"};
82 expectedContextLength = 0;
83 }
84
Václav Kubernát3b5e6522020-06-26 18:36:09 +020085 SECTION("dump")
86 {
87 input = "dump ";
88 expectedCompletions = {"xml", "json"};
89 expectedContextLength = 0;
90 }
91
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010092 REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
Václav Kubernát57272422019-02-08 12:48:24 +010093}