xref: /aosp_15_r20/external/pdfium/core/fxcrt/widetext_buffer_unittest.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2018 The PDFium Authors
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 "core/fxcrt/widetext_buffer.h"
6 
7 #include <utility>
8 
9 #include "testing/gtest/include/gtest/gtest.h"
10 
11 namespace fxcrt {
12 
TEST(WideTextBuffer,EmptyBuf)13 TEST(WideTextBuffer, EmptyBuf) {
14   WideTextBuffer wtb;
15   EXPECT_TRUE(wtb.GetWideSpan().empty());
16   EXPECT_TRUE(wtb.AsStringView().IsEmpty());
17   EXPECT_TRUE(wtb.MakeString().IsEmpty());
18 }
19 
TEST(WideTextBuffer,OperatorLtLt)20 TEST(WideTextBuffer, OperatorLtLt) {
21   WideTextBuffer wtb;
22   wtb << "clams" << L"\u208c\u208e";
23   EXPECT_EQ(wtb.MakeString(), L"clams\u208c\u208e");
24 }
25 
TEST(WideTextBuffer,Deletion)26 TEST(WideTextBuffer, Deletion) {
27   WideTextBuffer wtb;
28   wtb << L"ABCDEFG";
29   EXPECT_TRUE(wtb.AsStringView().EqualsASCII("ABCDEFG"));
30 
31   wtb.Delete(1, 3);
32   EXPECT_TRUE(wtb.AsStringView().EqualsASCII("AEFG"));
33 
34   wtb.Delete(1, 0);
35   EXPECT_TRUE(wtb.AsStringView().EqualsASCII("AEFG"));
36 
37   wtb.Delete(0, 2);
38   EXPECT_TRUE(wtb.AsStringView().EqualsASCII("FG"));
39 
40   wtb.Delete(0, 2);
41   EXPECT_TRUE(wtb.AsStringView().EqualsASCII(""));
42 
43   wtb.Delete(0, 0);
44   EXPECT_TRUE(wtb.AsStringView().EqualsASCII(""));
45 }
46 
TEST(WideTextBuffer,Move)47 TEST(WideTextBuffer, Move) {
48   WideTextBuffer wtb;
49   wtb << "clams";
50   EXPECT_EQ(wtb.MakeString(), L"clams");
51 
52   WideTextBuffer wtb2(std::move(wtb));
53   EXPECT_EQ(wtb.MakeString(), L"");
54   EXPECT_EQ(wtb2.MakeString(), L"clams");
55 
56   WideTextBuffer wtb3;
57   wtb3 = std::move(wtb2);
58   EXPECT_EQ(wtb2.MakeString(), L"");
59   EXPECT_EQ(wtb3.MakeString(), L"clams");
60 }
61 
62 }  // namespace fxcrt
63