From 85c1dd47ac1b5f39b3325edeb3a335d81bb7a9e4 Mon Sep 17 00:00:00 2001 From: Ksenia Morozova Date: Mon, 14 Oct 2024 13:17:22 +0100 Subject: [PATCH] fix CustomKanaMapping issue --- WanaKanaShaapu.UnitTest/ToKanaUnitTests.cs | 6 +++++- WanaKanaShaapu/Internal/Utils.cs | 3 ++- WanaKanaShaapu/TreeTraverser.cs | 2 +- WanaKanaShaapu/WanaKana.cs | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/WanaKanaShaapu.UnitTest/ToKanaUnitTests.cs b/WanaKanaShaapu.UnitTest/ToKanaUnitTests.cs index 4f123d6..80226a4 100644 --- a/WanaKanaShaapu.UnitTest/ToKanaUnitTests.cs +++ b/WanaKanaShaapu.UnitTest/ToKanaUnitTests.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using WanaKanaShaapu; namespace WanaKanaShaapu.UnitTests { @@ -111,9 +112,12 @@ public void ToKana_WhenPassedObsoleteKanaFlagTrue_ReturnsObsoleteKanaString(stri } [TestCase("wanakana", "わにBanaに")] + [TestCase("GG", "GG")] + [TestCase(" GG ", " GG ")] + [TestCase("TT", "TT")] public void ToKana_WhenPassedCustomMapping_ReturnsACorrectString(string input, string expectedOutput) { - string result = WanaKana.ToKana(input, new DefaultOptions { CustomKanaMapping = new Dictionary { { "na", "に" }, { "ka", "Bana" } } }); + string result = WanaKana.ToKana(input, new DefaultOptions { CustomKanaMapping = new Dictionary { { "na", "に" }, { "ka", "Bana" }, { "GG", "GG" }, { "TT", "TT" } } }); Assert.AreEqual(result, expectedOutput); } diff --git a/WanaKanaShaapu/Internal/Utils.cs b/WanaKanaShaapu/Internal/Utils.cs index 37aaec0..b1b2ed4 100644 --- a/WanaKanaShaapu/Internal/Utils.cs +++ b/WanaKanaShaapu/Internal/Utils.cs @@ -145,12 +145,13 @@ internal static Dictionary CreateCustomTree(DefaultOptions options { var treeCopy = TreeBuilder.BuildRomajiToKanaTree(); foreach (var pair in options.CustomKanaMapping) - ChangeNodeData(treeCopy, pair.Key, pair.Value); + ChangeNodeData(treeCopy, pair.Key.ToLower(), pair.Value); return treeCopy; } internal static void ChangeNodeData(Dictionary tree, string key, string value) { + Node node = tree[key.First().ToString()]; if (key.Length == 1 || !node.Children.Any()) node.Data = value; diff --git a/WanaKanaShaapu/TreeTraverser.cs b/WanaKanaShaapu/TreeTraverser.cs index fa34976..326a0cb 100644 --- a/WanaKanaShaapu/TreeTraverser.cs +++ b/WanaKanaShaapu/TreeTraverser.cs @@ -24,7 +24,7 @@ public static string TraverseTree(string result, string word, Dictionary slice.Contains(k.Key))) convertedString += ToKatakana(TreeTraverser.TraverseTree(convertedString, slice.ToLower(), tree, tree, options)); else convertedString += TreeTraverser.TraverseTree(convertedString, slice, tree, tree, options);