blob: 29f23a76509b2ee4c136d0a8417050cd764b776b [file] [log] [blame]
/*
* Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
* Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
*
* Written by Václav Kubernát <kubervac@fit.cvut.cz>
*
*/
#include "trompeloeil_doctest.h"
#include "parser.hpp"
#include "pretty_printers.hpp"
#include "static_schema.hpp"
TEST_CASE("enum completion")
{
auto schema = std::make_shared<StaticSchema>();
schema->addModule("mod");
schema->addContainer("/", "mod:contA");
schema->addLeafEnum("/", "mod:leafEnum", {"lala", "lol", "data", "coze"});
schema->addLeafEnum("/mod:contA", "mod:leafInCont", {"abc", "def"});
schema->addList("/", "mod:list", {"number"});
schema->addLeaf("/mod:list", "mod:number", yang::LeafDataTypes::Int32);
schema->addLeafEnum("/mod:list", "mod:leafInList", {"ano", "anoda", "ne", "katoda"});
Parser parser(schema);
std::string input;
std::ostringstream errorStream;
std::set<std::string> expectedCompletions;
int expectedContextLength;
SECTION("set mod:leafEnum ")
{
input = "set mod:leafEnum ";
expectedCompletions = {"lala", "lol", "data", "coze"};
expectedContextLength = 0;
}
SECTION("set mod:leafEnum c")
{
input = "set mod:leafEnum c";
expectedCompletions = {"coze"};
expectedContextLength = 1;
}
SECTION("set mod:leafEnum l")
{
input = "set mod:leafEnum l";
expectedCompletions = {"lala", "lol"};
expectedContextLength = 1;
}
SECTION("set mod:contA/leafInCont ")
{
input = "set mod:contA/leafInCont ";
expectedCompletions = {"abc", "def"};
expectedContextLength = 0;
}
SECTION("set mod:list[number=42]/leafInList ")
{
input = "set mod:list[number=42]/leafInList ";
expectedCompletions = {"ano", "anoda", "ne", "katoda"};
expectedContextLength = 0;
}
REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
}