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 | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 24 | expectedCompletions = {"cd", "copy", "create", "delete", "set", "commit", "get", "ls", "discard", "help", "describe", "move", "dump", "prepare", "exec", "cancel"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 25 | expectedContextLength = 0; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 26 | SECTION("no space") |
| 27 | { |
Jan Kundrát | 4a65b01 | 2020-05-29 14:03:38 +0200 | [diff] [blame] | 28 | input = ""; |
| 29 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 30 | SECTION("space") |
| 31 | { |
Jan Kundrát | 4a65b01 | 2020-05-29 14:03:38 +0200 | [diff] [blame] | 32 | input = " "; |
| 33 | } |
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 | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 39 | expectedCompletions = {"cd", "commit", "copy", "create", "cancel"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 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 | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 46 | expectedCompletions = {"delete", "discard", "describe", "dump"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 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 | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 71 | SECTION("copy datastores") |
| 72 | { |
| 73 | input = "copy "; |
| 74 | expectedCompletions = {"running", "startup"}; |
| 75 | expectedContextLength = 0; |
| 76 | } |
| 77 | |
Václav Kubernát | 3b5e652 | 2020-06-26 18:36:09 +0200 | [diff] [blame] | 78 | SECTION("dump") |
| 79 | { |
| 80 | input = "dump "; |
| 81 | expectedCompletions = {"xml", "json"}; |
| 82 | expectedContextLength = 0; |
| 83 | } |
| 84 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 85 | REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength})); |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 86 | } |