blob: 29f23a76509b2ee4c136d0a8417050cd764b776b [file] [log] [blame]
Václav Kubernát989b5de2019-02-20 16:28:35 +01001
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áta33cf082019-03-28 11:55:57 +010010#include "trompeloeil_doctest.h"
Václav Kubernát989b5de2019-02-20 16:28:35 +010011#include "parser.hpp"
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010012#include "pretty_printers.hpp"
Václav Kubernát989b5de2019-02-20 16:28:35 +010013#include "static_schema.hpp"
14
15TEST_CASE("enum completion")
16{
17 auto schema = std::make_shared<StaticSchema>();
18 schema->addModule("mod");
Václav Kubernátefcac932020-01-10 15:26:32 +010019 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át7707cae2020-01-16 12:04:53 +010023 schema->addLeaf("/mod:list", "mod:number", yang::LeafDataTypes::Int32);
Václav Kubernátefcac932020-01-10 15:26:32 +010024 schema->addLeafEnum("/mod:list", "mod:leafInList", {"ano", "anoda", "ne", "katoda"});
Václav Kubernát989b5de2019-02-20 16:28:35 +010025 Parser parser(schema);
26 std::string input;
27 std::ostringstream errorStream;
28
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010029 std::set<std::string> expectedCompletions;
30 int expectedContextLength;
Václav Kubernát989b5de2019-02-20 16:28:35 +010031
32 SECTION("set mod:leafEnum ")
33 {
34 input = "set mod:leafEnum ";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010035 expectedCompletions = {"lala", "lol", "data", "coze"};
36 expectedContextLength = 0;
Václav Kubernát989b5de2019-02-20 16:28:35 +010037 }
38
39 SECTION("set mod:leafEnum c")
40 {
41 input = "set mod:leafEnum c";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010042 expectedCompletions = {"coze"};
43 expectedContextLength = 1;
Václav Kubernát989b5de2019-02-20 16:28:35 +010044 }
45
46 SECTION("set mod:leafEnum l")
47 {
48 input = "set mod:leafEnum l";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010049 expectedCompletions = {"lala", "lol"};
50 expectedContextLength = 1;
Václav Kubernát989b5de2019-02-20 16:28:35 +010051 }
52
53
54 SECTION("set mod:contA/leafInCont ")
55 {
56 input = "set mod:contA/leafInCont ";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010057 expectedCompletions = {"abc", "def"};
58 expectedContextLength = 0;
Václav Kubernát989b5de2019-02-20 16:28:35 +010059 }
60
61 SECTION("set mod:list[number=42]/leafInList ")
62 {
63 input = "set mod:list[number=42]/leafInList ";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010064 expectedCompletions = {"ano", "anoda", "ne", "katoda"};
65 expectedContextLength = 0;
Václav Kubernát989b5de2019-02-20 16:28:35 +010066 }
67
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010068 REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
Václav Kubernát989b5de2019-02-20 16:28:35 +010069}