Commit 9f3da489 authored by Daniel Salzman's avatar Daniel Salzman

yparser: extend boolen values with true/false

parent 08e2e12a
......@@ -79,11 +79,11 @@ static int yp_str_to_txt(
static int yp_bool_to_bin(
TXT_BIN_PARAMS)
{
if (strcasecmp(txt, "on") == 0) {
if (strcasecmp(txt, "on") == 0 || strcasecmp(txt, "true") == 0) {
bin[0] = '\0'; // Just in case.
*bin_len = 1;
return KNOT_EOK;
} else if (strcasecmp(txt, "off") == 0) {
} else if (strcasecmp(txt, "off") == 0 || strcasecmp(txt, "false") == 0) {
*bin_len = 0;
return KNOT_EOK;
}
......
......@@ -55,10 +55,11 @@ static const lookup_table_t opts[] = {
};
static const yp_item_t static_scheme[] = {
{ C_OPT, YP_TOPT, YP_VOPT = { opts } },
{ C_GRP, YP_TGRP, YP_VGRP = { group } },
{ C_MULTIGRP, YP_TGRP, YP_VGRP = { multi_group }, YP_FMULTI },
{ C_REF, YP_TREF, YP_VREF = { C_MULTIGRP } },
{ C_OPT, YP_TOPT, YP_VOPT = { opts } },
{ C_BOOL, YP_TBOOL, YP_VNONE },
{ C_GRP, YP_TGRP, YP_VGRP = { group } },
{ C_MULTIGRP, YP_TGRP, YP_VGRP = { multi_group }, YP_FMULTI },
{ C_REF, YP_TREF, YP_VREF = { C_MULTIGRP } },
{ NULL }
};
......@@ -96,6 +97,31 @@ int main(int argc, char *argv[])
ok(ctx->key0->type == YP_TOPT, "type check");
ok(yp_opt(ctx->data) == 1, "value check");
/* Boolean test. */
str = "bool: true\nbool: on\nbool: false\nbool: off";
ret = yp_set_input_string(yp, str, strlen(str));
ok(ret == KNOT_EOK, "set input string");
for (int i = 0; i < 2; i++) {
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse");
ret = yp_scheme_check_parser(ctx, yp);
ok(ret == KNOT_EOK, "check parser");
ok(ctx->event == YP_EKEY0, "event check");
ok(strcmp(ctx->key0->name + 1, "bool") == 0, "name check");
ok(ctx->key0->type == YP_TBOOL, "type check");
ok(yp_bool(ctx->data_len) == true, "value check");
}
for (int i = 0; i < 2; i++) {
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse");
ret = yp_scheme_check_parser(ctx, yp);
ok(ret == KNOT_EOK, "check parser");
ok(ctx->event == YP_EKEY0, "event check");
ok(strcmp(ctx->key0->name + 1, "bool") == 0, "name check");
ok(ctx->key0->type == YP_TBOOL, "type check");
ok(yp_bool(ctx->data_len) == false, "value check");
}
/* Group test. */
str = "group:\n integer: 20\n string: [short, \"long string\"]";
ret = yp_set_input_string(yp, str, strlen(str));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment