forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectiveLineProcessorTests.cs
More file actions
102 lines (94 loc) · 3.97 KB
/
DirectiveLineProcessorTests.cs
File metadata and controls
102 lines (94 loc) · 3.97 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
using ScriptCs.Contracts;
using Should;
using Xunit;
namespace ScriptCs.Tests
{
public class DirectiveLineProcessorTests
{
public class TheProcessLineMethod
{
[Fact]
public void ShouldReturnTrueButNotContinueProcessingDirectiveIfAfterCodeByDefault()
{
var directiveLineProcessor = new TestableDirectiveLineProcessor();
var returnValue = directiveLineProcessor.ProcessLine(null, null, "#Test x", false);
returnValue.ShouldBeTrue();
directiveLineProcessor.InheritedProcessLineCalled.ShouldBeFalse();
}
[Fact]
public void ShouldReturnTrueAndContinueProcessingDirectiveIfAfterCodeAndBehaviourAfterCodeIsAllow()
{
var directiveLineProcessor = new TestableDirectiveLineProcessor(BehaviorAfterCode.Allow);
var returnValue = directiveLineProcessor.ProcessLine(null, null, "#Test x", false);
returnValue.ShouldBeTrue();
directiveLineProcessor.InheritedProcessLineCalled.ShouldBeTrue();
}
}
public class TheMatchesMethod
{
[Fact]
public void ShouldReturnTrueWhenLineMatchesDirectiveStringWithAnArgument()
{
var directiveLineProcessor = new TestableDirectiveLineProcessor();
directiveLineProcessor.Matches("#Test argument").ShouldBeTrue();
}
[Fact]
public void ShouldReturnTrueWhenLineMatchesDirectiveStringWithoutAnArgument()
{
var directiveLineProcessor = new TestableDirectiveLineProcessor();
directiveLineProcessor.Matches("#Test").ShouldBeTrue();
}
[Fact]
public void ShouldReturnFalseWhenLineDoesNotMatchDirectiveStringWithAnArgument()
{
var directiveLineProcessor = new TestableDirectiveLineProcessor();
directiveLineProcessor.Matches("#NotATest argument").ShouldBeFalse();
}
[Fact]
public void ShouldReturnFalseWhenLineDoesNotMatchDirectiveStringWithoutAnArgument()
{
var directiveLineProcessor = new TestableDirectiveLineProcessor();
directiveLineProcessor.Matches("#NotATest").ShouldBeFalse();
}
}
public class TheGetDirectiveArgumentMethod
{
[Fact]
public void ShouldParseTheArgumentFromTheDirectiveLine()
{
var directiveLineProcessor = new TestableDirectiveLineProcessor(BehaviorAfterCode.Allow);
directiveLineProcessor.ProcessLine(null, null, "#Test argument", false);
directiveLineProcessor.ArgumentParsedCorrectly.ShouldBeTrue();
}
}
public class TestableDirectiveLineProcessor : DirectiveLineProcessor
{
private BehaviorAfterCode? _behaviourAfterCode;
public TestableDirectiveLineProcessor()
{ }
public TestableDirectiveLineProcessor(BehaviorAfterCode behaviourAfterCode)
{
_behaviourAfterCode = behaviourAfterCode;
}
protected override BehaviorAfterCode BehaviorAfterCode
{
get
{
return _behaviourAfterCode ?? base.BehaviorAfterCode;
}
}
protected override string DirectiveName
{
get { return "Test"; }
}
public bool ArgumentParsedCorrectly { get; private set; }
public bool InheritedProcessLineCalled { get; private set; }
protected override bool ProcessLine(IFileParser parser, FileParserContext context, string line)
{
ArgumentParsedCorrectly = GetDirectiveArgument(line) == "argument";
InheritedProcessLineCalled = true;
return true;
}
}
}
}