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 | |
Václav Kubernát | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 9 | #include "trompeloeil_doctest.hpp" |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 10 | #include "parser.hpp" |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 11 | #include "pretty_printers.hpp" |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 12 | #include "static_schema.hpp" |
| 13 | |
| 14 | TEST_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át | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 20 | std::set<std::string> expectedCompletions; |
| 21 | int expectedContextLength; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 22 | SECTION("") |
| 23 | { |
| 24 | input = ""; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 25 | expectedCompletions = {"cd", "create", "delete", "set", "commit", "get", "ls", "discard", "help"}; |
| 26 | expectedContextLength = 0; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | SECTION(" ") |
| 30 | { |
| 31 | input = " "; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 32 | expectedCompletions = {"cd", "create", "delete", "set", "commit", "get", "ls", "discard", "help"}; |
| 33 | expectedContextLength = 0; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | SECTION("c") |
| 37 | { |
| 38 | input = "c"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 39 | expectedCompletions = {"cd", "commit", "create"}; |
| 40 | expectedContextLength = 1; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | SECTION("d") |
| 44 | { |
| 45 | input = "d"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 46 | expectedCompletions = {"delete", "discard"}; |
| 47 | expectedContextLength = 1; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | SECTION("x") |
| 51 | { |
| 52 | input = "x"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 53 | expectedCompletions = {}; |
| 54 | expectedContextLength = 1; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | SECTION("cd") |
| 58 | { |
| 59 | input = "cd"; |
Václav Kubernát | 0165e6c | 2020-02-17 18:18:14 +0100 | [diff] [blame^] | 60 | expectedCompletions = {"cd "}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 61 | expectedContextLength = 2; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | SECTION("create") |
| 65 | { |
| 66 | input = "create"; |
Václav Kubernát | 0165e6c | 2020-02-17 18:18:14 +0100 | [diff] [blame^] | 67 | expectedCompletions = {"create "}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 68 | expectedContextLength = 6; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 71 | REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength})); |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 72 | } |