示例#1
0
void __CUT__Token_create( void )
{
    CORD data = CORD_from_char_star("100");
    Token *tk = Token_create(TK_INT, data, NULL);

    ASSERT(tk->id == TK_INT, "wrong id.");
    ASSERT(tk->value == 100, "wrong value.");

    tk = Token_create(TK_CHR, CORD_from_char_star("'A'"), NULL);
    ASSERT(tk->id == TK_CHR, "wrong id.");
    ASSERT(tk->value == 'A', "wrong value.");

    tk = Token_create(TK_FLOAT, CORD_from_char_star("1.1"), NULL);
    ASSERT(tk->id == TK_FLOAT, "wrong id.");
    ASSERT(tk->value <= 2.0f && tk->value >= 0.0f, "wrong value");

    tk = Token_create(TK_HEX, CORD_from_char_star("0xAE"), NULL);
    ASSERT(tk->id == TK_HEX, "wrong id.");
    ASSERT(tk->value == 0xAE, "wrong value");

    tk = Token_create(TK_REG, CORD_from_char_star("R0"), NULL);
    ASSERT(tk->id = TK_REG, "wrong id.");
    ASSERT(tk->value == 0, "wrong value.");
}
示例#2
0
文件: cordtest.c 项目: comforx/bdwgc
void test_basics(void)
{
    CORD x = CORD_from_char_star("ab");
    register int i;
    char c;
    CORD y;
    CORD_pos p;

    x = CORD_cat(x,x);
    if (x == CORD_EMPTY) ABORT("CORD_cat(x,x) returned empty cord");
    if (!CORD_IS_STRING(x)) ABORT("short cord should usually be a string");
    if (strcmp(x, "abab") != 0) ABORT("bad CORD_cat result");

    for (i = 1; i < 16; i++) {
        x = CORD_cat(x,x);
    }
    x = CORD_cat(x,"c");
    if (CORD_len(x) != 128*1024+1) ABORT("bad length");

    count = 0;
    if (CORD_iter5(x, 64*1024-1, test_fn, CORD_NO_FN, (void *)13) == 0) {
        ABORT("CORD_iter5 failed");
    }
    if (count != 64*1024 + 2) ABORT("CORD_iter5 failed");

    count = 0;
    CORD_set_pos(p, x, 64*1024-1);
    while(CORD_pos_valid(p)) {
        (void) test_fn(CORD_pos_fetch(p), (void *)13);
    CORD_next(p);
    }
    if (count != 64*1024 + 2) ABORT("Position based iteration failed");

    y = CORD_substr(x, 1023, 5);
    if (!y) ABORT("CORD_substr returned NULL");
    if (!CORD_IS_STRING(y)) ABORT("short cord should usually be a string");
    if (strcmp(y, "babab") != 0) ABORT("bad CORD_substr result");

    y = CORD_substr(x, 1024, 8);
    if (!y) ABORT("CORD_substr returned NULL");
    if (!CORD_IS_STRING(y)) ABORT("short cord should usually be a string");
    if (strcmp(y, "abababab") != 0) ABORT("bad CORD_substr result");

    y = CORD_substr(x, 128*1024-1, 8);
    if (!y) ABORT("CORD_substr returned NULL");
    if (!CORD_IS_STRING(y)) ABORT("short cord should usually be a string");
    if (strcmp(y, "bc") != 0) ABORT("bad CORD_substr result");

    x = CORD_balance(x);
    if (CORD_len(x) != 128*1024+1) ABORT("bad length");

    count = 0;
    if (CORD_iter5(x, 64*1024-1, test_fn, CORD_NO_FN, (void *)13) == 0) {
        ABORT("CORD_iter5 failed");
    }
    if (count != 64*1024 + 2) ABORT("CORD_iter5 failed");

    y = CORD_substr(x, 1023, 5);
    if (!y) ABORT("CORD_substr returned NULL");
    if (!CORD_IS_STRING(y)) ABORT("short cord should usually be a string");
    if (strcmp(y, "babab") != 0) ABORT("bad CORD_substr result");
    y = CORD_from_fn(id_cord_fn, 0, 13);
    i = 0;
    CORD_set_pos(p, y, i);
    while(CORD_pos_valid(p)) {
        c = CORD_pos_fetch(p);
        if(c != i) ABORT("Traversal of function node failed");
    CORD_next(p); i++;
    }
    if (i != 13) ABORT("Bad apparent length for function node");
}