Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: content/renderer/hyphenator/hyphenator_unittest.cc

Issue 9545017: Adds a hy-phen-ator. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/hyphenator/hyphenator.cc ('k') | third_party/hyphen/README.chromium » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "content/renderer/hyphenator/hyphenator.h"
6
7 #include "base/path_service.h"
8 #include "base/platform_file.h"
9 #include "base/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/hyphen/hyphen.h"
12
13 // A unit test for our hyphenator. This class loads a sample hyphenation
14 // dictionary and hyphenates words.
15 class HyphenatorTest : public testing::Test {
16 public:
17 HyphenatorTest() {
18 Initialize();
19 }
20
21 bool Initialize() {
22 FilePath dictionary_path;
23 if (!PathService::Get(base::DIR_SOURCE_ROOT, &dictionary_path))
24 return false;
25 dictionary_path = dictionary_path.AppendASCII("third_party");
26 dictionary_path = dictionary_path.AppendASCII("hyphen");
27 dictionary_path = dictionary_path.AppendASCII("hyph_en_US.dic");
28 base::PlatformFile file = base::CreatePlatformFile(
29 dictionary_path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
30 NULL, NULL);
31 hyphenator_.reset(new content::Hyphenator(file));
32 return hyphenator_->Initialize();
33 }
34
35 // Creates a human-readable hyphenated word. This function inserts '-'
36 // characters to all places where we can insert hyphens to improve the
37 // readability of this unit test.
38 string16 Hyphenate(const string16& word) {
39 string16 hyphenated_word(word);
40 size_t position = word.length();
41 while (position > 0) {
42 size_t new_position = hyphenator_->ComputeLastHyphenLocation(word,
43 position);
44 EXPECT_LT(new_position, position);
45 if (new_position > 0)
46 hyphenated_word.insert(new_position, 1, '-');
47 position = new_position;
48 }
49 return hyphenated_word;
50 }
51
52 private:
53 scoped_ptr<content::Hyphenator> hyphenator_;
54 };
55
56 // Verifies that our hyphenator yields the same hyphenated words as the original
57 // hyphen library does.
58 TEST_F(HyphenatorTest, HyphenateWords) {
59 static const struct {
60 const char* input;
61 const char* expected;
62 } kTestCases[] = {
63 { "and", "and" },
64 { "concupiscent,", "con-cu-pis-cent," },
65 { "evidence.", "ev-i-dence." },
66 { "first", "first" },
67 { "getting", "get-ting" },
68 { "hedgehog", "hedge-hog" },
69 { "remarkable", "re-mark-able" },
70 { "straightened", "straight-ened" },
71 { "undid", "un-did" },
72 { "were", "were" },
73 { "Simply", "Sim-ply" },
74 { "Undone.", "Un-done." },
75 { "comfortably", "com-fort-ably"},
76 { "declination", "dec-li-na-tion" },
77 { "flamingo:", "flamin-go:" },
78 { "lination", "lina-tion" },
79 { "reciprocity", "rec-i-proc-i-ty" },
80 { "throughout", "through-out" },
81 { "undid", "un-did" },
82 { "undone.", "un-done." },
83 { "unnecessary", "un-nec-es-sary" },
84 };
85 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
86 string16 input = ASCIIToUTF16(kTestCases[i].input);
87 string16 expected = ASCIIToUTF16(kTestCases[i].expected);
88 EXPECT_EQ(expected, Hyphenate(input));
89 }
90 }
OLDNEW
« no previous file with comments | « content/renderer/hyphenator/hyphenator.cc ('k') | third_party/hyphen/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698