mirror of
https://github.com/DanielSWolf/rhubarb-lip-sync.git
synced 2026-11-21 12:25:08 +00:00
Made entire application Unicode-aware
All 8-bit strings are UTF-8-encoded now.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "tokenization.h"
|
||||
#include <regex>
|
||||
#include <unordered_set>
|
||||
#include <utf8.h>
|
||||
|
||||
using namespace testing;
|
||||
using std::string;
|
||||
@@ -14,57 +15,64 @@ bool returnTrue(const string&) {
|
||||
}
|
||||
|
||||
TEST(tokenizeText, simpleCases) {
|
||||
EXPECT_THAT(tokenizeText(U"", returnTrue), IsEmpty());
|
||||
EXPECT_THAT(tokenizeText(U" \t\n\r\n ", returnTrue), IsEmpty());
|
||||
EXPECT_THAT(tokenizeText("", returnTrue), IsEmpty());
|
||||
EXPECT_THAT(tokenizeText(" \t\n\r\n ", returnTrue), IsEmpty());
|
||||
EXPECT_THAT(
|
||||
tokenizeText(U"Wit is educated insolence.", returnTrue),
|
||||
tokenizeText("Wit is educated insolence.", returnTrue),
|
||||
ElementsAre("wit", "is", "educated", "insolence")
|
||||
);
|
||||
}
|
||||
|
||||
TEST(tokenizeText, numbers) {
|
||||
EXPECT_THAT(
|
||||
tokenizeText(U"Henry V died at 36.", returnTrue),
|
||||
tokenizeText("Henry V died at 36.", returnTrue),
|
||||
ElementsAre("henry", "the", "fifth", "died", "at", "thirty", "six")
|
||||
);
|
||||
EXPECT_THAT(
|
||||
tokenizeText(U"I spent $4.50 on gum.", returnTrue),
|
||||
tokenizeText("I spent $4.50 on gum.", returnTrue),
|
||||
ElementsAre("i", "spent", "four", "dollars", "fifty", "cents", "on", "gum")
|
||||
);
|
||||
EXPECT_THAT(
|
||||
tokenizeText(U"I was born in 1982.", returnTrue),
|
||||
tokenizeText("I was born in 1982.", returnTrue),
|
||||
ElementsAre("i", "was", "born", "in", "nineteen", "eighty", "two")
|
||||
);
|
||||
}
|
||||
|
||||
TEST(tokenizeText, abbreviations) {
|
||||
EXPECT_THAT(
|
||||
tokenizeText(U"Prof. Foo lives on Dr. Dolittle Dr.", [](const string& word) { return word == "prof."; }),
|
||||
tokenizeText("Prof. Foo lives on Dr. Dolittle Dr.", [](const string& word) { return word == "prof."; }),
|
||||
ElementsAre("prof.", "foo", "lives", "on", "doctor", "dolittle", "drive")
|
||||
);
|
||||
}
|
||||
|
||||
TEST(tokenizeText, apostrophes) {
|
||||
EXPECT_THAT(
|
||||
tokenizeText(U"'Tis said he'd wish'd for a 'bus 'cause he wouldn't walk.", [](const string& word) { return word == "wouldn't"; }),
|
||||
tokenizeText("'Tis said he'd wish'd for a 'bus 'cause he wouldn't walk.", [](const string& word) { return word == "wouldn't"; }),
|
||||
ElementsAreArray(vector<string>{ "tis", "said", "he'd", "wish'd", "for", "a", "bus", "cause", "he", "wouldn't", "walk" })
|
||||
);
|
||||
}
|
||||
|
||||
TEST(tokenizeText, math) {
|
||||
EXPECT_THAT(
|
||||
tokenizeText(U"'1+2*3=7", returnTrue),
|
||||
tokenizeText("'1+2*3=7", returnTrue),
|
||||
ElementsAre("one", "plus", "two", "times", "three", "equals", "seven")
|
||||
);
|
||||
}
|
||||
|
||||
TEST(tokenizeText, unicodeCharacters) {
|
||||
EXPECT_THAT(
|
||||
tokenizeText("A naïve man called 晨 had piña colada and crème brûlée.", returnTrue),
|
||||
ElementsAre("a", "naive", "man", "called", "had", "pina", "colada", "and", "creme", "brulee")
|
||||
);
|
||||
}
|
||||
|
||||
// Checks that each word contains only the characters a-z and the apostrophe
|
||||
TEST(tokenizeText, wordsUseLimitedCharacters) {
|
||||
// Create string containing lots of undesirable characters
|
||||
u32string input = U"A naïve man called 晨 was having piña colada and crème brûlée.";
|
||||
string input = "A naïve man called 晨 was having piña colada and crème brûlée.";
|
||||
for (char32_t c = 0; c <= 1000; ++c) {
|
||||
input.append(U" ");
|
||||
input.append(1, c);
|
||||
input.append(" ");
|
||||
utf8::append(c, back_inserter(input));
|
||||
}
|
||||
|
||||
regex legal("^[a-z']+$");
|
||||
|
||||
Reference in New Issue
Block a user