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 | 5b8e282 | 2022-01-14 03:19:54 +0100 | [diff] [blame] | 22 | |
Jan Kundrát | 4a65b01 | 2020-05-29 14:03:38 +0200 | [diff] [blame] | 23 | SECTION("no prefix") |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 24 | { |
Petr Gotthard | 1c76dea | 2022-04-13 17:56:58 +0200 | [diff] [blame] | 25 | expectedCompletions = {"cd", "copy", "create", "delete", "set", "commit", "get", "ls", "discard", "help", "describe", "move", "dump", "prepare", "exec", "cancel", "switch", "quit"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 26 | expectedContextLength = 0; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 27 | SECTION("no space") |
| 28 | { |
Jan Kundrát | 4a65b01 | 2020-05-29 14:03:38 +0200 | [diff] [blame] | 29 | input = ""; |
| 30 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 31 | SECTION("space") |
| 32 | { |
Jan Kundrát | 4a65b01 | 2020-05-29 14:03:38 +0200 | [diff] [blame] | 33 | input = " "; |
| 34 | } |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | SECTION("c") |
| 38 | { |
| 39 | input = "c"; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 40 | expectedCompletions = {"cd", "commit", "copy", "create", "cancel"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 41 | expectedContextLength = 1; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | SECTION("d") |
| 45 | { |
| 46 | input = "d"; |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 47 | expectedCompletions = {"delete", "discard", "describe", "dump"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 48 | expectedContextLength = 1; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | SECTION("x") |
| 52 | { |
| 53 | input = "x"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 54 | expectedCompletions = {}; |
| 55 | expectedContextLength = 1; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | SECTION("cd") |
| 59 | { |
| 60 | input = "cd"; |
Václav Kubernát | 0165e6c | 2020-02-17 18:18:14 +0100 | [diff] [blame] | 61 | expectedCompletions = {"cd "}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 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 | 0165e6c | 2020-02-17 18:18:14 +0100 | [diff] [blame] | 68 | expectedCompletions = {"create "}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 69 | expectedContextLength = 6; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 72 | SECTION("copy datastores") |
| 73 | { |
| 74 | input = "copy "; |
| 75 | expectedCompletions = {"running", "startup"}; |
| 76 | expectedContextLength = 0; |
| 77 | } |
| 78 | |
Václav Kubernát | 162165e | 2021-02-22 09:46:53 +0100 | [diff] [blame] | 79 | SECTION("switch datastore targets") |
| 80 | { |
| 81 | input = "switch "; |
| 82 | expectedCompletions = {"running", "startup", "operational"}; |
| 83 | expectedContextLength = 0; |
| 84 | } |
| 85 | |
Václav Kubernát | 3b5e652 | 2020-06-26 18:36:09 +0200 | [diff] [blame] | 86 | SECTION("dump") |
| 87 | { |
| 88 | input = "dump "; |
| 89 | expectedCompletions = {"xml", "json"}; |
| 90 | expectedContextLength = 0; |
| 91 | } |
| 92 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 93 | REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength})); |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 94 | } |