- Added string strip methods lstrip and rstrip
- Fixed the tokenizer to chomp whitespace from left and right of tokens - Fixed the tokenizer so it returns reserved symbols not just constants and expressions - Added some tests for the basic tokenizer and parser - Started working on structures to allow the basic interpreter to store lines in memory
This commit is contained in:
16
tests/basic_parser.c
Normal file
16
tests/basic_parser.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "types.h"
|
||||
#include "basic.h"
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct basic_expr *expr;
|
||||
expr = basic_parse_expr("1 + 1");
|
||||
if ( expr == NULL ) return 1;
|
||||
if ( expr->lval_type != BASIC_LVAL_CONST ) return 2;
|
||||
if ( expr->rval_type != BASIC_RVAL_CONST ) return 3;
|
||||
if ( expr->lval.i != 1 ) return 4;
|
||||
if ( expr->rval.i != 1 ) return 5;
|
||||
if ( expr->type != BASIC_OPTP_ADD ) return 6;
|
||||
return 0;
|
||||
}
|
||||
5
tests/basic_parser.deps
Normal file
5
tests/basic_parser.deps
Normal file
@@ -0,0 +1,5 @@
|
||||
basic
|
||||
stdlib
|
||||
string
|
||||
conio
|
||||
screen
|
||||
@@ -6,12 +6,12 @@
|
||||
char *_tokenize(char *ptr, char *token);
|
||||
char *_token_get(void);
|
||||
|
||||
#define assert_lvalue(str, lval, ret_null, ret_neq) \
|
||||
#define assert_token_value(str, val, ret_null, ret_neq) \
|
||||
ptr = _tokenize(str, BASIC_TOKENIZER_TOKENS); \
|
||||
value = _token_get(); \
|
||||
if ( ptr == NULL ) return ret_null; \
|
||||
rc = strcmp(value, lval); \
|
||||
printf("(value) == (lval) ? : (%s) == (%s) %d\n", value, lval, rc); \
|
||||
rc = strcmp(value, val); \
|
||||
printf("(%s) => (value) == (val) ? : (%s) == (%s) %d\n", str, value, val, rc); \
|
||||
if ( rc != 0 ) return ret_neq;
|
||||
|
||||
|
||||
@@ -21,9 +21,10 @@ int main(void)
|
||||
char *value = NULL;
|
||||
int rc = 0;
|
||||
|
||||
assert_lvalue("1+1", "1", 1, 2);
|
||||
assert_lvalue("1 + 1", "1", 2, 3);
|
||||
assert_lvalue("10 + 10", "10", 4, 5);
|
||||
|
||||
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;
|
||||
}
|
||||
19
tests/string_chomp.c
Normal file
19
tests/string_chomp.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define assert_strip(method, str, strip, count, rvalue, ret_strcmp, ret_count) \
|
||||
memset((char *)&buff, 0x00, 32); \
|
||||
rc = method(str, (char *)&buff, strip); \
|
||||
printf("method(%s) => (%d, %s)\n", str, rc, (char *)&buff); \
|
||||
if ( rc != count) return ret_count; \
|
||||
if ( strcmp((char *)&buff, rvalue) != 0 ) return ret_strcmp;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char buff[32];
|
||||
int rc = 0;
|
||||
assert_strip(lstrip, " white space", " ", 3, "white space", 1, 2)
|
||||
assert_strip(rstrip, "white space ", " ", 3, "white space", 3, 4)
|
||||
return 0;
|
||||
}
|
||||
2
tests/string_chomp.deps
Normal file
2
tests/string_chomp.deps
Normal file
@@ -0,0 +1,2 @@
|
||||
string
|
||||
stdlib
|
||||
Reference in New Issue
Block a user