From 19b245316023d2de7e872e9a4bd7119da0c0a8dc Mon Sep 17 00:00:00 2001 From: Scott Kirkland Date: Thu, 10 Feb 2011 15:26:49 -0800 Subject: [PATCH] Added the remainder of the inflector tests: capitalize, uncapitalize, ordinalize, and dasherize --- Inflector.Tests/CapitalizeTests.cs | 28 ++++++++ Inflector.Tests/DasherizeTests.cs | 26 ++++++++ Inflector.Tests/Inflector.Tests.csproj | 4 ++ Inflector.Tests/InflectorTestBase.cs | 88 -------------------------- Inflector.Tests/OrdinalizeTests.cs | 50 +++++++++++++++ Inflector.Tests/UncapitalizeTests.cs | 28 ++++++++ README.txt | 3 + 7 files changed, 139 insertions(+), 88 deletions(-) create mode 100644 Inflector.Tests/CapitalizeTests.cs create mode 100644 Inflector.Tests/DasherizeTests.cs create mode 100644 Inflector.Tests/OrdinalizeTests.cs create mode 100644 Inflector.Tests/UncapitalizeTests.cs create mode 100644 README.txt diff --git a/Inflector.Tests/CapitalizeTests.cs b/Inflector.Tests/CapitalizeTests.cs new file mode 100644 index 0000000..35a4a1c --- /dev/null +++ b/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"); + } + } +} \ No newline at end of file diff --git a/Inflector.Tests/DasherizeTests.cs b/Inflector.Tests/DasherizeTests.cs new file mode 100644 index 0000000..87c32db --- /dev/null +++ b/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"); + } + } +} \ No newline at end of file diff --git a/Inflector.Tests/Inflector.Tests.csproj b/Inflector.Tests/Inflector.Tests.csproj index 37e6e80..e6f136a 100644 --- a/Inflector.Tests/Inflector.Tests.csproj +++ b/Inflector.Tests/Inflector.Tests.csproj @@ -49,12 +49,16 @@ + + + + diff --git a/Inflector.Tests/InflectorTestBase.cs b/Inflector.Tests/InflectorTestBase.cs index 7e84eb1..686c639 100644 --- a/Inflector.Tests/InflectorTestBase.cs +++ b/Inflector.Tests/InflectorTestBase.cs @@ -5,93 +5,5 @@ namespace Inflector.Tests public abstract class InflectorTestBase { public readonly Dictionary TestData = new Dictionary(); - - public readonly Dictionary SingularToPlural = new Dictionary(); - public readonly Dictionary PascalToUnderscore = new Dictionary(); - public readonly Dictionary UnderscoreToCamel = new Dictionary(); - - public readonly Dictionary PascalToUnderscoreWithoutReverse = - new Dictionary(); - - public readonly Dictionary CamelWithModuleToUnderscoreWithSlash = - new Dictionary(); - - public readonly Dictionary UnderscoreToHuman = new Dictionary(); - public readonly Dictionary MixtureToTitleCase = new Dictionary(); - public readonly Dictionary OrdinalNumbers = new Dictionary(); - public readonly Dictionary UnderscoresToDashes = new Dictionary(); - public readonly Dictionary ClassNameToTableName = new Dictionary(); - public readonly Dictionary ClassNameToForeignKeyName = new Dictionary(); - - 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"); - - } } } \ No newline at end of file diff --git a/Inflector.Tests/OrdinalizeTests.cs b/Inflector.Tests/OrdinalizeTests.cs new file mode 100644 index 0000000..c4d0030 --- /dev/null +++ b/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"); + + } + } +} \ No newline at end of file diff --git a/Inflector.Tests/UncapitalizeTests.cs b/Inflector.Tests/UncapitalizeTests.cs new file mode 100644 index 0000000..2b4298e --- /dev/null +++ b/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"); + } + } +} \ No newline at end of file diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..b17465e --- /dev/null +++ b/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. \ No newline at end of file