Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/i18n/char_iterator.h" | 5 #include "base/i18n/char_iterator.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 TEST(CharIteratorsTest, TestUTF8) { | 10 TEST(CharIteratorsTest, TestUTF8) { |
| 11 std::string empty(""); | 11 std::string empty(""); |
| 12 base::UTF8CharIterator empty_iter(&empty); | 12 base::i18n::UTF8CharIterator empty_iter(&empty); |
|
brettw
2011/01/18 18:36:10
I'd just put this entire file in the base::i18n na
tfarina
2011/01/18 18:42:04
Done.
| |
| 13 ASSERT_TRUE(empty_iter.end()); | 13 ASSERT_TRUE(empty_iter.end()); |
| 14 ASSERT_EQ(0, empty_iter.array_pos()); | 14 ASSERT_EQ(0, empty_iter.array_pos()); |
| 15 ASSERT_EQ(0, empty_iter.char_pos()); | 15 ASSERT_EQ(0, empty_iter.char_pos()); |
| 16 ASSERT_FALSE(empty_iter.Advance()); | 16 ASSERT_FALSE(empty_iter.Advance()); |
| 17 | 17 |
| 18 std::string str("s\303\273r"); // [u with circumflex] | 18 std::string str("s\303\273r"); // [u with circumflex] |
| 19 base::UTF8CharIterator iter(&str); | 19 base::i18n::UTF8CharIterator iter(&str); |
| 20 ASSERT_FALSE(iter.end()); | 20 ASSERT_FALSE(iter.end()); |
| 21 ASSERT_EQ(0, iter.array_pos()); | 21 ASSERT_EQ(0, iter.array_pos()); |
| 22 ASSERT_EQ(0, iter.char_pos()); | 22 ASSERT_EQ(0, iter.char_pos()); |
| 23 ASSERT_EQ('s', iter.get()); | 23 ASSERT_EQ('s', iter.get()); |
| 24 ASSERT_TRUE(iter.Advance()); | 24 ASSERT_TRUE(iter.Advance()); |
| 25 | 25 |
| 26 ASSERT_FALSE(iter.end()); | 26 ASSERT_FALSE(iter.end()); |
| 27 ASSERT_EQ(1, iter.array_pos()); | 27 ASSERT_EQ(1, iter.array_pos()); |
| 28 ASSERT_EQ(1, iter.char_pos()); | 28 ASSERT_EQ(1, iter.char_pos()); |
| 29 ASSERT_EQ(251, iter.get()); | 29 ASSERT_EQ(251, iter.get()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 40 ASSERT_EQ(3, iter.char_pos()); | 40 ASSERT_EQ(3, iter.char_pos()); |
| 41 | 41 |
| 42 // Don't care what it returns, but this shouldn't crash | 42 // Don't care what it returns, but this shouldn't crash |
| 43 iter.get(); | 43 iter.get(); |
| 44 | 44 |
| 45 ASSERT_FALSE(iter.Advance()); | 45 ASSERT_FALSE(iter.Advance()); |
| 46 } | 46 } |
| 47 | 47 |
| 48 TEST(CharIteratorsTest, TestUTF16) { | 48 TEST(CharIteratorsTest, TestUTF16) { |
| 49 string16 empty = UTF8ToUTF16(""); | 49 string16 empty = UTF8ToUTF16(""); |
| 50 base::UTF16CharIterator empty_iter(&empty); | 50 base::i18n::UTF16CharIterator empty_iter(&empty); |
| 51 ASSERT_TRUE(empty_iter.end()); | 51 ASSERT_TRUE(empty_iter.end()); |
| 52 ASSERT_EQ(0, empty_iter.array_pos()); | 52 ASSERT_EQ(0, empty_iter.array_pos()); |
| 53 ASSERT_EQ(0, empty_iter.char_pos()); | 53 ASSERT_EQ(0, empty_iter.char_pos()); |
| 54 ASSERT_FALSE(empty_iter.Advance()); | 54 ASSERT_FALSE(empty_iter.Advance()); |
| 55 | 55 |
| 56 // This test string contains 4 characters: | 56 // This test string contains 4 characters: |
| 57 // x | 57 // x |
| 58 // u with circumflex - 2 bytes in UTF8, 1 codeword in UTF16 | 58 // u with circumflex - 2 bytes in UTF8, 1 codeword in UTF16 |
| 59 // math double-struck A - 4 bytes in UTF8, 2 codewords in UTF16 | 59 // math double-struck A - 4 bytes in UTF8, 2 codewords in UTF16 |
| 60 // z | 60 // z |
| 61 string16 str = UTF8ToUTF16("x\303\273\360\235\224\270z"); | 61 string16 str = UTF8ToUTF16("x\303\273\360\235\224\270z"); |
| 62 base::UTF16CharIterator iter(&str); | 62 base::i18n::UTF16CharIterator iter(&str); |
| 63 ASSERT_FALSE(iter.end()); | 63 ASSERT_FALSE(iter.end()); |
| 64 ASSERT_EQ(0, iter.array_pos()); | 64 ASSERT_EQ(0, iter.array_pos()); |
| 65 ASSERT_EQ(0, iter.char_pos()); | 65 ASSERT_EQ(0, iter.char_pos()); |
| 66 ASSERT_EQ('x', iter.get()); | 66 ASSERT_EQ('x', iter.get()); |
| 67 ASSERT_TRUE(iter.Advance()); | 67 ASSERT_TRUE(iter.Advance()); |
| 68 | 68 |
| 69 ASSERT_FALSE(iter.end()); | 69 ASSERT_FALSE(iter.end()); |
| 70 ASSERT_EQ(1, iter.array_pos()); | 70 ASSERT_EQ(1, iter.array_pos()); |
| 71 ASSERT_EQ(1, iter.char_pos()); | 71 ASSERT_EQ(1, iter.char_pos()); |
| 72 ASSERT_EQ(251, iter.get()); | 72 ASSERT_EQ(251, iter.get()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 86 | 86 |
| 87 ASSERT_TRUE(iter.end()); | 87 ASSERT_TRUE(iter.end()); |
| 88 ASSERT_EQ(5, iter.array_pos()); | 88 ASSERT_EQ(5, iter.array_pos()); |
| 89 ASSERT_EQ(4, iter.char_pos()); | 89 ASSERT_EQ(4, iter.char_pos()); |
| 90 | 90 |
| 91 // Don't care what it returns, but this shouldn't crash | 91 // Don't care what it returns, but this shouldn't crash |
| 92 iter.get(); | 92 iter.get(); |
| 93 | 93 |
| 94 ASSERT_FALSE(iter.Advance()); | 94 ASSERT_FALSE(iter.Advance()); |
| 95 } | 95 } |
| OLD | NEW |