- add sources.
[platform/framework/web/crosswalk.git] / src / ui / gfx / text_utils_unittest.cc
1 // Copyright (c) 2011 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 "ui/gfx/text_utils.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace gfx {
11 namespace {
12
13 const char16 kAcceleratorChar = '&';
14
15 TEST(TextUtilsTest, RemoveAcceleratorChar) {
16   struct TestData {
17     const char* input;
18     int accelerated_char_pos;
19     int accelerated_char_span;
20     const char* output;
21   } cases[] = {
22     { "", -1, 0, "" },
23     { "&", -1, 0, "" },
24     { "no accelerator", -1, 0, "no accelerator" },
25     { "&one accelerator", 0, 1, "one accelerator" },
26     { "one &accelerator", 4, 1, "one accelerator" },
27     { "one_accelerator&", -1, 0, "one_accelerator" },
28     { "&two &accelerators", 4, 1, "two accelerators" },
29     { "two &accelerators&", 4, 1, "two accelerators" },
30     { "two& &accelerators", 4, 1, "two accelerators" },
31     { "&&escaping", -1, 0, "&escaping" },
32     { "escap&&ing", -1, 0, "escap&ing" },
33     { "escaping&&", -1, 0, "escaping&" },
34     { "&mix&&ed", 0, 1, "mix&ed" },
35     { "&&m&ix&&e&d&", 6, 1, "&mix&ed" },
36     { "&&m&&ix&ed&&", 5, 1, "&m&ixed&" },
37     { "&m&&ix&ed&&", 4, 1, "m&ixed&" },
38     // U+1D49C MATHEMATICAL SCRIPT CAPITAL A, which occupies two |char16|'s.
39     { "&\xF0\x9D\x92\x9C", 0, 2, "\xF0\x9D\x92\x9C" },
40     { "Test&\xF0\x9D\x92\x9Cing", 4, 2, "Test\xF0\x9D\x92\x9Cing" },
41     { "Test\xF0\x9D\x92\x9C&ing", 6, 1, "Test\xF0\x9D\x92\x9Cing" },
42     { "Test&\xF0\x9D\x92\x9C&ing", 6, 1, "Test\xF0\x9D\x92\x9Cing" },
43     { "Test&\xF0\x9D\x92\x9C&&ing", 4, 2, "Test\xF0\x9D\x92\x9C&ing" },
44     { "Test&\xF0\x9D\x92\x9C&\xF0\x9D\x92\x9Cing", 6, 2,
45       "Test\xF0\x9D\x92\x9C\xF0\x9D\x92\x9Cing" },
46   };
47
48   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
49     int accelerated_char_pos;
50     int accelerated_char_span;
51     base::string16 result = RemoveAcceleratorChar(UTF8ToUTF16(cases[i].input),
52                                                   kAcceleratorChar,
53                                                   &accelerated_char_pos,
54                                                   &accelerated_char_span);
55     EXPECT_EQ(result, UTF8ToUTF16(cases[i].output));
56     EXPECT_EQ(accelerated_char_pos, cases[i].accelerated_char_pos);
57     EXPECT_EQ(accelerated_char_span, cases[i].accelerated_char_span);
58   }
59 }
60
61 }  // namespace
62 }  // namespace gfx