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" |
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"; |
| 60 | // TODO: depending on how Readline works, this will have to be changed to include a space |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame^] | 61 | expectedCompletions = {"cd"}; |
| 62 | expectedContextLength = 2; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | SECTION("create") |
| 66 | { |
| 67 | input = "create"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame^] | 68 | expectedCompletions = {"create"}; |
| 69 | expectedContextLength = 6; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame^] | 72 | REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength})); |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 73 | } |