1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "third_party/blink/renderer/platform/wtf/text/text_codec_icu.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/blink/renderer/platform/wtf/text/character_names.h"
9 #include "third_party/blink/renderer/platform/wtf/vector.h"
10
11 namespace WTF {
12
TEST(TextCodecICUTest,IgnorableCodePoint)13 TEST(TextCodecICUTest, IgnorableCodePoint) {
14 TextEncoding iso2022jp("iso-2022-jp");
15 std::unique_ptr<TextCodec> codec = TextCodecICU::Create(iso2022jp, nullptr);
16 Vector<UChar> source;
17 source.push_back('a');
18 source.push_back(kZeroWidthJoinerCharacter);
19 std::string encoded =
20 codec->Encode(source.data(), source.size(), kEntitiesForUnencodables);
21 EXPECT_EQ("a‍", encoded);
22 const String source2(u"ABC~¤•★星星★•¤~XYZ");
23 const std::string encoded2(codec->Encode(source2.GetCharacters<UChar>(),
24 source2.length(),
25 kEntitiesForUnencodables));
26 const String source3(u"ABC~¤•★星🌟星★•¤~XYZ");
27 const std::string encoded3(codec->Encode(source3.GetCharacters<UChar>(),
28 source3.length(),
29 kEntitiesForUnencodables));
30 EXPECT_EQ(encoded3, encoded2);
31 EXPECT_EQ(
32 "ABC~¤•\x1B$B!z@1\x1B(B🌟\x1B$B@1!z\x1B(B•¤~"
33 "XYZ",
34 encoded2);
35 }
36 }
37