1/*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "config.h"
32#include "platform/text/SegmentedString.h"
33
34#include <gtest/gtest.h>
35
36using blink::SegmentedString;
37
38namespace {
39
40TEST(SegmentedStringTest, CurrentChar)
41{
42    SegmentedString original(String("cde"));
43    {
44        SegmentedString copied(original);
45        SegmentedString assigned;
46        assigned = original;
47        EXPECT_EQ("cde", original.toString());
48        EXPECT_EQ('c', original.currentChar());
49        EXPECT_EQ('c', copied.currentChar());
50        EXPECT_EQ('c', assigned.currentChar());
51    }
52    original.push('a');
53    {
54        SegmentedString copied(original);
55        SegmentedString assigned;
56        assigned = original;
57        EXPECT_EQ("acde", original.toString());
58        EXPECT_EQ('a', original.currentChar());
59        EXPECT_EQ('a', copied.currentChar());
60        EXPECT_EQ('a', assigned.currentChar());
61    }
62    original.push('b');
63    {
64        // Two consecutive push means to push the second char *after* the
65        // first char in SegmentedString.
66        SegmentedString copied(original);
67        SegmentedString assigned;
68        assigned = original;
69        EXPECT_EQ("abcde", original.toString());
70        EXPECT_EQ('a', original.currentChar());
71        EXPECT_EQ('a', copied.currentChar());
72        EXPECT_EQ('a', assigned.currentChar());
73    }
74    original.advance();
75    {
76        SegmentedString copied(original);
77        SegmentedString assigned;
78        assigned = original;
79        EXPECT_EQ("bcde", original.toString());
80        EXPECT_EQ('b', original.currentChar());
81        EXPECT_EQ('b', copied.currentChar());
82        EXPECT_EQ('b', assigned.currentChar());
83    }
84}
85
86} // namespace
87