예제 #1
0
TEST(ng_charreach, setRange) {
    // Exhaustive test: every possible contiguous range.
    for (unsigned range = 0; range < 256; range++) {
        for (unsigned from = 0; from < 256 - range; from++) {
            unsigned to = from + range;
            CharReach cr;
            cr.setRange(from, to);
            ASSERT_EQ(from, cr.find_first());
            ASSERT_EQ(to, cr.find_last());
            ASSERT_EQ(range + 1, cr.count());
        }
    }
}
예제 #2
0
TEST(Truffle, ExecMatch7) {
    m128 mask1, mask2;

    CharReach chars;

    // hi bits
    chars.setRange(127, 255);

    truffleBuildMasks(chars, (u8 *)&mask1, (u8 *)&mask2);

    std::array<u8, 128> t1;
    t1.fill('*'); // it's full of stars!

    for (unsigned int c = 127; c <= 255; c++) {
        t1[40] = (u8)c;
        const u8 *rv = truffleExec(mask1, mask2, (u8 *)t1.data(), (u8 *)t1.data() + 128);

        ASSERT_EQ((size_t)t1.data() + 40, (size_t)rv);
    }
}
예제 #3
0
TEST(Truffle, ExecMatch6) {
    m128 mask1, mask2;

    CharReach chars;

    // [0-Z] - includes some graph chars
    chars.setRange('0', 'Z');

    truffleBuildMasks(chars, (u8 *)&mask1, (u8 *)&mask2);

    std::array<u8, 128> t1;
    t1.fill('*'); // it's full of stars!

    for (u8 c = '0'; c <= 'Z'; c++) {
        t1[17] = c;
        const u8 *rv = truffleExec(mask1, mask2, (u8 *)t1.data(), (u8 *)t1.data() + 128);

        ASSERT_EQ((size_t)t1.data() + 17, (size_t)rv);
    }
}