Skip to content

Commit

Permalink
Resolved an AllowEmptyStrings() bug:
Browse files Browse the repository at this point in the history
- The ToString() method of Name now handles scenarious where the name is an empty string
- Empty names can be a result of a SyllableGenerator with no graphemes but the AllowEmptyStringGeneration flag set to true
  • Loading branch information
kesac committed Jan 6, 2024
1 parent 58a674e commit 9526fcc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Syllabore/Syllabore.Tests/SyllableGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ public void SyllableGenerator_NoGraphemesWithEmptyStringAllowed_EndingSyllableGe
Assert.AreEqual(sut.NextEndingSyllable(), string.Empty);
}

[TestMethod]
public void NameGenerator_NoGraphemesWithEmptyStringAllowed_EmptyStringsGenerated()
{
var sg = new SyllableGenerator().AllowEmptyStrings(true);
var sut = new NameGenerator(sg);
Assert.AreEqual(sut.Next(), string.Empty);
}

[TestMethod]
public void SyllableGenerator_WithOneVowel_VowelAppearsInOutput()
{
Expand Down
11 changes: 10 additions & 1 deletion Syllabore/Syllabore/Name.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ public Name(Name copy) {
public override string ToString()
{
var result = string.Join(string.Empty, this.Syllables);
return result.Substring(0, 1).ToUpper() + result.Substring(1).ToLower();

if(result.Length > 0)
{
// Capitalize the first letter
return result.Substring(0, 1).ToUpper() + result.Substring(1).ToLower();
}
else
{
return result;
}
}

/// <summary>
Expand Down

0 comments on commit 9526fcc

Please sign in to comment.