diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 14:55:02 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 14:55:02 +0000 |
commit | ed24f7a5588e96f5f675d62161d1c290c53c6558 (patch) | |
tree | 0538d67bfb37bb64f1d3c72bd9bb94c693279db2 /ui/gfx/text_utils_unittest.cc | |
parent | fb9a5e0628d306ac4d8d4ccdc82bd43c34dd6b04 (diff) | |
download | chromium_src-ed24f7a5588e96f5f675d62161d1c290c53c6558.zip chromium_src-ed24f7a5588e96f5f675d62161d1c290c53c6558.tar.gz chromium_src-ed24f7a5588e96f5f675d62161d1c290c53c6558.tar.bz2 |
ui/gfx: Extract RemoveAcceleratorChar() out of skia_util.*
This function has nothing to do with Skia, better to extract it into its own
module.
TEST=ui_unittests
R=asvitkine@chromium.org
TBR=sky@chromium.org # for gyp changes
Review URL: https://codereview.chromium.org/11364217
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167675 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/text_utils_unittest.cc')
-rw-r--r-- | ui/gfx/text_utils_unittest.cc | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/ui/gfx/text_utils_unittest.cc b/ui/gfx/text_utils_unittest.cc new file mode 100644 index 0000000..0b4aaad --- /dev/null +++ b/ui/gfx/text_utils_unittest.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/gfx/text_utils.h" + +#include "base/utf_string_conversions.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace gfx { +namespace { + +const char16 kAcceleratorChar = '&'; + +TEST(TextUtilsTest, RemoveAcceleratorChar) { + struct TestData { + const char* input; + int accelerated_char_pos; + int accelerated_char_span; + const char* output; + } cases[] = { + { "", -1, 0, "" }, + { "&", -1, 0, "" }, + { "no accelerator", -1, 0, "no accelerator" }, + { "&one accelerator", 0, 1, "one accelerator" }, + { "one &accelerator", 4, 1, "one accelerator" }, + { "one_accelerator&", -1, 0, "one_accelerator" }, + { "&two &accelerators", 4, 1, "two accelerators" }, + { "two &accelerators&", 4, 1, "two accelerators" }, + { "two& &accelerators", 4, 1, "two accelerators" }, + { "&&escaping", -1, 0, "&escaping" }, + { "escap&&ing", -1, 0, "escap&ing" }, + { "escaping&&", -1, 0, "escaping&" }, + { "&mix&&ed", 0, 1, "mix&ed" }, + { "&&m&ix&&e&d&", 6, 1, "&mix&ed" }, + { "&&m&&ix&ed&&", 5, 1, "&m&ixed&" }, + { "&m&&ix&ed&&", 4, 1, "m&ixed&" }, + // U+1D49C MATHEMATICAL SCRIPT CAPITAL A, which occupies two |char16|'s. + { "&\xF0\x9D\x92\x9C", 0, 2, "\xF0\x9D\x92\x9C" }, + { "Test&\xF0\x9D\x92\x9Cing", 4, 2, "Test\xF0\x9D\x92\x9Cing" }, + { "Test\xF0\x9D\x92\x9C&ing", 6, 1, "Test\xF0\x9D\x92\x9Cing" }, + { "Test&\xF0\x9D\x92\x9C&ing", 6, 1, "Test\xF0\x9D\x92\x9Cing" }, + { "Test&\xF0\x9D\x92\x9C&&ing", 4, 2, "Test\xF0\x9D\x92\x9C&ing" }, + { "Test&\xF0\x9D\x92\x9C&\xF0\x9D\x92\x9Cing", 6, 2, + "Test\xF0\x9D\x92\x9C\xF0\x9D\x92\x9Cing" }, + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { + int accelerated_char_pos; + int accelerated_char_span; + string16 result = RemoveAcceleratorChar(UTF8ToUTF16(cases[i].input), + kAcceleratorChar, + &accelerated_char_pos, + &accelerated_char_span); + EXPECT_EQ(result, UTF8ToUTF16(cases[i].output)); + EXPECT_EQ(accelerated_char_pos, cases[i].accelerated_char_pos); + EXPECT_EQ(accelerated_char_span, cases[i].accelerated_char_span); + } +} + +} // namespace +} // namespace gfx |