TEST(ng_charreach, clear) { CharReach cr; ASSERT_EQ(0U, cr.count()); ASSERT_TRUE(cr.none()); ASSERT_FALSE(cr.all()); cr.set('q'); cr.set('u'); cr.set('a'); cr.set('r'); cr.set('k'); ASSERT_EQ(5U, cr.count()); cr.clear('r'); ASSERT_EQ(4U, cr.count()); ASSERT_FALSE(cr.test('r')); cr.setall(); ASSERT_EQ(cr.size(), cr.count()); ASSERT_TRUE(cr.all()); cr.clear(0xff); ASSERT_FALSE(cr.all()); }
TEST(Truffle, CompileChars) { m128 mask1, mask2; CharReach chars; // test one char at a time for (u32 c = 0; c < 256; ++c) { mask1 = zeroes128(); mask2 = zeroes128(); chars.clear(); chars.set((u8)c); truffleBuildMasks(chars, (u8 *)&mask1, (u8 *)&mask2); CharReach out = truffle2cr((u8 *)&mask1, (u8 *)&mask2); ASSERT_EQ(out, chars); } // set all chars up to dot for (u32 c = 0; c < 256; ++c) { mask1 = zeroes128(); mask2 = zeroes128(); chars.set((u8)c); truffleBuildMasks(chars, (u8 *)&mask1, (u8 *)&mask2); CharReach out = truffle2cr((u8 *)&mask1, (u8 *)&mask2); ASSERT_EQ(out, chars); } // unset all chars from dot for (u32 c = 0; c < 256; ++c) { mask1 = zeroes128(); mask2 = zeroes128(); chars.clear((u8)c); truffleBuildMasks(chars, (u8 *)&mask1, (u8 *)&mask2); CharReach out = truffle2cr((u8 *)&mask1, (u8 *)&mask2); ASSERT_EQ(out, chars); } }
TEST(ng_charreach, bit5) { CharReach cr; ASSERT_TRUE(cr.isBit5Insensitive()); cr.set('a'); ASSERT_FALSE(cr.isBit5Insensitive()); cr.set('A'); ASSERT_TRUE(cr.isBit5Insensitive()); cr.set('!'); ASSERT_FALSE(cr.isBit5Insensitive()); cr.set(1); ASSERT_TRUE(cr.isBit5Insensitive()); cr.clear(); cr.set('!'); cr.set('A'); ASSERT_FALSE(cr.isBit5Insensitive()); cr.clear(); cr.set('A'); cr.set('b'); ASSERT_FALSE(cr.isBit5Insensitive()); cr.set('a'); cr.set('B'); ASSERT_TRUE(cr.isBit5Insensitive()); }
TEST(ng_charreach, find_last) { CharReach cr; cr.set('a'); ASSERT_EQ(cr.find_last(), (size_t)'a'); cr.set('b'); ASSERT_EQ(cr.find_last(), (size_t)'b'); cr.set(192); ASSERT_EQ(cr.find_last(), (size_t)192); cr.set(207); ASSERT_EQ(cr.find_last(), (size_t)207); cr.set(223); ASSERT_EQ(cr.find_last(), (size_t)223); cr.set(255); ASSERT_EQ(cr.find_last(), (size_t)255); cr.clear(); ASSERT_EQ(cr.find_last(), cr.size()); cr.set(0); ASSERT_EQ(cr.find_last(), (size_t)0); cr.set(1); ASSERT_EQ(cr.find_last(), (size_t)1); }