at work
This commit is contained in:
51
tests/clparser_test.c
Normal file
51
tests/clparser_test.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2023 Oleg Borodin <borodin@unix7.org>
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <cllexer.h>
|
||||
#include <clparser.h>
|
||||
|
||||
int main(void) {
|
||||
//(void)argc;
|
||||
//(void)argv;
|
||||
|
||||
char* argv[] = { "main", "--id=-123", "--name=qwerty12234", "--debug=truew" };
|
||||
int argc = 4;
|
||||
|
||||
cllexer_t lexer;
|
||||
clparser_t parser;
|
||||
|
||||
cllexer_init(&lexer);
|
||||
clparser_init(&parser, &lexer);
|
||||
|
||||
int id = 0;
|
||||
char* name = "";
|
||||
bool debug = false;
|
||||
|
||||
clparser_bind(&parser, CLVALTYPE_INT, "id", (void *)&id);
|
||||
clparser_bind(&parser, CLVALTYPE_STR, "name", (void *)&name);
|
||||
clparser_bind(&parser, CLVALTYPE_BOOL, "debug", (void *)&debug);
|
||||
|
||||
if (clparser_parse(&parser, &argv[1], argc - 1) < 0) {
|
||||
printf("parse args error\n");
|
||||
return 1;
|
||||
}
|
||||
printf("id = %d\n", id);
|
||||
printf("name = %s\n", name);
|
||||
printf("debug = %d\n", debug);
|
||||
|
||||
clparser_destroy(&parser);
|
||||
cllexer_destroy(&lexer);
|
||||
|
||||
free(name);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user