2
2
3
3
using NUnit . Framework ;
4
4
using System ;
5
+ using System . Collections ;
6
+ using System . Collections . Generic ;
5
7
using System . Xml ;
6
8
7
9
namespace NUnit . Engine . Tests
@@ -16,47 +18,19 @@ public void CreateParser()
16
18
_parser = new TestSelectionParser ( ) ;
17
19
}
18
20
19
- [ TestCase ( "cat=Urgent" , "<cat>Urgent</cat>" ) ]
20
- [ TestCase ( "cat==Urgent" , "<cat>Urgent</cat>" ) ]
21
- [ TestCase ( "cat!=Urgent" , "<not><cat>Urgent</cat></not>" ) ]
22
- [ TestCase ( "cat =~ Urgent" , "<cat re='1'>Urgent</cat>" ) ]
23
- [ TestCase ( "cat !~ Urgent" , "<not><cat re='1'>Urgent</cat></not>" ) ]
24
- [ TestCase ( "cat = Urgent || cat = High" , "<or><cat>Urgent</cat><cat>High</cat></or>" ) ]
25
- [ TestCase ( "Priority == High" , "<prop name='Priority'>High</prop>" ) ]
26
- [ TestCase ( "Priority != Urgent" , "<not><prop name='Priority'>Urgent</prop></not>" ) ]
27
- [ TestCase ( "Author =~ Jones" , "<prop name='Author' re='1'>Jones</prop>" ) ]
28
- [ TestCase ( "Author !~ Jones" , "<not><prop name='Author' re='1'>Jones</prop></not>" ) ]
29
- [ TestCase ( "name='SomeTest'" , "<name>SomeTest</name>" ) ]
30
- [ TestCase ( "method=TestMethod" , "<method>TestMethod</method>" ) ]
31
- [ TestCase ( "method=Test1||method=Test2||method=Test3" , "<or><method>Test1</method><method>Test2</method><method>Test3</method></or>" ) ]
32
- [ TestCase ( "namespace=Foo" , "<namespace>Foo</namespace>" ) ]
33
- [ TestCase ( "namespace=Foo.Bar" , "<namespace>Foo.Bar</namespace>" ) ]
34
- [ TestCase ( "namespace=Foo||namespace=Bar" , "<or><namespace>Foo</namespace><namespace>Bar</namespace></or>" ) ]
35
- [ TestCase ( "namespace=Foo.Bar||namespace=Bar.Baz" , "<or><namespace>Foo.Bar</namespace><namespace>Bar.Baz</namespace></or>" ) ]
36
- [ TestCase ( "test='My.Test.Fixture.Method(42)'" , "<test>My.Test.Fixture.Method(42)</test>" ) ]
37
- [ TestCase ( "test='My.Test.Fixture.Method(\" xyz\" )'" , "<test>My.Test.Fixture.Method("xyz")</test>" ) ]
38
- [ TestCase ( "test='My.Test.Fixture.Method(\" abc\\ 's\" )'" , "<test>My.Test.Fixture.Method("abc's")</test>" ) ]
39
- [ TestCase ( "test='My.Test.Fixture.Method(\" x&y&z\" )'" , "<test>My.Test.Fixture.Method("x&y&z")</test>" ) ]
40
- [ TestCase ( "test='My.Test.Fixture.Method(\" <xyz>\" )'" , "<test>My.Test.Fixture.Method("<xyz>")</test>" ) ]
41
- [ TestCase ( "test=='Issue1510.TestSomething(Option1,\" ABC\" )'" , "<test>Issue1510.TestSomething(Option1,"ABC")</test>" ) ]
42
- [ TestCase ( "cat==Urgent && test=='My.Tests'" , "<and><cat>Urgent</cat><test>My.Tests</test></and>" ) ]
43
- [ TestCase ( "cat==Urgent and test=='My.Tests'" , "<and><cat>Urgent</cat><test>My.Tests</test></and>" ) ]
44
- [ TestCase ( "cat==Urgent || test=='My.Tests'" , "<or><cat>Urgent</cat><test>My.Tests</test></or>" ) ]
45
- [ TestCase ( "cat==Urgent or test=='My.Tests'" , "<or><cat>Urgent</cat><test>My.Tests</test></or>" ) ]
46
- [ TestCase ( "cat==Urgent || test=='My.Tests' && cat == high" , "<or><cat>Urgent</cat><and><test>My.Tests</test><cat>high</cat></and></or>" ) ]
47
- [ TestCase ( "cat==Urgent && test=='My.Tests' || cat == high" , "<or><and><cat>Urgent</cat><test>My.Tests</test></and><cat>high</cat></or>" ) ]
48
- [ TestCase ( "cat==Urgent && (test=='My.Tests' || cat == high)" , "<and><cat>Urgent</cat><or><test>My.Tests</test><cat>high</cat></or></and>" ) ]
49
- [ TestCase ( "cat==Urgent && !(test=='My.Tests' || cat == high)" , "<and><cat>Urgent</cat><not><or><test>My.Tests</test><cat>high</cat></or></not></and>" ) ]
50
- [ TestCase ( "!(test!='My.Tests')" , "<not><not><test>My.Tests</test></not></not>" ) ]
51
- [ TestCase ( "!(cat!=Urgent)" , "<not><not><cat>Urgent</cat></not></not>" ) ]
52
- public void TestParser ( string input , string output )
21
+ [ TestCaseSource ( nameof ( UniqueOutputs ) ) ]
22
+ public void AllOutputsAreValidXml ( string output )
53
23
{
54
- Assert . That ( _parser . Parse ( input ) , Is . EqualTo ( output ) ) ;
55
-
56
24
XmlDocument doc = new XmlDocument ( ) ;
57
25
Assert . DoesNotThrow ( ( ) => doc . LoadXml ( output ) ) ;
58
26
}
59
27
28
+ [ TestCaseSource ( nameof ( ParserTestCases ) ) ]
29
+ public void TestParser ( string input , string output )
30
+ {
31
+ Assert . That ( _parser . Parse ( input ) , Is . EqualTo ( output ) ) ;
32
+ }
33
+
60
34
[ TestCase ( null , typeof ( ArgumentNullException ) ) ]
61
35
[ TestCase ( "" , typeof ( TestSelectionParserException ) ) ]
62
36
[ TestCase ( " " , typeof ( TestSelectionParserException ) ) ]
@@ -65,5 +39,84 @@ public void TestParser_InvalidInput(string input, Type type)
65
39
{
66
40
Assert . That ( ( ) => _parser . Parse ( input ) , Throws . TypeOf ( type ) ) ;
67
41
}
42
+
43
+ private static readonly TestCaseData [ ] ParserTestCases = new [ ]
44
+ {
45
+ // Category Filter
46
+ new TestCaseData ( "cat=Urgent" , "<cat>Urgent</cat>" ) ,
47
+ new TestCaseData ( "cat=/Urgent/" , "<cat>Urgent</cat>" ) ,
48
+ new TestCaseData ( "cat='Urgent'" , "<cat>Urgent</cat>" ) ,
49
+ new TestCaseData ( "cat==Urgent" , "<cat>Urgent</cat>" ) ,
50
+ new TestCaseData ( "cat!=Urgent" , "<not><cat>Urgent</cat></not>" ) ,
51
+ new TestCaseData ( "cat =~ Urgent" , "<cat re='1'>Urgent</cat>" ) ,
52
+ new TestCaseData ( "cat !~ Urgent" , "<not><cat re='1'>Urgent</cat></not>" ) ,
53
+ // Property Filter
54
+ new TestCaseData ( "Priority == High" , "<prop name='Priority'>High</prop>" ) ,
55
+ new TestCaseData ( "Priority != Urgent" , "<not><prop name='Priority'>Urgent</prop></not>" ) ,
56
+ new TestCaseData ( "Author =~ Jones" , "<prop name='Author' re='1'>Jones</prop>" ) ,
57
+ new TestCaseData ( "Author !~ Jones" , "<not><prop name='Author' re='1'>Jones</prop></not>" ) ,
58
+ // Name Filter
59
+ new TestCaseData ( "name='SomeTest'" , "<name>SomeTest</name>" ) ,
60
+ // Method Filter
61
+ new TestCaseData ( "method=TestMethod" , "<method>TestMethod</method>" ) ,
62
+ new TestCaseData ( "method=Test1||method=Test2||method=Test3" , "<or><method>Test1</method><method>Test2</method><method>Test3</method></or>" ) ,
63
+ // Namespace Filter
64
+ new TestCaseData ( "namespace=Foo" , "<namespace>Foo</namespace>" ) ,
65
+ new TestCaseData ( "namespace=Foo.Bar" , "<namespace>Foo.Bar</namespace>" ) ,
66
+ new TestCaseData ( "namespace=Foo||namespace=Bar" , "<or><namespace>Foo</namespace><namespace>Bar</namespace></or>" ) ,
67
+ new TestCaseData ( "namespace=Foo.Bar||namespace=Bar.Baz" , "<or><namespace>Foo.Bar</namespace><namespace>Bar.Baz</namespace></or>" ) ,
68
+ // Test Filter
69
+ new TestCaseData ( "test='My.Test.Fixture.Method(42)'" , "<test>My.Test.Fixture.Method(42)</test>" ) ,
70
+ new TestCaseData ( "test='My.Test.Fixture.Method(\" xyz\" )'" , "<test>My.Test.Fixture.Method("xyz")</test>" ) ,
71
+ new TestCaseData ( "test='My.Test.Fixture.Method(\" abc\\ 's\" )'" , "<test>My.Test.Fixture.Method("abc's")</test>" ) ,
72
+ new TestCaseData ( "test='My.Test.Fixture.Method(\" x&y&z\" )'" , "<test>My.Test.Fixture.Method("x&y&z")</test>" ) ,
73
+ new TestCaseData ( "test='My.Test.Fixture.Method(\" <xyz>\" )'" , "<test>My.Test.Fixture.Method("<xyz>")</test>" ) ,
74
+ new TestCaseData ( "test=='Issue1510.TestSomething ( Option1 , \" ABC\" ) '" , "<test>Issue1510.TestSomething(Option1,"ABC")</test>" ) ,
75
+ new TestCaseData ( "test=='Issue1510.TestSomething ( Option1 , \" A B C\" ) '" , "<test>Issue1510.TestSomething(Option1,"A B C")</test>" ) ,
76
+ new TestCaseData ( "test=/My.Test.Fixture.Method(42)/" , "<test>My.Test.Fixture.Method(42)</test>" ) ,
77
+ new TestCaseData ( "test=/My.Test.Fixture.Method(\" xyz\" )/" , "<test>My.Test.Fixture.Method("xyz")</test>" ) ,
78
+ new TestCaseData ( "test=/My.Test.Fixture.Method(\" abc\\ 's\" )/" , "<test>My.Test.Fixture.Method("abc's")</test>" ) ,
79
+ new TestCaseData ( "test=/My.Test.Fixture.Method(\" x&y&z\" )/" , "<test>My.Test.Fixture.Method("x&y&z")</test>" ) ,
80
+ new TestCaseData ( "test=/My.Test.Fixture.Method(\" <xyz>\" )/" , "<test>My.Test.Fixture.Method("<xyz>")</test>" ) ,
81
+ new TestCaseData ( "test==/Issue1510.TestSomething ( Option1 , \" ABC\" ) /" , "<test>Issue1510.TestSomething(Option1,"ABC")</test>" ) ,
82
+ new TestCaseData ( "test==/Issue1510.TestSomething ( Option1 , \" A B C\" ) /" , "<test>Issue1510.TestSomething(Option1,"A B C")</test>" ) ,
83
+ new TestCaseData ( "test=My.Test.Fixture.Method(42)" , "<test>My.Test.Fixture.Method(42)</test>" ) ,
84
+ new TestCaseData ( "test=My.Test.Fixture.Method(\" xyz\" )" , "<test>My.Test.Fixture.Method("xyz")</test>" ) ,
85
+ new TestCaseData ( "test=My.Test.Fixture.Method(\" abc\\ 's\" )" , "<test>My.Test.Fixture.Method("abc's")</test>" ) ,
86
+ new TestCaseData ( "test=My.Test.Fixture.Method(\" x&y&z\" )" , "<test>My.Test.Fixture.Method("x&y&z")</test>" ) ,
87
+ new TestCaseData ( "test=My.Test.Fixture.Method(\" <xyz>\" )" , "<test>My.Test.Fixture.Method("<xyz>")</test>" ) ,
88
+ new TestCaseData ( "test==Issue1510.TestSomething ( Option1 , \" ABC\" ) " , "<test>Issue1510.TestSomething(Option1,"ABC")</test>" ) ,
89
+ new TestCaseData ( "test==Issue1510.TestSomething ( Option1 , \" A B C\" ) " , "<test>Issue1510.TestSomething(Option1,"A B C")</test>" ) ,
90
+ // And Filter
91
+ new TestCaseData ( "cat==Urgent && test=='My.Tests'" , "<and><cat>Urgent</cat><test>My.Tests</test></and>" ) ,
92
+ new TestCaseData ( "cat==Urgent and test=='My.Tests'" , "<and><cat>Urgent</cat><test>My.Tests</test></and>" ) ,
93
+ // Or Filter
94
+ new TestCaseData ( "cat==Urgent || test=='My.Tests'" , "<or><cat>Urgent</cat><test>My.Tests</test></or>" ) ,
95
+ new TestCaseData ( "cat==Urgent or test=='My.Tests'" , "<or><cat>Urgent</cat><test>My.Tests</test></or>" ) ,
96
+ // Mixed And Filter with Or Filter
97
+ new TestCaseData ( "cat = Urgent || cat = High" , "<or><cat>Urgent</cat><cat>High</cat></or>" ) ,
98
+ new TestCaseData ( "cat==Urgent || test=='My.Tests' && cat == high" , "<or><cat>Urgent</cat><and><test>My.Tests</test><cat>high</cat></and></or>" ) ,
99
+ new TestCaseData ( "cat==Urgent && test=='My.Tests' || cat == high" , "<or><and><cat>Urgent</cat><test>My.Tests</test></and><cat>high</cat></or>" ) ,
100
+ new TestCaseData ( "cat==Urgent && (test=='My.Tests' || cat == high)" , "<and><cat>Urgent</cat><or><test>My.Tests</test><cat>high</cat></or></and>" ) ,
101
+ new TestCaseData ( "cat==Urgent && !(test=='My.Tests' || cat == high)" , "<and><cat>Urgent</cat><not><or><test>My.Tests</test><cat>high</cat></or></not></and>" ) ,
102
+ // Not Filter
103
+ new TestCaseData ( "!(test!='My.Tests')" , "<not><not><test>My.Tests</test></not></not>" ) ,
104
+ new TestCaseData ( "!(cat!=Urgent)" , "<not><not><cat>Urgent</cat></not></not>" )
105
+ } ;
106
+
107
+ private static IEnumerable < string > UniqueOutputs ( )
108
+ {
109
+ List < string > alreadyReturned = new List < string > ( ) ;
110
+
111
+ foreach ( var testCase in ParserTestCases )
112
+ {
113
+ var output = testCase . Arguments [ 1 ] as string ;
114
+ if ( ! alreadyReturned . Contains ( output ) )
115
+ {
116
+ alreadyReturned . Add ( output ) ;
117
+ yield return output ;
118
+ }
119
+ }
120
+ }
68
121
}
69
122
}
0 commit comments