Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 4 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 5 | * |
| 6 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 7 | * |
| 8 | */ |
| 9 | |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 10 | #include "trompeloeil_doctest.h" |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 11 | #include "parser.hpp" |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 12 | #include "pretty_printers.hpp" |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 13 | #include "static_schema.hpp" |
| 14 | |
| 15 | TEST_CASE("enum completion") |
| 16 | { |
| 17 | auto schema = std::make_shared<StaticSchema>(); |
| 18 | schema->addModule("mod"); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 19 | schema->addContainer("/", "mod:contA"); |
| 20 | schema->addLeafEnum("/", "mod:leafEnum", {"lala", "lol", "data", "coze"}); |
| 21 | schema->addLeafEnum("/mod:contA", "mod:leafInCont", {"abc", "def"}); |
| 22 | schema->addList("/", "mod:list", {"number"}); |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 23 | schema->addLeaf("/mod:list", "mod:number", yang::LeafDataTypes::Int32); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 24 | schema->addLeafEnum("/mod:list", "mod:leafInList", {"ano", "anoda", "ne", "katoda"}); |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 25 | Parser parser(schema); |
| 26 | std::string input; |
| 27 | std::ostringstream errorStream; |
| 28 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 29 | std::set<std::string> expectedCompletions; |
| 30 | int expectedContextLength; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 31 | |
| 32 | SECTION("set mod:leafEnum ") |
| 33 | { |
| 34 | input = "set mod:leafEnum "; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 35 | expectedCompletions = {"lala", "lol", "data", "coze"}; |
| 36 | expectedContextLength = 0; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | SECTION("set mod:leafEnum c") |
| 40 | { |
| 41 | input = "set mod:leafEnum c"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 42 | expectedCompletions = {"coze"}; |
| 43 | expectedContextLength = 1; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | SECTION("set mod:leafEnum l") |
| 47 | { |
| 48 | input = "set mod:leafEnum l"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 49 | expectedCompletions = {"lala", "lol"}; |
| 50 | expectedContextLength = 1; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
| 54 | SECTION("set mod:contA/leafInCont ") |
| 55 | { |
| 56 | input = "set mod:contA/leafInCont "; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 57 | expectedCompletions = {"abc", "def"}; |
| 58 | expectedContextLength = 0; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | SECTION("set mod:list[number=42]/leafInList ") |
| 62 | { |
| 63 | input = "set mod:list[number=42]/leafInList "; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 64 | expectedCompletions = {"ano", "anoda", "ne", "katoda"}; |
| 65 | expectedContextLength = 0; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 66 | } |
| 67 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 68 | REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength})); |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 69 | } |