Skip to content

Commit

Permalink
Added the remainder of the inflector tests: capitalize, uncapitalize,…
Browse files Browse the repository at this point in the history
… ordinalize, and dasherize
  • Loading branch information
srkirkland committed Feb 10, 2011
1 parent 85baff2 commit 19b2453
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 88 deletions.
28 changes: 28 additions & 0 deletions Inflector.Tests/CapitalizeTests.cs
@@ -0,0 +1,28 @@
using NUnit.Framework;

namespace Inflector.Tests
{
[TestFixture]
public class CapitalizeTests : InflectorTestBase
{
[Test]
public void Capitalize()
{
foreach (var pair in TestData)
{
Assert.AreEqual(Inflector.Capitalize(pair.Key), pair.Value);
}
}

public CapitalizeTests()
{
//Capitalizes the first char and lowers the rest of the string
TestData.Add("some title", "Some title");
TestData.Add("some Title", "Some title");
TestData.Add("SOMETITLE", "Sometitle");
TestData.Add("someTitle", "Sometitle");
TestData.Add("some title goes here", "Some title goes here");
TestData.Add("some TITLE", "Some title");
}
}
}
26 changes: 26 additions & 0 deletions Inflector.Tests/DasherizeTests.cs
@@ -0,0 +1,26 @@
using NUnit.Framework;

namespace Inflector.Tests
{
[TestFixture]
public class DasherizeTests : InflectorTestBase
{
[Test]
public void Dasherize()
{
foreach (var pair in TestData)
{
Assert.AreEqual(Inflector.Dasherize(pair.Key), pair.Value);
}
}

public DasherizeTests()
{
//Just replaces underscore with a dash
TestData.Add("some_title", "some-title");
TestData.Add("some-title", "some-title");
TestData.Add("some_title_goes_here", "some-title-goes-here");
TestData.Add("some_title and_another", "some-title and-another");
}
}
}
4 changes: 4 additions & 0 deletions Inflector.Tests/Inflector.Tests.csproj
Expand Up @@ -49,12 +49,16 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CapitalizeTests.cs" />
<Compile Include="DasherizeTests.cs" />
<Compile Include="HumanizeTests.cs" />
<Compile Include="OrdinalizeTests.cs" />
<Compile Include="PascalizeAndCamelizeTests.cs" />
<Compile Include="PluralizeTests.cs" />
<Compile Include="InflectorTestBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TitleizeTests.cs" />
<Compile Include="UncapitalizeTests.cs" />
<Compile Include="UnderscoreTests.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
88 changes: 0 additions & 88 deletions Inflector.Tests/InflectorTestBase.cs
Expand Up @@ -5,93 +5,5 @@ namespace Inflector.Tests
public abstract class InflectorTestBase
{
public readonly Dictionary<string, string> TestData = new Dictionary<string, string>();

public readonly Dictionary<string, string> SingularToPlural = new Dictionary<string, string>();
public readonly Dictionary<string, string> PascalToUnderscore = new Dictionary<string, string>();
public readonly Dictionary<string, string> UnderscoreToCamel = new Dictionary<string, string>();

public readonly Dictionary<string, string> PascalToUnderscoreWithoutReverse =
new Dictionary<string, string>();

public readonly Dictionary<string, string> CamelWithModuleToUnderscoreWithSlash =
new Dictionary<string, string>();

public readonly Dictionary<string, string> UnderscoreToHuman = new Dictionary<string, string>();
public readonly Dictionary<string, string> MixtureToTitleCase = new Dictionary<string, string>();
public readonly Dictionary<string, string> OrdinalNumbers = new Dictionary<string, string>();
public readonly Dictionary<string, string> UnderscoresToDashes = new Dictionary<string, string>();
public readonly Dictionary<string, string> ClassNameToTableName = new Dictionary<string, string>();
public readonly Dictionary<string, string> ClassNameToForeignKeyName = new Dictionary<string, string>();

protected InflectorTestBase()
{
PascalToUnderscore.Add("Product", "product");
PascalToUnderscore.Add("SpecialGuest", "special_guest");
PascalToUnderscore.Add("ApplicationController", "application_controller");
PascalToUnderscore.Add("Area51Controller", "area51_controller");

UnderscoreToCamel.Add("product", "product");
UnderscoreToCamel.Add("special_guest", "specialGuest");
UnderscoreToCamel.Add("application_controller", "applicationController");
UnderscoreToCamel.Add("area51_controller", "area51Controller");

PascalToUnderscoreWithoutReverse.Add("HTMLTidy", "html_tidy");
PascalToUnderscoreWithoutReverse.Add("HTMLTidyGenerator", "html_tidy_generator");
PascalToUnderscoreWithoutReverse.Add("FreeBSD", "free_bsd");
PascalToUnderscoreWithoutReverse.Add("HTML", "html");

UnderscoreToHuman.Add("employee_salary", "Employee salary");
UnderscoreToHuman.Add("employee_id", "Employee id");
UnderscoreToHuman.Add("underground", "Underground");

MixtureToTitleCase.Add("active_record", "Active Record");
MixtureToTitleCase.Add("ActiveRecord", "Active Record");
MixtureToTitleCase.Add("action web service", "Action Web Service");
MixtureToTitleCase.Add("Action Web Service", "Action Web Service");
MixtureToTitleCase.Add("Action web service", "Action Web Service");
MixtureToTitleCase.Add("actionwebservice", "Actionwebservice");
MixtureToTitleCase.Add("Actionwebservice", "Actionwebservice");

OrdinalNumbers.Add("0", "0th");
OrdinalNumbers.Add("1", "1st");
OrdinalNumbers.Add("2", "2nd");
OrdinalNumbers.Add("3", "3rd");
OrdinalNumbers.Add("4", "4th");
OrdinalNumbers.Add("5", "5th");
OrdinalNumbers.Add("6", "6th");
OrdinalNumbers.Add("7", "7th");
OrdinalNumbers.Add("8", "8th");
OrdinalNumbers.Add("9", "9th");
OrdinalNumbers.Add("10", "10th");
OrdinalNumbers.Add("11", "11th");
OrdinalNumbers.Add("12", "12th");
OrdinalNumbers.Add("13", "13th");
OrdinalNumbers.Add("14", "14th");
OrdinalNumbers.Add("20", "20th");
OrdinalNumbers.Add("21", "21st");
OrdinalNumbers.Add("22", "22nd");
OrdinalNumbers.Add("23", "23rd");
OrdinalNumbers.Add("24", "24th");
OrdinalNumbers.Add("100", "100th");
OrdinalNumbers.Add("101", "101st");
OrdinalNumbers.Add("102", "102nd");
OrdinalNumbers.Add("103", "103rd");
OrdinalNumbers.Add("104", "104th");
OrdinalNumbers.Add("110", "110th");
OrdinalNumbers.Add("1000", "1000th");
OrdinalNumbers.Add("1001", "1001st");

UnderscoresToDashes.Add("street", "street");
UnderscoresToDashes.Add("street_address", "street-address");
UnderscoresToDashes.Add("person_street_address", "person-street-address");

ClassNameToTableName.Add("CostomerOrders", "CostomerOrder");
ClassNameToTableName.Add("Costomer_Orders", "Costomer_Order");

ClassNameToForeignKeyName.Add("ProductId", "Product");
ClassNameToForeignKeyName.Add("SpecialGuestId", "SpecialGuest");
ClassNameToForeignKeyName.Add("ApplicationControllerId", "ApplicationController");

}
}
}
50 changes: 50 additions & 0 deletions Inflector.Tests/OrdinalizeTests.cs
@@ -0,0 +1,50 @@
using NUnit.Framework;

