Skip to content
Permalink
a165e5f6b6
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
77 lines (65 sloc) 2.25 KB
#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);
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);
}