This repository has been archived on 2026-05-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
piquant/tests/basic_tokenizer.c

29 lines
770 B
C
Raw Permalink Normal View History

#include "basic.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
char *_tokenize(char *ptr, char *token);
#define assert_token_value(str, val, ret_null, ret_neq) \
ptr = _tokenize(str, BASIC_TOKENIZER_TOKENS); \
value = tokenizer_token(); \
if ( ptr == NULL ) return ret_null; \
rc = strcmp(value, val); \
printf("(%s) => (value) == (val) ? : (%s) == (%s) %d\n", str, value, val, rc); \
if ( rc != 0 ) return ret_neq;
int main(void)
{
char *ptr = NULL;
char *value = NULL;
int rc = 0;
assert_token_value("1+1", "1", 1, 2);
assert_token_value("1 + 1", "1", 2, 3);
assert_token_value("10 + 10", "10", 4, 5);
assert_token_value("1+ 2", "1", 6, 7)
assert_token_value("+ 2", "+", 8, 9)
return 0;
}