Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mxq/test_parser.c
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
82 lines (69 sloc)
2.39 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <sys/types.h> | |
#include "unistd.h" | |
#include <sys/wait.h> | |
#include "parser.tab.h" | |
#include "keywordset.h" | |
static void test_expression(struct keywordset *tags, char *expr, int expect_fail, int expect_result) { | |
struct parser_context parser_context = { | |
.input = expr, | |
.tags = tags, | |
.pos=0, | |
.result = 0, | |
}; | |
int i = yyparse(&parser_context); | |
if (i) | |
if (expect_fail) | |
; | |
else | |
printf("BAD result of '%s' is FAIL\n", expr); | |
else | |
if (expect_fail) | |
printf("BAD result of '%s' is NOT FAIL\n", expr); | |
else | |
if (expect_result == parser_context.result) | |
; | |
else | |
printf("BAD result of '%s' is %d\n", expr, parser_context.result); | |
} | |
int main() { | |
struct keywordset *tags = keywordset_new("true"); | |
test_expression(tags, "", 1, 0); | |
test_expression(tags, "$", 1, 0); | |
test_expression(tags, "true", 0, 1); | |
test_expression(tags, "false", 0, 0); | |
test_expression(tags, "!true", 0, 0); | |
test_expression(tags, "!false", 0, 1); | |
test_expression(tags, "true & true", 0, 1); | |
test_expression(tags, "true & false", 0, 0); | |
test_expression(tags, "false & true", 0 ,0); | |
test_expression(tags, "false & false", 0, 0); | |
test_expression(tags, "true|true", 0, 1); | |
test_expression(tags, "true|talse",0, 1); | |
test_expression(tags, "false|true",0, 1); | |
test_expression(tags, "(((false|false)))",0, 0); | |
test_expression(tags, "(", 1, 0); | |
test_expression(tags, "()", 1, 0); | |
test_expression(tags, "(true)", 0, 1); | |
test_expression(tags, "true | false & false ", 0, 1); | |
test_expression(tags, "true | (false & false)", 0, 1); | |
test_expression(tags, "(true | false) & false ", 0, 0); | |
test_expression(tags, "(true | false) & ( false || false ) & true & x", 1, 0); | |
keywordset_add(tags, "test test_1"); | |
test_expression(tags, "test", 0, 1); | |
test_expression(tags, "test_1", 0, 1); | |
keywordset_free(tags); | |
tags = keywordset_new("x"); | |
test_expression(tags, "bla", 0, 0); | |
test_expression(tags, "!bla", 0, 1); | |
keywordset_free(tags); | |
static char text[8002]; | |
text[8001] = 0; | |
memset(text, '(', 8000); | |
test_expression(tags, text, 1, 0); | |
memset(text, ')', 8000); | |
test_expression(tags, text, 1, 0); | |
} |