-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathFilterHelperTests.cs
More file actions
112 lines (93 loc) · 3.03 KB
/
FilterHelperTests.cs
File metadata and controls
112 lines (93 loc) · 3.03 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.TestPlatform.Filter.Source.UnitTests;
[TestClass]
public class FilterHelperTests
{
[TestMethod]
public void EscapeShouldReturnOriginalStringWhenNoSpecialCharacters()
{
var input = "TestMethod";
Assert.AreEqual(input, FilterHelper.Escape(input));
}
[TestMethod]
public void EscapeShouldEscapeOpenParenthesis()
{
Assert.AreEqual(@"Test\(Method", FilterHelper.Escape("Test(Method"));
}
[TestMethod]
public void EscapeShouldEscapeCloseParenthesis()
{
Assert.AreEqual(@"Test\)Method", FilterHelper.Escape("Test)Method"));
}
[TestMethod]
public void EscapeShouldEscapeAmpersand()
{
Assert.AreEqual(@"Test\&Method", FilterHelper.Escape("Test&Method"));
}
[TestMethod]
public void EscapeShouldEscapePipe()
{
Assert.AreEqual(@"Test\|Method", FilterHelper.Escape("Test|Method"));
}
[TestMethod]
public void EscapeShouldEscapeEqualSign()
{
Assert.AreEqual(@"Test\=Method", FilterHelper.Escape("Test=Method"));
}
[TestMethod]
public void EscapeShouldEscapeExclamationMark()
{
Assert.AreEqual(@"Test\!Method", FilterHelper.Escape("Test!Method"));
}
[TestMethod]
public void EscapeShouldEscapeTilde()
{
Assert.AreEqual(@"Test\~Method", FilterHelper.Escape("Test~Method"));
}
[TestMethod]
public void EscapeShouldEscapeBackslash()
{
Assert.AreEqual(@"Test\\Method", FilterHelper.Escape(@"Test\Method"));
}
[TestMethod]
public void EscapeShouldEscapeMultipleSpecialCharacters()
{
Assert.AreEqual(@"Test\(A\|B\)", FilterHelper.Escape("Test(A|B)"));
}
[TestMethod]
public void UnescapeShouldReturnOriginalStringWhenNoEscapeCharacters()
{
var input = "TestMethod";
Assert.AreEqual(input, FilterHelper.Unescape(input));
}
[TestMethod]
public void UnescapeShouldUnescapeOpenParenthesis()
{
Assert.AreEqual("Test(Method", FilterHelper.Unescape(@"Test\(Method"));
}
[TestMethod]
public void UnescapeShouldUnescapeCloseParenthesis()
{
Assert.AreEqual("Test)Method", FilterHelper.Unescape(@"Test\)Method"));
}
[TestMethod]
public void UnescapeShouldUnescapeBackslash()
{
Assert.AreEqual(@"Test\Method", FilterHelper.Unescape(@"Test\\Method"));
}
[TestMethod]
public void UnescapeShouldThrowOnInvalidEscapeSequence()
{
Assert.ThrowsExactly<ArgumentException>(() => FilterHelper.Unescape(@"Test\AMethod"));
}
[TestMethod]
public void EscapeAndUnescapeRoundtrip()
{
var input = "TestClass(\"param\").Method(1.5)";
Assert.AreEqual(input, FilterHelper.Unescape(FilterHelper.Escape(input)));
}
}