mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-14 03:58:18 +00:00
23 lines
797 B
C++
23 lines
797 B
C++
#include <gtest/gtest.h>
|
|
|
|
#include <engine/shared/json.h>
|
|
|
|
TEST(Json, Escape)
|
|
{
|
|
char aBuf[128];
|
|
char aSmall[2];
|
|
char aSix[6];
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), ""), "");
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "a"), "a");
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "\n"), "\\n");
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "\\"), "\\\\"); // https://www.xkcd.com/1638/
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "\x1b"), "\\u001b"); // escape
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "愛"), "愛");
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "😂"), "😂");
|
|
|
|
// Truncations
|
|
EXPECT_STREQ(EscapeJson(aSmall, sizeof(aSmall), "\\"), "");
|
|
EXPECT_STREQ(EscapeJson(aSix, sizeof(aSix), "\x01"), "");
|
|
EXPECT_STREQ(EscapeJson(aSix, sizeof(aSix), "aaaaaa"), "aaaaa");
|
|
}
|