1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.ActiveRecord
.Framework
.Internal
.Tests
17 using System
.Collections
;
18 using NUnit
.Framework
;
21 public class InflectorTestCase
25 private static readonly Hashtable singularToPlural
= new Hashtable();
28 public void SetupTestData()
30 singularToPlural
.Add("search", "searches");
31 singularToPlural
.Add("switch", "switches");
32 singularToPlural
.Add("fix", "fixes");
33 singularToPlural
.Add("box", "boxes");
34 singularToPlural
.Add("process", "processes");
35 singularToPlural
.Add("address", "addresses");
36 singularToPlural
.Add("case", "cases");
37 singularToPlural
.Add("stack", "stacks");
38 singularToPlural
.Add("wish", "wishes");
39 singularToPlural
.Add("fish", "fish");
41 singularToPlural
.Add("category", "categories");
42 singularToPlural
.Add("query", "queries");
43 singularToPlural
.Add("ability", "abilities");
44 singularToPlural
.Add("agency", "agencies");
45 singularToPlural
.Add("movie", "movies");
47 singularToPlural
.Add("archive", "archives");
49 singularToPlural
.Add("index", "indices");
51 singularToPlural
.Add("wife", "wives");
52 singularToPlural
.Add("safe", "saves");
53 singularToPlural
.Add("half", "halves");
55 singularToPlural
.Add("move", "moves");
57 singularToPlural
.Add("salesperson", "salespeople");
58 singularToPlural
.Add("person", "people");
60 singularToPlural
.Add("spokesman", "spokesmen");
61 singularToPlural
.Add("man", "men");
62 singularToPlural
.Add("woman", "women");
64 singularToPlural
.Add("basis", "bases");
65 singularToPlural
.Add("diagnosis", "diagnoses");
67 singularToPlural
.Add("datum", "data");
68 singularToPlural
.Add("medium", "media");
69 singularToPlural
.Add("analysis", "analyses");
71 singularToPlural
.Add("node_child", "node_children");
72 singularToPlural
.Add("child", "children");
74 singularToPlural
.Add("experience", "experiences");
75 singularToPlural
.Add("day", "days");
77 singularToPlural
.Add("comment", "comments");
78 singularToPlural
.Add("foobar", "foobars");
79 singularToPlural
.Add("newsletter", "newsletters");
81 singularToPlural
.Add("old_news", "old_news");
82 singularToPlural
.Add("news", "news");
84 singularToPlural
.Add("series", "series");
85 singularToPlural
.Add("species", "species");
87 singularToPlural
.Add("quiz", "quizzes");
89 singularToPlural
.Add("perspective", "perspectives");
91 singularToPlural
.Add("ox", "oxen");
92 singularToPlural
.Add("photo", "photos");
93 singularToPlural
.Add("buffalo", "buffaloes");
94 singularToPlural
.Add("tomato", "tomatoes");
95 singularToPlural
.Add("dwarf", "dwarves");
96 singularToPlural
.Add("elf", "elves");
97 singularToPlural
.Add("information", "information");
98 singularToPlural
.Add("equipment", "equipment");
99 singularToPlural
.Add("bus", "buses");
100 singularToPlural
.Add("status", "statuses");
101 singularToPlural
.Add("status_code", "status_codes");
102 singularToPlural
.Add("mouse", "mice");
104 singularToPlural
.Add("louse", "lice");
105 singularToPlural
.Add("house", "houses");
106 singularToPlural
.Add("octopus", "octopi");
107 singularToPlural
.Add("virus", "viri");
108 singularToPlural
.Add("alias", "aliases");
109 singularToPlural
.Add("portfolio", "portfolios");
111 singularToPlural
.Add("vertex", "vertices");
112 singularToPlural
.Add("matrix", "matrices");
114 singularToPlural
.Add("axis", "axes");
115 singularToPlural
.Add("testis", "testes");
116 singularToPlural
.Add("crisis", "crises");
118 singularToPlural
.Add("rice", "rice");
119 singularToPlural
.Add("shoe", "shoes");
121 singularToPlural
.Add("horse", "horses");
122 singularToPlural
.Add("prize", "prizes");
123 singularToPlural
.Add("edge", "edges");
129 public void PluralizePlurals()
131 Assert
.AreEqual("plurals", Inflector
.Pluralize("plurals"));
132 Assert
.AreEqual("Plurals", Inflector
.Pluralize("Plurals"));
136 public void Pluralize()
138 foreach(DictionaryEntry dictionaryEntry
in singularToPlural
)
140 Assert
.AreEqual(dictionaryEntry
.Value
, Inflector
.Pluralize((string) dictionaryEntry
.Key
));
141 Assert
.AreEqual(Inflector
.Capitalize((string) dictionaryEntry
.Value
),
142 Inflector
.Pluralize(Inflector
.Capitalize((string) dictionaryEntry
.Key
)));
147 public void Singularize()
149 foreach(DictionaryEntry dictionaryEntry
in singularToPlural
)
151 Assert
.AreEqual(dictionaryEntry
.Key
, Inflector
.Singularize((string) dictionaryEntry
.Value
));
152 Assert
.AreEqual(Inflector
.Capitalize((string) dictionaryEntry
.Key
),
153 Inflector
.Singularize(Inflector
.Capitalize((string) dictionaryEntry
.Value
)));