-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathCaptureTests.cs
67 lines (56 loc) · 1.93 KB
/
CaptureTests.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
using CSharpVerbalExpressions;
using NUnit.Framework;
namespace VerbalExpressionsUnitTests
{
[TestFixture]
public class CaptureTests
{
[Test]
public void BeginCaptureAndEndCapture_AddComOrOrg_RegexIsAsExpected()
{
// Arrange
VerbalExpressions verbEx = VerbalExpressions.DefaultExpression;
// Act
verbEx.BeginCapture()
.Add("com")
.Or("org")
.EndCapture();
// Assert
Assert.AreEqual("((com)|(org))", verbEx.ToString());
}
[Test]
public void BeginCaptureAndEndCapture_DuplicatesIdentifier_DoesMatch()
{
// Arrange
VerbalExpressions verbEx = VerbalExpressions.DefaultExpression;
const string TEST_STRING = "He said that that was the the correct answer.";
// Act
verbEx.BeginCapture()
.Word()
.EndCapture()
.Add(@"\s", false)
.BeginCapture()
.Add(@"\1", false)
.EndCapture();
// Assert
Assert.AreEqual(@"(\w+)\s(\1)", verbEx.ToString());
Assert.IsTrue(verbEx.Test(TEST_STRING), "There is no duplicates in the textString.");
}
[Test]
public void BeginCaptureWithName_CreateRegexGroupNameAsExpected()
{
// Arrange
VerbalExpressions verbEx = VerbalExpressions.DefaultExpression;
// Act
verbEx.Add("COD")
.BeginCapture("GroupNumber")
.Any("0-9")
.RepeatPrevious(3)
.EndCapture()
.Add("END");
// Assert
Assert.AreEqual(@"COD(?<GroupNumber>[0-9]{3})END", verbEx.ToString());
Assert.AreEqual("123", verbEx.Capture("COD123END", "GroupNumber"));
}
}
}