blob: eb4949a74a23bcfaef139dfdfbce93e4644622be [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át9cfcd872020-02-18 12:34:02 +010025 expectedCompletions = {"cd", "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át9cfcd872020-02-18 12:34:02 +010032 expectedCompletions = {"cd", "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á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á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át1ed4aa32020-01-23 13:13:28 +010071 REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
Václav Kubernát57272422019-02-08 12:48:24 +010072}