1 // Copyright 2010-2018, Google Inc.
2 // 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 #include "composer/internal/converter.h"
31
32 #include <string>
33
34 #include "composer/table.h"
35 #include "testing/base/public/gunit.h"
36
37 namespace mozc {
38 namespace {
39
InitTable(mozc::composer::Table * table)40 void InitTable(mozc::composer::Table* table) {
41 table->AddRule("a", "あ", "");
42 table->AddRule("i", "い", "");
43 table->AddRule("ka", "か", "");
44 table->AddRule("ki", "き", "");
45 table->AddRule("ku", "く", "");
46 table->AddRule("ke", "け", "");
47 table->AddRule("ko", "こ", "");
48 table->AddRule("kk", "っ", "k");
49 table->AddRule("na", "な", "");
50 table->AddRule("ni", "に", "");
51 table->AddRule("n", "ん", "");
52 table->AddRule("nn", "ん", "");
53 }
54
TEST(ConverterTest,Converter)55 TEST(ConverterTest, Converter) {
56 static const struct TestCase {
57 const char *input;
58 const char *expected_output;
59 } test_cases[] = {
60 { "a", "あ" },
61 { "ka", "か" },
62 { "ki", "き" },
63 { "ku", "く" },
64 { "kk", "っk" },
65 { "aka", "あか" },
66 { "kakizkka", "かきzっか" },
67 { "nankanai?", "なんかない?" },
68 { "nannkanain?", "なんかないん?" },
69 { "nannkanain", "なんかないん" },
70 };
71 static const int size = arraysize(test_cases);
72
73 mozc::composer::Table table;
74 InitTable(&table);
75 mozc::composer::Converter converter(table);
76
77 for (int i = 0; i < size; ++i) {
78 const TestCase &test = test_cases[i];
79 string output;
80 converter.Convert(test.input, &output);
81 EXPECT_EQ(test.expected_output, output);
82 }
83 }
84
85 } // namespace
86 } // namespace mozc
87