forked from Azure/bicep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show spelling suggestion in symbol/property name not found error mess…
…ages (Azure#615) * Implement a levenshtein distance based spell checker * Provide spelling sugesstion for not found symbol * Spell checking for property names * Fix tests * Fix malformed code * Remove a bogus test * Fix levenshtein max boundary * Address comments * levenshtein => Levenshtein
- Loading branch information
Showing
14 changed files
with
341 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using Bicep.Core.Text; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Bicep.Core.UnitTests.Text | ||
{ | ||
[TestClass] | ||
public class SpellCheckerTests | ||
{ | ||
[DataTestMethod] | ||
[DataRow(null)] | ||
[DataRow(new string[0])] | ||
public void GetSpellingSuggestion_NullOrEmptyCandidatesEnumerable_ReturnsNull(string[] candidates) | ||
{ | ||
string? result = SpellChecker.GetSpellingSuggestion("foo", candidates); | ||
|
||
result.Should().BeNull(); | ||
} | ||
|
||
[DataTestMethod] | ||
public void GetSpellingSuggestion_EmptyCandidate_ReturnsNull() | ||
{ | ||
var candidates = new [] { "", "" }; | ||
|
||
string? result = SpellChecker.GetSpellingSuggestion("foo", candidates); | ||
|
||
result.Should().BeNull(); | ||
} | ||
|
||
[TestMethod] | ||
public void GetSpellingSuggestion_CandidateHasLessThanThreeCharacters_ReturnsNull() | ||
{ | ||
var candidates = new [] { "o", "oo", "oO", "OO" }; | ||
|
||
string? result = SpellChecker.GetSpellingSuggestion("ooo", candidates); | ||
|
||
result.Should().BeNull(); | ||
} | ||
|
||
[DataTestMethod] | ||
// maxLengthDifference = 1 | ||
[DataRow("ooo", "ooooo", "oooooo")] | ||
[DataRow("ooooo", "ooo", "ooooooo")] | ||
// maxLengthDifference = 2 | ||
[DataRow("oooooo", "ooo", "ooooooooo", "oooooooooooooo")] | ||
[DataRow("oooooooo", "oooo", "ooooo", "ooooooooooo")] | ||
public void GetSpellingSuggestion_LengthDifferenceExceedsMax_ReturnsNull(string name, params string[] candidates) | ||
{ | ||
string? result = SpellChecker.GetSpellingSuggestion(name, candidates); | ||
|
||
result.Should().BeNull(); | ||
} | ||
|
||
[DataTestMethod] | ||
// maxLengthDifference = 1, maxDistance = 1 | ||
[DataRow("ooo", "ooooo", "oooooo", "oxo", "oOO")] | ||
[DataRow("ooooo", "ooo", "ooooooo", "oooooo", "oOoOO")] | ||
// maxLengthDifference = 2, maxDistance = 2 | ||
[DataRow("oooooo", "ooo", "ooooooooo", "ooooox", "OOOOOO")] | ||
[DataRow("oooooooo", "oooo", "ooooo", "ooooooooooo", "ooooooo", "OoOooOOo")] | ||
public void GetSpellingSuggestion_CandidateMatchesNameCaseInsensitively_ReturnsCandidate(string name, params string[] candidates) | ||
{ | ||
string? result = SpellChecker.GetSpellingSuggestion(name, candidates); | ||
|
||
result.Should().Be(candidates[^1]); | ||
} | ||
|
||
[DataTestMethod] | ||
// maxLengthDifference = 1, maxDistance = 1 | ||
[DataRow("ooo", "ooooo", "oooooo", "oxx", "oooo", "oxo", "xoo")] | ||
[DataRow("ooo", "ooooo", "oooooo", "oxx", "oxo", "xoo", "oooo")] | ||
[DataRow("ooo", "ooooo", "oooooo", "oxx", "xoo", "oooo", "oxo")] | ||
[DataRow("ooooo", "ooo", "ooooooo", "oxxoo", "oooo", "oooooo", "oxooo")] | ||
[DataRow("ooooo", "ooo", "ooooooo", "oxxoo", "oooooo", "oxooo", "oooo")] | ||
[DataRow("ooooo", "ooo", "ooooooo", "oxxoo", "oxooo", "oooo", "oooooo")] | ||
// maxLengthDifference = 2, maxDistance = 2 | ||
[DataRow("oooooo", "ooo", "ooooooooo", "oooo", "ooooo", "ooooooo", "ooooox")] | ||
[DataRow("oooooo", "ooo", "ooooooooo", "oooo", "ooooooo", "ooooox", "ooooo")] | ||
[DataRow("oooooo", "ooo", "ooooooooo", "oooo", "ooooox", "ooooo", "ooooooo")] | ||
[DataRow("oooooooo", "oooo", "ooooo", "ooooooooooo", "oooooo", "ooooooo", "ooooooooo", "ooooooox")] | ||
[DataRow("oooooooo", "oooo", "ooooo", "ooooooooooo", "oooooo", "ooooooooo", "ooooooox", "ooooooo")] | ||
[DataRow("oooooooo", "oooo", "ooooo", "ooooooooooo", "oooooo", "ooooooox", "ooooooo", "ooooooooo")] | ||
public void GetSpellingSuggestion_NoCaseInsensitiveMatches_ReturnsFirstCandidateWithSmallestEditDistance(string name, params string[] candidates) | ||
{ | ||
string? result = SpellChecker.GetSpellingSuggestion(name, candidates); | ||
|
||
result.Should().Be(candidates[^3]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.