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; |
Jan Kundrát | 4a65b01 | 2020-05-29 14:03:38 +0200 | [diff] [blame] | 22 | SECTION("no prefix") |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 23 | { |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 24 | expectedCompletions = {"cd", "copy", "create", "delete", "set", "commit", "get", "ls", "discard", "help", "describe", "move"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 25 | expectedContextLength = 0; |
Jan Kundrát | 4a65b01 | 2020-05-29 14:03:38 +0200 | [diff] [blame] | 26 | SECTION("no space") { |
| 27 | input = ""; |
| 28 | } |
| 29 | SECTION("space") { |
| 30 | input = " "; |
| 31 | } |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | SECTION("c") |
| 35 | { |
| 36 | input = "c"; |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 37 | expectedCompletions = {"cd", "commit", "copy", "create"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 38 | expectedContextLength = 1; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | SECTION("d") |
| 42 | { |
| 43 | input = "d"; |
Václav Kubernát | 9cfcd87 | 2020-02-18 12:34:02 +0100 | [diff] [blame] | 44 | expectedCompletions = {"delete", "discard", "describe"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 45 | expectedContextLength = 1; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | SECTION("x") |
| 49 | { |
| 50 | input = "x"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 51 | expectedCompletions = {}; |
| 52 | expectedContextLength = 1; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | SECTION("cd") |
| 56 | { |
| 57 | input = "cd"; |
Václav Kubernát | 0165e6c | 2020-02-17 18:18:14 +0100 | [diff] [blame] | 58 | expectedCompletions = {"cd "}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 59 | expectedContextLength = 2; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | SECTION("create") |
| 63 | { |
| 64 | input = "create"; |
Václav Kubernát | 0165e6c | 2020-02-17 18:18:14 +0100 | [diff] [blame] | 65 | expectedCompletions = {"create "}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 66 | expectedContextLength = 6; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 69 | SECTION("copy datastores") |
| 70 | { |
| 71 | input = "copy "; |
| 72 | expectedCompletions = {"running", "startup"}; |
| 73 | expectedContextLength = 0; |
| 74 | } |
| 75 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 76 | REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength})); |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 77 | } |