blob: 45eb9981859f2463a94ab5ac13c7b0b3e45277ad [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átbf65dd72020-05-28 02:32:31 +020024 expectedCompletions = {"cd", "copy", "create", "delete", "set", "commit", "get", "ls", "discard", "help", "describe", "move"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010025 expectedContextLength = 0;
Jan Kundrát4a65b012020-05-29 14:03:38 +020026 SECTION("no space") {
27 input = "";
28 }
29 SECTION("space") {
30 input = " ";
31 }
Václav Kubernát57272422019-02-08 12:48:24 +010032 }
33
34 SECTION("c")
35 {
36 input = "c";
Václav Kubernát7160a132020-04-03 02:11:01 +020037 expectedCompletions = {"cd", "commit", "copy", "create"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010038 expectedContextLength = 1;
Václav Kubernát57272422019-02-08 12:48:24 +010039 }
40
41 SECTION("d")
42 {
43 input = "d";
Václav Kubernát9cfcd872020-02-18 12:34:02 +010044 expectedCompletions = {"delete", "discard", "describe"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010045 expectedContextLength = 1;
Václav Kubernát57272422019-02-08 12:48:24 +010046 }
47
48 SECTION("x")
49 {
50 input = "x";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010051 expectedCompletions = {};
52 expectedContextLength = 1;
Václav Kubernát57272422019-02-08 12:48:24 +010053 }
54
55 SECTION("cd")
56 {
57 input = "cd";
Václav Kubernát0165e6c2020-02-17 18:18:14 +010058 expectedCompletions = {"cd "};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010059 expectedContextLength = 2;
Václav Kubernát57272422019-02-08 12:48:24 +010060 }
61
62 SECTION("create")
63 {
64 input = "create";
Václav Kubernát0165e6c2020-02-17 18:18:14 +010065 expectedCompletions = {"create "};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010066 expectedContextLength = 6;
Václav Kubernát57272422019-02-08 12:48:24 +010067 }
68
Václav Kubernát7160a132020-04-03 02:11:01 +020069 SECTION("copy datastores")
70 {
71 input = "copy ";
72 expectedCompletions = {"running", "startup"};
73 expectedContextLength = 0;
74 }
75
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010076 REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
Václav Kubernát57272422019-02-08 12:48:24 +010077}