forked from elig0n/Switcheroo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StartsWithMatcherTests.cs
109 lines (90 loc) · 3.45 KB
/
StartsWithMatcherTests.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
97
98
99
100
101
102
103
104
105
106
107
108
109
using System.Linq;
using NUnit.Framework;
using Switcheroo.Core.Matchers;
namespace Switcheroo.Core.UnitTests
{
[TestFixture]
public class StartsWithMatcherTests
{
[Test]
public void Evaluate_InputStartsWithPattern_ResultIsMatched()
{
var input = "google chrome";
var pattern = "google";
var result = Evaluate(input, pattern);
Assert.That(result.Matched, Is.True);
}
[Test]
public void Evaluate_InputStartsWithPattern_ScoreIsFour()
{
var input = "google chrome";
var pattern = "google";
var result = Evaluate(input, pattern);
Assert.That(result.Score, Is.EqualTo(4));
}
[Test]
public void Evaluate_InputStartsWithPattern_FirstStringPartIsMatch()
{
var input = "google chrome";
var pattern = "google";
var result = Evaluate(input, pattern);
Assert.That(result.StringParts.First().Value, Is.EqualTo("google"));
Assert.That(result.StringParts.First().IsMatch, Is.True);
}
[Test]
public void Evaluate_InputStartsWithPattern_SecondStringPartIsNotMatch()
{
var input = "google chrome";
var pattern = "google";
var result = Evaluate(input, pattern);
Assert.That(result.StringParts.ToList()[1].Value, Is.EqualTo(" chrome"));
Assert.That(result.StringParts.ToList()[1].IsMatch, Is.False);
}
[Test]
public void Evaluate_NullInput_ReturnsNotMatchingResult()
{
var result = Evaluate(null, "google");
Assert.That(result.Matched, Is.False);
}
[Test]
public void Evaluate_NullPattern_ReturnsNotMatchingResult()
{
var result = Evaluate("google chrome", null);
Assert.That(result.Matched, Is.False);
}
[Test]
public void Evaluate_NullPattern_ReturnsOneNonMatchingStringPart()
{
var result = Evaluate("google chrome", null);
Assert.That(result.StringParts.Count(), Is.EqualTo(1));
Assert.That(result.StringParts.First().Value, Is.EqualTo("google chrome"));
Assert.That(result.StringParts.First().IsMatch, Is.False);
}
[Test]
public void Evaluate_InputContainsPattern_ReturnsNotMatchingResult()
{
var result = Evaluate("google chrome", "chrome");
Assert.That(result.Matched, Is.False);
}
[Test]
public void Evaluate_InputContainsPattern_ReturnsOneNonMatchingStringPart()
{
var result = Evaluate("google chrome", "chrome");
Assert.That(result.StringParts.Count(), Is.EqualTo(1));
Assert.That(result.StringParts.First().Value, Is.EqualTo("google chrome"));
Assert.That(result.StringParts.First().IsMatch, Is.False);
}
[Test]
public void Evaluate_InputStartsWithPattern_CasingIsNotChanged()
{
var result = Evaluate("Google Chrome", "google");
Assert.That(result.StringParts[0].Value, Is.EqualTo("Google"));
Assert.That(result.StringParts[1].Value, Is.EqualTo(" Chrome"));
}
private static MatchResult Evaluate(string input, string pattern)
{
var matcher = new StartsWithMatcher();
return matcher.Evaluate(input, pattern);
}
}
}