namespace Inflector.Tests
{
[TestFixture]
public class OrdinalizeTests : InflectorTestBase
{
[Test]
public void Ordinalize()
{
foreach (var pair in TestData)
{
Assert.AreEqual(Inflector.Ordinalize(pair.Key), pair.Value);
}
}

public OrdinalizeTests()
{
TestData.Add("0", "0th");
TestData.Add("1", "1st");
TestData.Add("2", "2nd");
TestData.Add("3", "3rd");
TestData.Add("4", "4th");
TestData.Add("5", "5th");
TestData.Add("6", "6th");
TestData.Add("7", "7th");
TestData.Add("8", "8th");
TestData.Add("9", "9th");
TestData.Add("10", "10th");
TestData.Add("11", "11th");
TestData.Add("12", "12th");
TestData.Add("13", "13th");
TestData.Add("14", "14th");
TestData.Add("20", "20th");
TestData.Add("21", "21st");
TestData.Add("22", "22nd");
TestData.Add("23", "23rd");
TestData.Add("24", "24th");
TestData.Add("100", "100th");
TestData.Add("101", "101st");
TestData.Add("102", "102nd");
TestData.Add("103", "103rd");
TestData.Add("104", "104th");
TestData.Add("110", "110th");
TestData.Add("1000", "1000th");
TestData.Add("1001", "1001st");

}
}
}
28 changes: 28 additions & 0 deletions Inflector.Tests/UncapitalizeTests.cs
@@ -0,0 +1,28 @@
using NUnit.Framework;

namespace Inflector.Tests
{
[TestFixture]
public class UncapitalizeTests : InflectorTestBase
{
[Test]
public void Uncapitalize()
{
foreach (var pair in TestData)
{
Assert.AreEqual(Inflector.Uncapitalize(pair.Key), pair.Value);
}
}

public UncapitalizeTests()
{
//Just lowers the first char and leaves the rest alone
TestData.Add("some title", "some title");
TestData.Add("some Title", "some Title");
TestData.Add("SOMETITLE", "sOMETITLE");
TestData.Add("someTitle", "someTitle");
TestData.Add("some title goes here", "some title goes here");
TestData.Add("some TITLE", "some TITLE");
}
}
}
3 changes: 3 additions & 0 deletions README.txt
@@ -0,0 +1,3 @@
A copy of the Inflector .NET class, originally written (I believe) by Andrew Peters, as well as unit tests of the class.

I added tests of each Inflector method, since I couldn't find a description anywhere on the web of what each method does.

0 comments on commit 19b2453

Please sign in to comment.