Skip to content

Commit 9d8694d

Browse files
authored
Merge pull request #111 from danipen/copilot/fix-equals-method-logic
Fix AttributedScopeStack equality type check
2 parents 4532112 + 3574b27 commit 9d8694d

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using NUnit.Framework;
2+
using TextMateSharp.Internal.Grammars;
3+
4+
namespace TextMateSharp.Tests.Internal.Grammars
5+
{
6+
[TestFixture]
7+
internal class AttributedScopeStackTests
8+
{
9+
[Test]
10+
public void Equals_ShouldMatchEquivalentStacks()
11+
{
12+
AttributedScopeStack stack1 = new AttributedScopeStack(new AttributedScopeStack(null, "source.cs", 1), "meta.test", 2);
13+
AttributedScopeStack stack2 = new AttributedScopeStack(new AttributedScopeStack(null, "source.cs", 1), "meta.test", 2);
14+
15+
Assert.IsTrue(stack1.Equals(stack2));
16+
Assert.IsTrue(stack2.Equals(stack1));
17+
}
18+
19+
[Test]
20+
public void Equals_ShouldReturnFalseForDifferentStacks()
21+
{
22+
AttributedScopeStack stack1 = new AttributedScopeStack(new AttributedScopeStack(null, "source.cs", 1), "meta.test", 2);
23+
AttributedScopeStack stack2 = new AttributedScopeStack(new AttributedScopeStack(null, "source.cs", 1), "meta.other", 2);
24+
25+
Assert.IsFalse(stack1.Equals(stack2));
26+
Assert.IsFalse(stack2.Equals(stack1));
27+
}
28+
29+
[Test]
30+
public void Equals_ShouldReturnFalseForDifferentType()
31+
{
32+
AttributedScopeStack stack = new AttributedScopeStack(null, "source.cs", 1);
33+
34+
Assert.IsFalse(stack.Equals(42));
35+
}
36+
37+
[Test]
38+
public void Equals_ShouldReturnFalseForNull()
39+
{
40+
AttributedScopeStack stack = new AttributedScopeStack(null, "source.cs", 1);
41+
42+
Assert.IsFalse(stack.Equals(null));
43+
}
44+
}
45+
}

src/TextMateSharp/Internal/Grammars/AttributedScopeStack.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private static bool Equals(AttributedScopeStack a, AttributedScopeStack b)
6666

6767
public override bool Equals(object other)
6868
{
69-
if (other == null || (other is AttributedScopeStack))
69+
if (other == null || !(other is AttributedScopeStack))
7070
return false;
7171

7272
return Equals(this, (AttributedScopeStack)other);
@@ -206,4 +206,4 @@ private static List<string> GenerateScopes(AttributedScopeStack scopesList)
206206
return result;
207207
}
208208
}
209-
}
209+
}

0 commit comments

Comments
 (0)