|
@@ -4,6 +4,7 @@
|
|
|
#include <assert.h>
|
|
|
|
|
|
#include "as_tokenizer.h"
|
|
|
+#include "utils.h"
|
|
|
|
|
|
char *inputBuffer =
|
|
|
"start:\n"
|
|
@@ -31,22 +32,25 @@ int main(int argc, char** argv) {
|
|
|
printf("[TEST] assembler tokenizer\n");
|
|
|
// make a memory buffer to FILE*
|
|
|
FILE *fp = fmemopen(inputBuffer, strlen(inputBuffer), "r");
|
|
|
- TokenStream* ts = makeTokenStream(fp);
|
|
|
+ Allocator alct = newAllocator();
|
|
|
+ TokenStream ts = makeTokenStream(alct, fp);
|
|
|
|
|
|
char *outputBuffer = malloc(10240);
|
|
|
// redirect stdout to a file
|
|
|
FILE *out = fmemopen(outputBuffer, 10240, "w");
|
|
|
FILE *origin_stdout = stdout;
|
|
|
stdout = out;
|
|
|
- while (peekToken(ts)->type != ENDOFFILE) {
|
|
|
- printToken(peekToken(ts));
|
|
|
- nextToken(ts);
|
|
|
+ while (peekToken(alct, ts)->type != ENDOFFILE) {
|
|
|
+ printToken(peekToken(alct, ts));
|
|
|
+ nextToken(alct, ts);
|
|
|
}
|
|
|
fclose(out);
|
|
|
stdout = origin_stdout;
|
|
|
// compare outputBuffer with expectedOutput
|
|
|
assert(strcmp(outputBuffer, expectedOutput) == 0);
|
|
|
printf("[PASS] assembler tokenizer\n");
|
|
|
+ free(outputBuffer);
|
|
|
+ deleteAllocator(alct);
|
|
|
return 0;
|
|
|
}
|
|
|
|