File size: 2,647 Bytes
8c763fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Management.Automation;
using Xunit;

namespace PSTests.Parallel
{
    public class WildcardPatternTests
    {
        [Fact]
        public void TestEscape_Null()
        {
            Assert.Throws<System.Management.Automation.PSArgumentNullException>(delegate { WildcardPattern.Escape(null); });
        }

        [Fact]
        public void TestEscape_Empty()
        {
            Assert.Equal(WildcardPattern.Escape(string.Empty), string.Empty);
        }

        [Theory]
        [InlineData("a", "a")]
        [InlineData("a*", "a`*")]
        [InlineData("*?[]", "`*`?`[`]")]
        [InlineData("`", "``")]
        [InlineData("```", "``````")]
        [InlineData("a`", "a``")]
        [InlineData("abc`def", "abc``def")]
        [InlineData("abc``def", "abc````def")]
        [InlineData("text with `backticks", "text with ``backticks")]
        [InlineData("ends with `", "ends with ``")]
        [InlineData("`starts with", "``starts with")]
        [InlineData("`in`between`", "``in``between``")]
        [InlineData("no special characters", "no special characters")]
        [InlineData("`*`", "```*``")]
        [InlineData("*`?[]", "`*```?`[`]")]
        [InlineData("`*`?`[", "```*```?```[")]
        [InlineData("*?[]`", "`*`?`[`]``")]
        [InlineData("nested `backticks `inside`", "nested ``backticks ``inside``")]
        [InlineData("wildcard*with`backtick", "wildcard`*with``backtick")]
        public void TestEscape_String(string source, string expected)
        {
            Assert.Equal(WildcardPattern.Escape(source), expected);
        }

        [Theory]
        [InlineData("a", "a")]
        [InlineData("a*", "a*")]
        [InlineData("*?[]", "*?[]")]
        public void TestEscape_String_NotEscape(string source, string expected)
        {
            Assert.Equal(WildcardPattern.Escape(source, new[] { '*', '?', '[', ']' }), expected);
        }

        [Fact]
        public void TestUnescape_Null()
        {
            Assert.Throws<System.Management.Automation.PSArgumentNullException>(delegate { WildcardPattern.Unescape(null); });
        }

        [Fact]
        public void TestUnescape_Empty()
        {
            Assert.Equal(WildcardPattern.Unescape(string.Empty), string.Empty);
        }

        [Theory]
        [InlineData("a", "a")]
        [InlineData("a`*", "a*")]
        [InlineData("`*`?`[`]", "*?[]")]
        public void TestUnescape_String(string source, string expected)
        {
            Assert.Equal(WildcardPattern.Unescape(source), expected);
        }
    }
}