This repository was archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathTextContentChangedEventArgsExtensionsTest.cs
96 lines (82 loc) · 3.6 KB
/
TextContentChangedEventArgsExtensionsTest.cs
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
89
90
91
92
93
94
95
96
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.VisualStudio.Test;
using Xunit;
namespace Microsoft.VisualStudio.Text
{
public class TextContentChangedEventArgsExtensionsTest
{
[Fact]
public void TextChangeOccurred_NoChanges_ReturnsFalse()
{
// Arrange
var before = new StringTextSnapshot(string.Empty);
var after = new StringTextSnapshot(string.Empty);
var testArgs = new TestTextContentChangedEventArgs(before, after);
// Act
var result = testArgs.TextChangeOccurred(out var changeInformation);
// Assert
Assert.False(result);
}
[Fact]
public void TextChangeOccurred_CancelingChanges_ReturnsFalse()
{
// Arrange
var before = new StringTextSnapshot("by");
before.Version.Changes.Add(new TestTextChange(new SourceChange(0, 2, "hi")));
before.Version.Changes.Add(new TestTextChange(new SourceChange(0, 2, "by")));
var after = new StringTextSnapshot("by");
var testArgs = new TestTextContentChangedEventArgs(before, after);
// Act
var result = testArgs.TextChangeOccurred(out var changeInformation);
// Assert
Assert.False(result);
}
[Fact]
public void TextChangeOccurred_SingleChange_ReturnsTrue()
{
// Arrange
var before = new StringTextSnapshot("by");
var firstChange = new TestTextChange(new SourceChange(0, 2, "hi"));
before.Version.Changes.Add(firstChange);
var after = new StringTextSnapshot("hi");
var testArgs = new TestTextContentChangedEventArgs(before, after);
// Act
var result = testArgs.TextChangeOccurred(out var changeInformation);
// Assert
Assert.True(result);
Assert.Same(firstChange, changeInformation.firstChange);
Assert.Equal(firstChange, changeInformation.lastChange);
Assert.Equal("hi", changeInformation.newText);
Assert.Equal("by", changeInformation.oldText);
}
[Fact]
public void TextChangeOccurred_MultipleChanges_ReturnsTrue()
{
// Arrange
var before = new StringTextSnapshot("by by");
var firstChange = new TestTextChange(new SourceChange(0, 2, "hi"));
before.Version.Changes.Add(firstChange);
var lastChange = new TestTextChange(new SourceChange(3, 2, "hi"));
before.Version.Changes.Add(lastChange);
var after = new StringTextSnapshot("hi hi");
var testArgs = new TestTextContentChangedEventArgs(before, after);
// Act
var result = testArgs.TextChangeOccurred(out var changeInformation);
// Assert
Assert.True(result);
Assert.Same(firstChange, changeInformation.firstChange);
Assert.Equal(lastChange, changeInformation.lastChange);
Assert.Equal("hi hi", changeInformation.newText);
Assert.Equal("by by", changeInformation.oldText);
}
private class TestTextContentChangedEventArgs : TextContentChangedEventArgs
{
public TestTextContentChangedEventArgs(ITextSnapshot before, ITextSnapshot after)
: base(before, after, EditOptions.DefaultMinimalChange, null)
{
}
}
}
}