Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 1 | /* |
| 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át | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame^] | 9 | #include "trompeloeil_doctest.h" |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 10 | #include "parser.hpp" |
| 11 | #include "static_schema.hpp" |
| 12 | |
| 13 | TEST_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át | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 23 | expected = {"cd", "create", "delete", "set", "commit", "get", "ls", "discard", "help"}; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | SECTION(" ") |
| 27 | { |
| 28 | input = " "; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 29 | expected = {"cd", "create", "delete", "set", "commit", "get", "ls", "discard", "help"}; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | SECTION("c") |
| 33 | { |
| 34 | input = "c"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 35 | expected = {"cd", "commit", "create"}; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | SECTION("d") |
| 39 | { |
| 40 | input = "d"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 41 | expected = {"delete", "discard"}; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 42 | } |
| 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át | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 54 | expected = {"cd"}; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | SECTION("create") |
| 58 | { |
| 59 | input = "create"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 60 | expected = {"create"}; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | REQUIRE(parser.completeCommand(input, errorStream) == expected); |
| 64 | } |