diff --git a/src/TextMateSharp.Tests/Internal/Grammars/AttributedScopeStackTests.cs b/src/TextMateSharp.Tests/Internal/Grammars/AttributedScopeStackTests.cs new file mode 100644 index 0000000..590933d --- /dev/null +++ b/src/TextMateSharp.Tests/Internal/Grammars/AttributedScopeStackTests.cs @@ -0,0 +1,45 @@ +using NUnit.Framework; +using TextMateSharp.Internal.Grammars; + +namespace TextMateSharp.Tests.Internal.Grammars +{ + [TestFixture] + internal class AttributedScopeStackTests + { + [Test] + public void Equals_ShouldMatchEquivalentStacks() + { + AttributedScopeStack stack1 = new AttributedScopeStack(new AttributedScopeStack(null, "source.cs", 1), "meta.test", 2); + AttributedScopeStack stack2 = new AttributedScopeStack(new AttributedScopeStack(null, "source.cs", 1), "meta.test", 2); + + Assert.IsTrue(stack1.Equals(stack2)); + Assert.IsTrue(stack2.Equals(stack1)); + } + + [Test] + public void Equals_ShouldReturnFalseForDifferentStacks() + { + AttributedScopeStack stack1 = new AttributedScopeStack(new AttributedScopeStack(null, "source.cs", 1), "meta.test", 2); + AttributedScopeStack stack2 = new AttributedScopeStack(new AttributedScopeStack(null, "source.cs", 1), "meta.other", 2); + + Assert.IsFalse(stack1.Equals(stack2)); + Assert.IsFalse(stack2.Equals(stack1)); + } + + [Test] + public void Equals_ShouldReturnFalseForDifferentType() + { + AttributedScopeStack stack = new AttributedScopeStack(null, "source.cs", 1); + + Assert.IsFalse(stack.Equals(42)); + } + + [Test] + public void Equals_ShouldReturnFalseForNull() + { + AttributedScopeStack stack = new AttributedScopeStack(null, "source.cs", 1); + + Assert.IsFalse(stack.Equals(null)); + } + } +} diff --git a/src/TextMateSharp/Internal/Grammars/AttributedScopeStack.cs b/src/TextMateSharp/Internal/Grammars/AttributedScopeStack.cs index c79ffe8..70ab106 100644 --- a/src/TextMateSharp/Internal/Grammars/AttributedScopeStack.cs +++ b/src/TextMateSharp/Internal/Grammars/AttributedScopeStack.cs @@ -66,7 +66,7 @@ private static bool Equals(AttributedScopeStack a, AttributedScopeStack b) public override bool Equals(object other) { - if (other == null || (other is AttributedScopeStack)) + if (other == null || !(other is AttributedScopeStack)) return false; return Equals(this, (AttributedScopeStack)other); @@ -206,4 +206,4 @@ private static List GenerateScopes(AttributedScopeStack scopesList) return result; } } -} \ No newline at end of file +}