File: Utf8Test.cpp

package info (click to toggle)
antlr4-cpp-runtime 4.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,988 kB
  • sloc: cpp: 15,909; sh: 31; makefile: 20
file content (110 lines) | stat: -rw-r--r-- 4,769 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <string>
#include <string_view>

#include "gtest/gtest.h"
#include "support/Utf8.h"

namespace antlrcpp {
namespace {

  struct Utf8EncodeTestCase final {
    char32_t code_point;
    std::string_view code_units;
  };

  using Utf8EncodeTest = testing::TestWithParam<Utf8EncodeTestCase>;

  TEST_P(Utf8EncodeTest, Compliance) {
    const Utf8EncodeTestCase& test_case = GetParam();
    std::string result;
    EXPECT_EQ(Utf8::encode(&result, test_case.code_point), test_case.code_units);
  }

  INSTANTIATE_TEST_SUITE_P(Utf8EncodeTest, Utf8EncodeTest,
                          testing::ValuesIn<Utf8EncodeTestCase>({
                              {0x0000, std::string_view("\x00", 1)},
                              {0x0001, "\x01"},
                              {0x007e, "\x7e"},
                              {0x007f, "\x7f"},
                              {0x0080, "\xc2\x80"},
                              {0x0081, "\xc2\x81"},
                              {0x00bf, "\xc2\xbf"},
                              {0x00c0, "\xc3\x80"},
                              {0x00c1, "\xc3\x81"},
                              {0x00c8, "\xc3\x88"},
                              {0x00d0, "\xc3\x90"},
                              {0x00e0, "\xc3\xa0"},
                              {0x00f0, "\xc3\xb0"},
                              {0x00f8, "\xc3\xb8"},
                              {0x00ff, "\xc3\xbf"},
                              {0x0100, "\xc4\x80"},
                              {0x07ff, "\xdf\xbf"},
                              {0x0400, "\xd0\x80"},
                              {0x0800, "\xe0\xa0\x80"},
                              {0x0801, "\xe0\xa0\x81"},
                              {0x1000, "\xe1\x80\x80"},
                              {0xd000, "\xed\x80\x80"},
                              {0xd7ff, "\xed\x9f\xbf"},
                              {0xe000, "\xee\x80\x80"},
                              {0xfffe, "\xef\xbf\xbe"},
                              {0xffff, "\xef\xbf\xbf"},
                              {0x10000, "\xf0\x90\x80\x80"},
                              {0x10001, "\xf0\x90\x80\x81"},
                              {0x40000, "\xf1\x80\x80\x80"},
                              {0x10fffe, "\xf4\x8f\xbf\xbe"},
                              {0x10ffff, "\xf4\x8f\xbf\xbf"},
                              {0xFFFD, "\xef\xbf\xbd"},
                          }));

  struct Utf8DecodeTestCase final {
    char32_t code_point;
    std::string_view code_units;
  };

  using Utf8DecodeTest = testing::TestWithParam<Utf8DecodeTestCase>;

  TEST_P(Utf8DecodeTest, Compliance) {
    const Utf8DecodeTestCase& test_case = GetParam();
    auto [code_point, code_units] = Utf8::decode(test_case.code_units);
    EXPECT_EQ(code_units, test_case.code_units.size());
    EXPECT_EQ(code_point, test_case.code_point);
  }

  INSTANTIATE_TEST_SUITE_P(Utf8DecodeTest, Utf8DecodeTest,
                          testing::ValuesIn<Utf8DecodeTestCase>({
                              {0x0000, std::string_view("\x00", 1)},
                              {0x0001, "\x01"},
                              {0x007e, "\x7e"},
                              {0x007f, "\x7f"},
                              {0x0080, "\xc2\x80"},
                              {0x0081, "\xc2\x81"},
                              {0x00bf, "\xc2\xbf"},
                              {0x00c0, "\xc3\x80"},
                              {0x00c1, "\xc3\x81"},
                              {0x00c8, "\xc3\x88"},
                              {0x00d0, "\xc3\x90"},
                              {0x00e0, "\xc3\xa0"},
                              {0x00f0, "\xc3\xb0"},
                              {0x00f8, "\xc3\xb8"},
                              {0x00ff, "\xc3\xbf"},
                              {0x0100, "\xc4\x80"},
                              {0x07ff, "\xdf\xbf"},
                              {0x0400, "\xd0\x80"},
                              {0x0800, "\xe0\xa0\x80"},
                              {0x0801, "\xe0\xa0\x81"},
                              {0x1000, "\xe1\x80\x80"},
                              {0xd000, "\xed\x80\x80"},
                              {0xd7ff, "\xed\x9f\xbf"},
                              {0xe000, "\xee\x80\x80"},
                              {0xfffe, "\xef\xbf\xbe"},
                              {0xffff, "\xef\xbf\xbf"},
                              {0x10000, "\xf0\x90\x80\x80"},
                              {0x10001, "\xf0\x90\x80\x81"},
                              {0x40000, "\xf1\x80\x80\x80"},
                              {0x10fffe, "\xf4\x8f\xbf\xbe"},
                              {0x10ffff, "\xf4\x8f\xbf\xbf"},
                              {0xFFFD, "\xef\xbf\xbd"},
                          }));

}
}