| 1 | #include <base/str.h> |
| 2 | |
| 3 | #include <game/client/components/censor.h> |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | static void Censor(const char *pInput, const char *pExpectedOutput, const std::vector<std::string> &vWords) |
| 8 | { |
| 9 | char aBuf[512]; |
| 10 | str_copy(dst&: aBuf, src: pInput); |
| 11 | CensorReplaceWords(pBuffer: aBuf, vWords, Replacement: '*'); |
| 12 | EXPECT_STREQ(aBuf, pExpectedOutput); |
| 13 | } |
| 14 | |
| 15 | TEST(ReplaceWords, Simple) |
| 16 | { |
| 17 | Censor(pInput: "hello" , pExpectedOutput: "*****" , vWords: {"hello" }); |
| 18 | Censor(pInput: "hello world" , pExpectedOutput: "hello *****" , vWords: {"world" }); |
| 19 | Censor(pInput: "foo bar baz" , pExpectedOutput: "*** *** ***" , vWords: {"baz" , "bar" , "foo" }); |
| 20 | } |
| 21 | |
| 22 | TEST(ReplaceWords, DISABLED_MissingBoundaries) |
| 23 | { |
| 24 | // TODO: not working yet |
| 25 | Censor(pInput: "foofoo" , pExpectedOutput: "******" , vWords: {"foo" }); |
| 26 | Censor(pInput: "you little foo!" , pExpectedOutput: "you little ***!" , vWords: {"foo" }); |
| 27 | Censor(pInput: "bаr" , pExpectedOutput: "***" , vWords: {"bar" }); // cyrillic a in input and latin a in censor |
| 28 | } |
| 29 | |
| 30 | TEST(ReplaceWords, DISABLED_Cyrillic) |
| 31 | { |
| 32 | // TODO: not working yet |
| 33 | // cyrillic a in input and latin a in censor |
| 34 | Censor(pInput: "bаr" , pExpectedOutput: "***" , vWords: {"bar" }); |
| 35 | } |
| 36 | |
| 37 | TEST(ReplaceWords, DISABLED_Spread) |
| 38 | { |
| 39 | // TODO: not working yet |
| 40 | Censor(pInput: "h,e,l,l,o" , pExpectedOutput: "*********" , vWords: {"hello" }); |
| 41 | Censor(pInput: "hell o" , pExpectedOutput: "******" , vWords: {"hello" }); |
| 42 | Censor(pInput: "h e l l o" , pExpectedOutput: "*********" , vWords: {"hello" }); |
| 43 | } |
| 44 | |