toNFC() is implemented now. Add unittest for toNFC().

JSON-107-01
Roker 4 years ago
parent 9c9384a235
commit d073634df1

@ -9,14 +9,17 @@ namespace {
struct TestEntry
{
std::string input;
int yesno; // HACK: -1 means: will throw "unimplemented", yet.
bool is_nfc;
IsNFC quick;
std::string nfc;
};
typedef TestEntry TE;
std::ostream& operator<<(std::ostream& o, const TestEntry& tt)
{
return o << "input=«" << tt.input << "», isNfc=" << tt.yesno << ", quick=" << tt.quick << ". ";
return o << "input=«" << tt.input << "», isNfc=" << tt.is_nfc << ", quick=" << tt.quick << ". ";
}
@ -24,28 +27,28 @@ const char nullo[4] = {0,0,0,0};
const std::vector<TestEntry> testValues =
{
{ "" , 1, IsNFC::Yes }, // always start with the simple case ;-)
{ "123" , 1, IsNFC::Yes }, // some ASCII digits. Still easy.
{ "\n\\\b", 1, IsNFC::Yes }, // backslash escapes for ASCII and control chars
{ "ä" , 1, IsNFC::Yes }, // <U+00E4> small a with diaeresis
{ "\xc4\x85" , 1, IsNFC::Yes }, // <U+0105> small a with ogonek
{ "" , true, IsNFC::Yes, "" }, // always start with the simple case ;-)
{ "123" , true, IsNFC::Yes, "123" }, // some ASCII digits. Still easy.
{ "\n\\\b" , true, IsNFC::Yes, "\n\\\b" }, // backslash escapes for ASCII and control chars
{ "ä" , true, IsNFC::Yes, "ä" }, // <U+00E4> small a with diaeresis
{ "\xc4\x85" , true, IsNFC::Yes, "\xc4\x85" }, // <U+0105> small a with ogonek
{ "a\xcc\x88", 0, IsNFC::Maybe }, // a + <U+0308> combining diaresis
{ "a\xcc\xa8", 0, IsNFC::Maybe }, // a + <U+0328> combining ogonek
{ "a\xcc\xa8\xcc\x88", 0, IsNFC::Maybe }, // a + <U+0328> + <U+0308> ( ogonek + diaresis)
{ "a\xcc\x88\xcc\xa8", 0, IsNFC::Maybe }, // a + <U+0308> + <U+0328> ( diaeresis + ogonek)
{ "a\xcc\x88", false, IsNFC::Maybe, "ä" }, // a + <U+0308> combining diaresis
{ "a\xcc\xa8", false, IsNFC::Maybe, "\xc4\x85" }, // a + <U+0328> combining ogonek
{ "a\xcc\xa8\xcc\x88", false, IsNFC::Maybe, "\xc4\x85\xcc\x88" }, // a + <U+0328> + <U+0308> (ogonek + diaeresis)
{ "a\xcc\x88\xcc\xa8", false, IsNFC::Maybe, "\xc4\x85\xcc\x88" }, // a + <U+0308> + <U+0328> (diaeresis + ogonek)
{ "\xc4\x85\xcc\x88" , 1, IsNFC::Maybe }, // <U+0105> small a with ogonek + combining diaeresis
{ "ä\xcc\xa8", 0, IsNFC::Maybe }, // a diaeresis + <U+0328> combining ogonek
{ "\xc4\x85\xcc\x88" , true, IsNFC::Maybe, "\xc4\x85\xcc\x88" }, // <U+0105> small a with ogonek + combining diaeresis
{ "ä\xcc\xa8" , false, IsNFC::Maybe, "\xc4\x85\xcc\x88" }, // a diaeresis + <U+0328> combining ogonek
// Already implemented, because <U+305> and <U+33C> have neither "No" nor "Maybe" NFC class:
{ "a\xcc\x85\xcc\xbc", 0, IsNFC::No }, // a + <U+0305> + <U+033C> ( overline + seagull_below)
{ "a\xcc\xbc\xcc\x85", +1, IsNFC::Yes }, // a + <U+033C> + <U+0305> ( seagull_below + overline)
{ "a\xcc\x85\xcc\xbc", false, IsNFC::No , "a\xcc\xbc\xcc\x85"}, // a + <U+0305> + <U+033C> (overline + seagull_below)
{ "a\xcc\xbc\xcc\x85", true, IsNFC::Yes , "a\xcc\xbc\xcc\x85"}, // a + <U+033C> + <U+0305> (seagull_below + overline)
{ std::string(nullo, nullo+1), 1, IsNFC::Yes }, // Yeah, 1 NUL byte
{ std::string(nullo, nullo+4), 1, IsNFC::Yes }, // Yeah, 4 NUL bytes
{ std::string(nullo, nullo+1), true, IsNFC::Yes, std::string(nullo, nullo+1) }, // Yeah, 1 NUL byte
{ std::string(nullo, nullo+4), true, IsNFC::Yes, std::string(nullo, nullo+4) }, // Yeah, 4 NUL bytes
{ "EOF", 1, IsNFC::Yes }
{ "EOF", true, IsNFC::Yes, "EOF" }
};
}
@ -59,13 +62,14 @@ INSTANTIATE_TEST_CASE_P(NfcTestInstance, NfcTest, testing::ValuesIn(testValues)
TEST_P( NfcTest, Meh )
{
const auto v = GetParam();
const auto& v = GetParam();
EXPECT_EQ( v.quick, isNFC_quick_check(v.input) );
if(v.yesno == -1) // needs deep test which is unimplemented, yet.
EXPECT_EQ( v.is_nfc, isNFC(v.input) );
EXPECT_EQ( v.nfc , toNFC(v.input) );
if(v.is_nfc)
{
EXPECT_THROW( isNFC( v.input ) , std::logic_error);
}else{
EXPECT_EQ( bool(v.yesno), isNFC( v.input ) );
EXPECT_EQ( v.input, toNFC(v.input) );
}
}

Loading…
Cancel
Save