1#include <gtest/gtest.h>
2
3#include <engine/shared/json.h>
4
5TEST(Json, Escape)
6{
7 char aBuf[128];
8 char aSmall[2];
9 char aSix[6];
10 EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), ""), "");
11 EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "a"), "a");
12 EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "\n"), "\\n");
13 EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "\\"), "\\\\"); // https://www.xkcd.com/1638/
14 EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "\x1b"), "\\u001b"); // escape
15 EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "愛"), "愛");
16 EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "😂"), "😂");
17
18 // Truncations
19 EXPECT_STREQ(EscapeJson(aSmall, sizeof(aSmall), "\\"), "");
20 EXPECT_STREQ(EscapeJson(aSix, sizeof(aSix), "\x01"), "");
21 EXPECT_STREQ(EscapeJson(aSix, sizeof(aSix), "aaaaaa"), "aaaaa");
22}
23