1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include "pcdata.h"
#include <library/cpp/testing/unittest/registar.h>
Y_UNIT_TEST_SUITE(TPcdata) {
Y_UNIT_TEST(TestStress) {
{
ui64 key = 0x000017C0B76C4E87ull;
TString res = EncodeHtmlPcdata(TStringBuf((const char*)&key, sizeof(key)));
}
for (size_t i = 0; i < 1000; ++i) {
const TString s = NUnitTest::RandomString(i, i);
UNIT_ASSERT_VALUES_EQUAL(DecodeHtmlPcdata(EncodeHtmlPcdata(s)), s);
}
}
Y_UNIT_TEST(Test1) {
const TString tests[] = {
"qw&qw",
"&<",
">&qw",
"\'&aaa"};
for (auto s : tests) {
UNIT_ASSERT_VALUES_EQUAL(DecodeHtmlPcdata(EncodeHtmlPcdata(s)), s);
}
}
Y_UNIT_TEST(Test2) {
UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("&qqq"), "&qqq");
}
Y_UNIT_TEST(TestEncodeHtmlPcdataAppend) {
TString s;
EncodeHtmlPcdataAppend("m&m", s);
EncodeHtmlPcdataAppend("'s", s);
UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's"), s);
UNIT_ASSERT_VALUES_EQUAL("m&m's", s);
}
Y_UNIT_TEST(TestStrangeAmpParameter) {
UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's", true), "m&m's");
UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's"), "m&m's"); //default
UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's", false), "m&m's");
}
}
|