Mercurial > libunicode
diff test/main.cpp @ 2:84765c6f4872
New style
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 02 Feb 2017 18:07:27 +0100 |
parents | 0d9603b420c2 |
children | 34a7a99dbcfa |
line wrap: on
line diff
--- a/test/main.cpp Mon Jan 02 20:43:34 2017 +0100 +++ b/test/main.cpp Thu Feb 02 18:07:27 2017 +0100 @@ -1,4 +1,4 @@ -/* +/* * main.cpp -- main test file for unicode * * Copyright (c) 2013-2017 David Demelier <markand@malikania.fr> @@ -31,11 +31,11 @@ * ------------------------------------------------------------------ */ -TEST(Conversion32to8, ascii) +TEST(conversion_32_to_8, ascii) { try { std::u32string u32{'a', 'b', 'c'}; - std::string s = unicode::toUtf8(u32); + std::string s = unicode::to_utf8(u32); ASSERT_EQ("abc", s); } catch (const std::exception &ex) { @@ -43,11 +43,11 @@ } } -TEST(Conversion32to8, valid) +TEST(conversion_32_to_8, valid) { try { std::u32string u32{'a', U'é', 'c', U'𠀀'}; - std::string s = unicode::toUtf8(u32); + std::string s = unicode::to_utf8(u32); std::string expected = u8"aéc𠀀"; ASSERT_EQ(expected, s); @@ -56,11 +56,11 @@ } } -TEST(Conversion32to8, invalid) +TEST(conversion_32_to_8, invalid) { std::u32string u32{'a', 0xFFFFFFFF, 'c'}; - ASSERT_ANY_THROW(unicode::toUtf8(u32)); + ASSERT_ANY_THROW(unicode::to_utf8(u32)); } /* @@ -68,12 +68,12 @@ * ------------------------------------------------------------------ */ -TEST(Conversion8to32, ascii) +TEST(Conversion_8_to_32, ascii) { try { std::string s{"abc"}; std::u32string expected{'a', 'b', 'c'}; - std::u32string result = unicode::toUtf32(s); + std::u32string result = unicode::to_utf32(s); ASSERT_EQ(expected, result); } catch (const std::exception &ex) { @@ -81,12 +81,12 @@ } } -TEST(Conversion8to32, valid) +TEST(Conversion_8_to_32, valid) { try { std::string s{u8"aéc𠀀"}; std::u32string expected{'a', U'é', 'c', U'𠀀'}; - std::u32string result = unicode::toUtf32(s); + std::u32string result = unicode::to_utf32(s); ASSERT_EQ(expected, result); } catch (const std::exception &ex) { @@ -99,7 +99,7 @@ * ------------------------------------------------------------------ */ -TEST(Toupper32, ascii) +TEST(toupper_32, ascii) { try { std::u32string u32{'a', 'b', 'c'}; @@ -112,7 +112,7 @@ } } -TEST(Toupper32, valid) +TEST(toupper_32, valid) { try { std::u32string u32{U'ä', U'ç', U'ë'}; @@ -125,7 +125,7 @@ } } -TEST(Toupper32, invalid) +TEST(toupper_32, invalid) { try { std::u32string u32{'a', 0xFFFFFFFF, 'b'}; @@ -143,7 +143,7 @@ * ------------------------------------------------------------------ */ -TEST(Tolower32, ascii) +TEST(tolower_32, ascii) { try { std::u32string u32{'A', 'B', 'C'}; @@ -156,7 +156,7 @@ } } -TEST(Tolower32, valid) +TEST(tolower_32, valid) { try { std::u32string u32{U'Ä', U'Ç', U'Ë'}; @@ -169,7 +169,7 @@ } } -TEST(Tolower32, invalid) +TEST(tolower_32, invalid) { try { std::u32string u32{'A', 0xFFFFFFFF, 'B'}; @@ -187,7 +187,7 @@ * ------------------------------------------------------------------ */ -TEST(Toupper8, ascii) +TEST(toupper_8, ascii) { try { std::string s{"abc"}; @@ -199,7 +199,7 @@ } } -TEST(Toupper8, valid) +TEST(toupper_8, valid) { try { std::string s{u8"aéc"}; @@ -211,7 +211,7 @@ } } -TEST(Toupper8, invalid) +TEST(toupper_8, invalid) { std::string s{"a" "\xFF""b"}; @@ -223,7 +223,7 @@ * ------------------------------------------------------------------ */ -TEST(Tolower8, ascii) +TEST(tolower_8, ascii) { try { std::string s{"ABC"}; @@ -235,7 +235,7 @@ } } -TEST(Tolower8, valid) +TEST(tolower_8, valid) { try { std::string s{u8"AÉC"}; @@ -247,7 +247,7 @@ } } -TEST(Tolower8, invalid) +TEST(tolower_8, invalid) { std::string s{"A" "\xFF""B"}; @@ -255,23 +255,23 @@ } /* - * Check functions + * Checks functions * ------------------------------------------------------------------ */ -TEST(Check, isspace) +TEST(checks, isspace) { ASSERT_TRUE(unicode::isspace(' ')); ASSERT_FALSE(unicode::isspace(/* é */ 233)); } -TEST(Check, isalpha) +TEST(checks, isalpha) { ASSERT_TRUE(unicode::isalpha(U'é')); ASSERT_FALSE(unicode::isalpha(U'€')); } -TEST(Check, isupper) +TEST(checks, isupper) { ASSERT_FALSE(unicode::isupper('a')); ASSERT_FALSE(unicode::isupper(U'é')); @@ -279,7 +279,7 @@ ASSERT_TRUE(unicode::isupper(U'É')); } -TEST(Check, islower) +TEST(checks, islower) { ASSERT_TRUE(unicode::islower('a')); ASSERT_TRUE(unicode::islower(U'é')); @@ -292,41 +292,42 @@ * ------------------------------------------------------------------ */ -TEST(Misc, nbytesPoint) +TEST(misc, nbytes_point) { - ASSERT_EQ(1, unicode::nbytesPoint('a')); - ASSERT_EQ(2, unicode::nbytesPoint(U'é')); - ASSERT_EQ(3, unicode::nbytesPoint(U'€')); - ASSERT_EQ(4, unicode::nbytesPoint(U'𠀀')); + ASSERT_EQ(1, unicode::nbytes_point('a')); + ASSERT_EQ(2, unicode::nbytes_point(U'é')); + ASSERT_EQ(3, unicode::nbytes_point(U'€')); + ASSERT_EQ(4, unicode::nbytes_point(U'𠀀')); } -TEST(Misc, nbytesUtf8) +TEST(misc, nbytes_utf8) { std::string s1{u8"a"}; std::string s2{u8"é"}; std::string s3{u8"€"}; std::string s4{u8"𠀀"}; - ASSERT_EQ(1, unicode::nbytesUtf8(s1[0])); - ASSERT_EQ(2, unicode::nbytesUtf8(s2[0])); - ASSERT_EQ(3, unicode::nbytesUtf8(s3[0])); - ASSERT_EQ(4, unicode::nbytesUtf8(s4[0])); + ASSERT_EQ(1, unicode::nbytes_utf8(s1[0])); + ASSERT_EQ(2, unicode::nbytes_utf8(s2[0])); + ASSERT_EQ(3, unicode::nbytes_utf8(s3[0])); + ASSERT_EQ(4, unicode::nbytes_utf8(s4[0])); } -TEST(Misc, forEach) +TEST(misc, for_each) { std::string s{u8"aé€𠀀"}; int current = 0; - unicode::forEach(s, [&] (char32_t code) { - if (current == 0) + unicode::for_each(s, [&] (char32_t code) { + if (current == 0) { ASSERT_EQ(U'a', code); - else if (current == 1) + } else if (current == 1) { ASSERT_EQ(U'é', code); - else if (current == 2) + } else if (current == 2) { ASSERT_EQ(U'€', code); - else if (current == 3) + } else if (current == 3) { ASSERT_EQ(U'𠀀', code); + } current++; }); @@ -334,14 +335,14 @@ ASSERT_EQ(4, current); } -TEST(Misc, forEachInvalid) +TEST(misc, for_each_invalid) { std::string s{"a" "\xFF" "b"}; - ASSERT_ANY_THROW(unicode::forEach(s, [&] (char32_t) { })); + ASSERT_ANY_THROW(unicode::for_each(s, [&] (char32_t) { })); } -int main(int argc, char **argv) +int main(int argc, char** argv) { InitGoogleTest(&argc, argv);