Beispiel #1
0
void test_eof_bof(void) {
  const char *b = "test";
  scanner_t *s = scanner_init(b);

  assert(scanner_peek(s) == 't');
  assert(scanner_advance(s) == 't');
  assert(scanner_advance(s) == 'e');
  assert(scanner_peek(s) == 's');
  assert(scanner_advance(s) == 's');
  assert(scanner_advance(s) == 't');
  assert(scanner_peek(s) == 0);
  assert(scanner_current(s) == 't');
  assert(scanner_advance(s) == 0);
  assert(scanner_advance(s) == 0);
  assert(scanner_advance(s) == 0);
  assert(scanner_advance(s) == 0);
  assert(scanner_current(s) == 0);
  assert(scanner_backup(s) == 't');
  assert(scanner_backup(s) == 's');
  assert(scanner_peek(s) == 't');
  assert(scanner_backup(s) == 'e');
  assert(scanner_backup(s) == 't');
  assert(scanner_backup(s) == 0);
  assert(scanner_current(s) == 0);
  assert(scanner_peek(s) == 't');

  scanner_destroy(s);
}
Beispiel #2
0
void test_eof_bof_after_accept(void) {
  const char *b = "test this";
  scanner_t *s = scanner_init(b);

  assert(scanner_advance(s) == 't');
  assert(scanner_advance(s) == 'e');
  assert(scanner_advance(s) == 's');
  assert(scanner_advance(s) == 't');
  assert(scanner_advance(s) == ' ');
  scanner_ignore(s);
  assert(scanner_current(s) == 0);
  assert(scanner_advance(s) == 't');
  assert(scanner_advance(s) == 'h');
  assert(scanner_advance(s) == 'i');
  assert(scanner_advance(s) == 's');
  assert(scanner_advance(s) == 0);
  assert(scanner_advance(s) == 0);
  assert(scanner_current(s) == 0);
  assert(scanner_backup(s) == 's');
  assert(scanner_backup(s) == 'i');
  assert(scanner_backup(s) == 'h');
  assert(scanner_backup(s) == 't');
  assert(scanner_backup(s) == 0);

  scanner_destroy(s);
}
Beispiel #3
0
void test_buffer_walk(void) {
  const char *b = "this is a small test buffer";
  scanner_t *s = scanner_init(b);

  assert(scanner_peek(s) == 't');
  assert(scanner_advance(s) == 't');
  assert(scanner_advance(s) == 'h');
  assert(scanner_advance(s) == 'i');
  assert(scanner_advance(s) == 's');
  assert(scanner_peek(s) == ' ');
  assert(scanner_current(s) == 's');
  assert(scanner_advance(s) == ' ');
  assert(scanner_backup(s) == 's');

  char *xthis = (char*)scanner_accept(s, (acceptfn)test_accept_fn);
  assert(strcmp(xthis, "this") == 0);
  free(xthis);

  size_t i = 4;
  char c;
  while ((c = scanner_advance(s)))
    assert(c == b[i++]);
  assert(strlen(b) == i);

  scanner_destroy(s);
}
Beispiel #4
0
void _test(char *test_name, Scanner *scn,
        char *infile, char *resfile, char *verifile)
{
    if (infile != NULL)
    {
        if (scanner_set_file_stream(scn, infile) == -1)
            return;
    }

    FILE *f = fopen(resfile, "w");
    if (f == NULL)
    {
        perror("couldn't open resfile for read:");
        return;
    }

    char *separator = NULL;
    char *token = NULL;

    int i = 0;
    while (!scanner_stream_is_empty(scn->stream))// && i < 55)
    {
        token = scanner_next(scn, &separator);
        //char *esc = g_strescape(separator, "");
        //printf("sep: '%s'\n", esc);
        //g_free(esc);
        //esc = NULL;
        fprintf(f, "%s\n%s\n", token, separator);
        g_free(token);
        i++;
    }
    fclose(f);
    scanner_destroy(scn);
    print_result(test_name, resfile, verifile);
}
JNIEXPORT void JNICALL Java_io_card_payment_CardScanner_nCleanup(JNIEnv *env, jobject thiz) {
  dmz_debug_log("Java_io_card_payment_CardScanner_nCleanup");

  if (dmz_refcount == 1) {
    scanner_destroy(&scannerState);
    dmz_context_destroy(dmz);
    dmz = NULL;
  }
  dmz_refcount--;
}
Beispiel #6
0
int main(){
	scanner_t scan = scanner_new("test.m");
	
	token_t tok;
	do {
		tok = scanner_read(&scan);
		printf("%s: %.*s\n", token_names[tok.type], (int)tok.length, tok.text);
	} while(tok.type != T_EOF);
	
	scanner_destroy(&scan);
}
Beispiel #7
0
void test_file_walk(const char *file) {
  char buf[3008];
  FILE *f = fopen(file, "rb");
  int i, j, n = fread(buf, sizeof(char), sizeof(buf), f);
  fclose(f);

  scanner_t *s = scanner_init_file(file);

  for (j = 0; j < n; j+=16) {
    for (i = 0; i < 16 && i+j < n; i++)
      assert(scanner_advance(s) == buf[j+i]);
    char *tok = (char*)scanner_accept(s, (acceptfn)test_accept_fn);
    assert(strncmp(tok, buf+j, 16) == 0);
    free(tok);
  }

  scanner_destroy(s);
}