#include //TODO Include the 2 libs of criterion #include #include #include #include "ast/ast.h" #include "lexer/expansion.h" #include "lexer/lexer.h" #include "lexer/token.h" #include "utils/utils.h" TestSuite(ParserBasic); Test(ParserBasic, onlyone) { struct string *input = string_create("echo"); struct lexer *test = lexer_new(input); struct ast *root = parse(lexer); cr_expect(root->type == AST_LIST); ast_free(root); lexer_free(test); } /* Test(ParserBasic, easytricky) { struct string *input = string_create("\'echo\' H\'el\'lo World \n test"); struct lexer *l = lexer_new(input); struct token t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "echo"); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "Hello"); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "World"); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_NEWLINE); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "test"); lexer_free(l); string_free(input); } Test(ParserBasic, harderdaddy) { struct string *input = string_create("echo\'\' H\\'ello World\\' \n test"); struct lexer *l = lexer_new(input); struct token t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "echo"); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "H\'ello World\'"); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_NEWLINE); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "test"); lexer_free(l); string_free(input); } Test(ParserBasic, routine) { struct string *input = string_create("i'f' 't''r''u''e'; 'then'\necho ok;\nelse echo \\'ko\\';"); struct lexer *l = lexer_new(input); struct token t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_IF); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "true"); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_SEMICOLON); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_THEN); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_NEWLINE); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "echo"); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "ok"); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_SEMICOLON); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_NEWLINE); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_ELSE); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "echo"); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_WORD); cr_expect_str_eq(t.value->data, "\'ko\'"); t = lexer_pop(l); cr_expect_eq(t.type, TOKEN_SEMICOLON); lexer_free(l); string_free(input); }*\