-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathFoldingReferenceEqualityTests.cs
More file actions
88 lines (78 loc) · 3.02 KB
/
Copy pathFoldingReferenceEqualityTests.cs
File metadata and controls
88 lines (78 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using Xunit;
namespace PowerShellEditorServices.Test.Language
{
public class FoldingReferenceEqualityTests
{
private static FoldingReference CreateFoldingReference() => new()
{
StartLine = 1,
StartCharacter = 2,
EndLine = 3,
EndCharacter = 4,
Kind = FoldingRangeKind.Region
};
[Fact]
public void EqualsNullReferenceReturnsFalse()
{
FoldingReference reference = CreateFoldingReference();
FoldingReference other = null;
// Previously this threw a NullReferenceException via CompareTo.
Assert.False(reference.Equals(other));
}
[Fact]
public void EqualsNullObjectReturnsFalse()
{
FoldingReference reference = CreateFoldingReference();
Assert.False(reference.Equals((object)null));
}
[Fact]
public void CompareToNullReturnsOne()
{
FoldingReference reference = CreateFoldingReference();
// A null instance sorts before any actual reference.
Assert.Equal(1, reference.CompareTo(null));
}
[Fact]
public void EqualReferencesAreEqualWithSameHashCode()
{
FoldingReference first = CreateFoldingReference();
FoldingReference second = CreateFoldingReference();
Assert.True(first.Equals(second));
Assert.True(first.Equals((object)second));
Assert.Equal(first.GetHashCode(), second.GetHashCode());
}
[Fact]
public void DifferentReferencesAreNotEqual()
{
FoldingReference first = CreateFoldingReference();
FoldingReference second = CreateFoldingReference();
second.EndLine = 42;
Assert.False(first.Equals(second));
}
[Fact]
public void EqualsDifferentTypeReturnsFalse()
{
FoldingReference reference = CreateFoldingReference();
Assert.False(reference.Equals("not a folding reference"));
}
[Fact]
public void CompareToWithDifferingKindsIsAntisymmetric()
{
FoldingReference comment = CreateFoldingReference();
comment.Kind = FoldingRangeKind.Comment;
FoldingReference region = CreateFoldingReference();
region.Kind = FoldingRangeKind.Region;
// Same range but different (non-null) kinds must order
// deterministically: the comparisons must have opposite signs so
// Array.Sort stays stable. Previously both returned -1.
int forward = comment.CompareTo(region);
int backward = region.CompareTo(comment);
Assert.NotEqual(0, forward);
Assert.Equal(-System.Math.Sign(forward), System.Math.Sign(backward));
}
}
}