blob: 015b4dbe3e03944fb7754ce964dfc29d1bdf2658 [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
Jan Kundráta33cf082019-03-28 11:55:57 +01009#include "trompeloeil_doctest.h"
Václav Kubernát57272422019-02-08 12:48:24 +010010#include "parser.hpp"
11#include "static_schema.hpp"
12
13TEST_CASE("command completion")
14{
15 auto schema = std::make_shared<StaticSchema>();
16 Parser parser(schema);
17 std::string input;
18 std::ostringstream errorStream;
19 std::set<std::string> expected;
20 SECTION("")
21 {
22 input = "";
Václav Kubernát054cc992019-02-21 14:23:52 +010023 expected = {"cd", "create", "delete", "set", "commit", "get", "ls", "discard", "help"};
Václav Kubernát57272422019-02-08 12:48:24 +010024 }
25
26 SECTION(" ")
27 {
28 input = " ";
Václav Kubernát054cc992019-02-21 14:23:52 +010029 expected = {"cd", "create", "delete", "set", "commit", "get", "ls", "discard", "help"};
Václav Kubernát57272422019-02-08 12:48:24 +010030 }
31
32 SECTION("c")
33 {
34 input = "c";
Václav Kubernáta395d332019-02-13 16:49:20 +010035 expected = {"cd", "commit", "create"};
Václav Kubernát57272422019-02-08 12:48:24 +010036 }
37
38 SECTION("d")
39 {
40 input = "d";
Václav Kubernáta395d332019-02-13 16:49:20 +010041 expected = {"delete", "discard"};
Václav Kubernát57272422019-02-08 12:48:24 +010042 }
43
44 SECTION("x")
45 {
46 input = "x";
47 expected = {};
48 }
49
50 SECTION("cd")
51 {
52 input = "cd";
53 // TODO: depending on how Readline works, this will have to be changed to include a space
Václav Kubernáta395d332019-02-13 16:49:20 +010054 expected = {"cd"};
Václav Kubernát57272422019-02-08 12:48:24 +010055 }
56
57 SECTION("create")
58 {
59 input = "create";
Václav Kubernáta395d332019-02-13 16:49:20 +010060 expected = {"create"};
Václav Kubernát57272422019-02-08 12:48:24 +010061 }
62
63 REQUIRE(parser.completeCommand(input, errorStream) == expected);
64}