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