Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
4 changes: 2 additions & 2 deletions src/TextMateSharp/Internal/Grammars/AttributedScopeStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -206,4 +206,4 @@ private static List<string> GenerateScopes(AttributedScopeStack scopesList)
return result;
}
}
}
}
Loading