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 | |
Václav Kubernát | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 10 | #include "trompeloeil_doctest.hpp" |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 11 | #include "datastoreaccess_mock.hpp" |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 12 | #include "parser.hpp" |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 13 | #include "pretty_printers.hpp" |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 14 | #include "static_schema.hpp" |
| 15 | |
| 16 | TEST_CASE("enum completion") |
| 17 | { |
| 18 | auto schema = std::make_shared<StaticSchema>(); |
| 19 | schema->addModule("mod"); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 20 | schema->addContainer("/", "mod:contA"); |
| 21 | schema->addLeafEnum("/", "mod:leafEnum", {"lala", "lol", "data", "coze"}); |
| 22 | schema->addLeafEnum("/mod:contA", "mod:leafInCont", {"abc", "def"}); |
| 23 | schema->addList("/", "mod:list", {"number"}); |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 24 | schema->addLeaf("/mod:list", "mod:number", yang::LeafDataTypes::Int32); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 25 | schema->addLeafEnum("/mod:list", "mod:leafInList", {"ano", "anoda", "ne", "katoda"}); |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 26 | auto mockDatastore = std::make_shared<MockDatastoreAccess>(); |
| 27 | // The parser will use DataQuery for key value completion, but I'm not testing that here, so I don't return anything. |
| 28 | ALLOW_CALL(*mockDatastore, listInstances("/mod:list")) |
| 29 | .RETURN(std::vector<ListInstance>{}); |
| 30 | |
| 31 | // DataQuery gets the schema from DatastoreAccess once |
| 32 | auto expectation = NAMED_REQUIRE_CALL(*mockDatastore, schema()) |
| 33 | .RETURN(schema); |
| 34 | auto dataQuery = std::make_shared<DataQuery>(*mockDatastore); |
| 35 | Parser parser(schema, dataQuery); |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 36 | std::string input; |
| 37 | std::ostringstream errorStream; |
| 38 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 39 | std::set<std::string> expectedCompletions; |
| 40 | int expectedContextLength; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 41 | |
| 42 | SECTION("set mod:leafEnum ") |
| 43 | { |
| 44 | input = "set mod:leafEnum "; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 45 | expectedCompletions = {"lala", "lol", "data", "coze"}; |
| 46 | expectedContextLength = 0; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | SECTION("set mod:leafEnum c") |
| 50 | { |
| 51 | input = "set mod:leafEnum c"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 52 | expectedCompletions = {"coze"}; |
| 53 | expectedContextLength = 1; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | SECTION("set mod:leafEnum l") |
| 57 | { |
| 58 | input = "set mod:leafEnum l"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 59 | expectedCompletions = {"lala", "lol"}; |
| 60 | expectedContextLength = 1; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | |
| 64 | SECTION("set mod:contA/leafInCont ") |
| 65 | { |
| 66 | input = "set mod:contA/leafInCont "; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 67 | expectedCompletions = {"abc", "def"}; |
| 68 | expectedContextLength = 0; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | SECTION("set mod:list[number=42]/leafInList ") |
| 72 | { |
| 73 | input = "set mod:list[number=42]/leafInList "; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 74 | expectedCompletions = {"ano", "anoda", "ne", "katoda"}; |
| 75 | expectedContextLength = 0; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 76 | } |
| 77 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 78 | REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength})); |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 79 | } |