public void BuildTest() { { var matcher = Builder.Build(new[] { DiscreteMatchProvider.GetName() }, true); Assert.IsTrue(matcher.IsCaseSensitive); Assert.IsTrue(matcher.ProviderTypes.Count == 1); Assert.IsTrue(matcher.ProviderTypes[0] == DiscreteMatchProvider.GetName()); } { var matcher = Builder.Build(new[] { DiscreteMatchProvider.GetName(), ChineseZhCnPinYinMatchProvider.GetName() }, false); Assert.IsTrue(matcher.IsCaseSensitive == false); Assert.IsTrue(matcher.ProviderTypes.Count == 2); Assert.IsTrue(matcher.ProviderTypes.Any(x => x == DiscreteMatchProvider.GetName())); Assert.IsTrue(matcher.ProviderTypes.Any(x => x == ChineseZhCnPinYinMatchProvider.GetName())); } #if !NET45 { var matcher = Builder.Build(new[] { JapaneseRomajiProvider.GetName(), ChineseZhCnPinYinInitialsMatchProvider.GetName() }, true); Assert.IsTrue(matcher.IsCaseSensitive == true); Assert.IsTrue(matcher.ProviderTypes.Count == 2); Assert.IsTrue(matcher.ProviderTypes.Any(x => x == JapaneseRomajiProvider.GetName())); Assert.IsTrue(matcher.ProviderTypes.Any(x => x == ChineseZhCnPinYinInitialsMatchProvider.GetName())); } #endif }
public void GetProviderDescriptionTest() { { var dsp1 = Builder.GetProviderDescription(DirectMatchProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(DirectMatchProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } { var dsp1 = Builder.GetProviderDescription(InitialsMatchProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(InitialsMatchProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } { var dsp1 = Builder.GetProviderDescription(DiscreteMatchProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(DiscreteMatchProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } { var dsp1 = Builder.GetProviderDescription(ChineseZhCnPinYinMatchProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(ChineseZhCnPinYinMatchProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } { var dsp1 = Builder.GetProviderDescription(ChineseZhCnPinYinInitialsMatchProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(ChineseZhCnPinYinInitialsMatchProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } #if !NET45 { var dsp1 = Builder.GetProviderDescription(JapaneseRomajiProvider.GetName()); var dsp2 = Builder.GetProviderDescriptionEn(JapaneseRomajiProvider.GetName()); Assert.IsTrue(!string.IsNullOrEmpty(dsp1)); Assert.IsTrue(!string.IsNullOrEmpty(dsp2)); } #endif }
public void FindMatchesTestCase() { var matcher = new JapaneseRomajiProvider(true); Assert.IsTrue(matcher.GetProviderName() == nameof(JapaneseRomajiProvider)); var dspen = matcher.GetProviderDescriptionEn(); var dsp = matcher.GetProviderDescription(); { { string str = "abcdefg"; var kws = new[] { "a" }; var ret = matcher.DoMatches(new MatchCache(str), kws); Assert.IsTrue(ret.IsMatchAllKeywords == false); // false by no Chinese char Assert.IsTrue(ret.Keywords.Count == 1 && ret.Keywords[0] == "a"); } { string str = "abcdefg"; var kws = new[] { "A" }; var ret = matcher.DoMatches(new MatchCache(str), kws); Assert.IsTrue(ret.IsMatchAllKeywords == false); // false by no Chinese char Assert.IsTrue(ret.Keywords.Count == 1 && ret.Keywords[0] == "A"); } } var org = new MatchCache("こんにちは, 世界A"); matcher.AppendDescriptions(ref org); Assert.IsTrue(org.SpellCaches.First().Value.GetProviderName() == matcher.GetProviderName()); { var kws = new[] { "kon" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == true); var m = ret.HitFlags; Assert.IsTrue(m.Count == org.StringLength && m[0] == true && m[1] == true && m[2] == true && m[3] == true && m[4] == true && m[5] == false && m[6] == false && m[7] == false && m[8] == false && m[9] == false); } { var kws = new[] { "konaa" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == false); } { var kws = new[] { "konaA" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == true); var m = ret.HitFlags; Assert.IsTrue(m.Count == org.StringLength && m[0] == true && m[1] == true && m[2] == true && m[3] == true && m[4] == true && m[5] == false && m[6] == false && m[7] == false && m[8] == false && m[9] == true); } { var kws = new[] { "sk" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == true); var m = ret.HitFlags; Assert.IsTrue(m.Count == org.StringLength && m[0] == false && m[1] == false && m[2] == false && m[3] == false && m[4] == false && m[5] == false && m[6] == false && m[7] == true && m[8] == true && m[9] == false); } { var kws = new[] { "se" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == true); var m = ret.HitFlags; Assert.IsTrue(m.Count == org.StringLength && m[0] == false && m[1] == false && m[2] == false && m[3] == false && m[4] == false && m[5] == false && m[6] == false && m[7] == true && m[8] == true && m[9] == false); } { var kws = new[] { "skai" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == true); var m = ret.HitFlags; Assert.IsTrue(m.Count == org.StringLength && m[0] == false && m[1] == false && m[2] == false && m[3] == false && m[4] == false && m[5] == false && m[6] == false && m[7] == true && m[8] == true && m[9] == false); } { var kws = new[] { "skaia" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == false); } { var kws = new[] { "skaiA" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == true); var m = ret.HitFlags; Assert.IsTrue(m.Count == org.StringLength && m[0] == false && m[1] == false && m[2] == false && m[3] == false && m[4] == false && m[5] == false && m[6] == false && m[7] == true && m[8] == true && m[9] == true); } { var kws = new[] { "," }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == true); var m = ret.HitFlags; Assert.IsTrue(m.Count == org.StringLength && m[0] == false && m[1] == false && m[2] == false && m[3] == false && m[4] == false && m[5] == true && m[6] == false && m[7] == false && m[8] == false && m[9] == false); } matcher.AppendDescriptions(ref org); { var kws = new[] { "konse" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == true); var m = ret.HitFlags; Assert.IsTrue(m.Count == org.StringLength && m[0] == true && m[1] == true && m[2] == true && m[3] == true && m[4] == true && m[5] == false && m[6] == false && m[7] == true && m[8] == true && m[9] == false); } matcher.AppendDescriptions(ref org); { var kws = new[] { "kon", "se" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == true); var m = ret.HitFlags; Assert.IsTrue(m.Count == org.StringLength && m[0] == true && m[1] == true && m[2] == true && m[3] == true && m[4] == true && m[5] == false && m[6] == false && m[7] == true && m[8] == true && m[9] == false); } matcher.AppendDescriptions(ref org); { var kws = new[] { "kon", "," }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == true); var m = ret.HitFlags; Assert.IsTrue(m.Count == org.StringLength && m[0] == true && m[1] == true && m[2] == true && m[3] == true && m[4] == true && m[5] == true && m[6] == false && m[7] == false && m[8] == false && m[9] == false); } { var kws = new[] { "chi" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == false); } { var kws = new[] { "kai" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == false); } { var kws = new[] { "konkai" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == false); } { var kws = new[] { "kon", "kai" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == false); } matcher.AppendDescriptions(ref org); { var kws = new[] { "kon", ",", "ABC" }; var ret = matcher.DoMatches(org, kws); Assert.IsTrue(ret.IsMatchAllKeywords == false); var m = ret.HitFlags; Assert.IsTrue(m.Count == org.StringLength && m[0] == true && m[1] == true && m[2] == true && m[3] == true && m[4] == true && m[5] == true && m[6] == false && m[7] == false && m[8] == false && m[9] == false); } }