TypoCorrectionTests.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. #nullable enable
  4. namespace Microsoft.DotNet.Cli.Utils.Tests
  5. {
  6. public class TypoCorrectionTests
  7. {
  8. [InlineData("wbe", "web|webapp|wpf|install|uninstall", "web|wpf", "Levanshtein algorithm")]
  9. [InlineData("uninstal", "web|webapp|install|uninstall", "uninstall|install", "StartsWith & Contains")]
  10. [InlineData("console", "web|webapp|install|uninstall", "", "No matches")]
  11. [InlineData("blazor", "razor|pazor|blazorweb|blazorservice|uninstall|pizor", "blazorweb|blazorservice|razor|pazor", "StartsWith & Levanshtein algorithm")]
  12. [InlineData("blazor", "razor|pazor|pazors", "razor|pazor", "Levanshtein algorithm with shortest distance filtering")]
  13. [InlineData("con", "lacon|test|consoleweb|precon|uninstall|ponsole|pons", "consoleweb|lacon|precon|pons", "StartsWith & Contains & Levanshtein algorithm")]
  14. [InlineData("c", "lacon|test|consoleweb|preconsole|uninstall|ponsole|pons|ccs", "consoleweb|ccs", "StartsWith & Levanshtein algorithm")]
  15. [InlineData("c", "peacon|lecture|beacon", "", "No matches due to Contains restriction on input length")]
  16. [InlineData(
  17. "eac",
  18. "peac|lect|beac|zeac|dect|meac|qeac|aect|oeac|xeac|necte|geacy|gueac",
  19. "peac|beac|zeac|meac|qeac|oeac|xeac|geacy|gueac|lect",
  20. "Contains due to max number of suggestions restriction")]
  21. [InlineData(
  22. "eacy",
  23. "eacyy|eacyl|eacys|eacyt|eacyp|eacyzz|eacyqwe|eacyasd|eacyaa|eacynbv|eacyrfd|peacy|peacp",
  24. "eacyy|eacyl|eacys|eacyt|eacyp|eacyzz|eacyaa|eacyqwe|eacyasd|eacynbv",
  25. "StartsWith due to max number of suggestions restriction")]
  26. [Theory]
  27. public void TypoCorrection_BasicTest(string token, string possibleTokens, string expectedTokens, string checkedScenario)
  28. {
  29. TypoCorrection.GetSimilarTokens(possibleTokens.Split('|'), token)
  30. .Should().BeEquivalentTo(expectedTokens.Split('|', StringSplitOptions.RemoveEmptyEntries), checkedScenario);
  31. }
  32. }
  33. }