@@ -10,18 +10,41 @@ namespace Smdn.Net.MuninPlugin;
1010
1111[ TestFixture ]
1212public partial class PluginGraphAttributesBuilderTests {
13- [ TestCase ( null , typeof ( ArgumentNullException ) ) ]
14- [ TestCase ( "" , typeof ( ArgumentException ) ) ]
15- [ TestCase ( " " , typeof ( ArgumentException ) ) ]
16- [ TestCase ( "\0 " , typeof ( ArgumentException ) ) ]
17- [ TestCase ( "\0 title" , typeof ( ArgumentException ) ) ]
18- [ TestCase ( "\n title" , typeof ( ArgumentException ) ) ]
19- [ TestCase ( "\r title" , typeof ( ArgumentException ) ) ]
20- [ TestCase ( "\t title" , typeof ( ArgumentException ) ) ]
21- [ TestCase ( "title\0 " , typeof ( ArgumentException ) ) ]
22- [ TestCase ( "title\n " , typeof ( ArgumentException ) ) ]
23- [ TestCase ( "title\r " , typeof ( ArgumentException ) ) ]
24- [ TestCase ( "title\t " , typeof ( ArgumentException ) ) ]
13+ private static System . Collections . IEnumerable YieldTestCases_WithTitle_ArgumentException ( )
14+ {
15+ yield return new object ? [ ] { null , typeof ( ArgumentNullException ) } ;
16+ yield return new object ? [ ] { "" , typeof ( ArgumentException ) } ;
17+ yield return new object ? [ ] { " " , typeof ( ArgumentException ) } ;
18+ yield return new object ? [ ] { "\0 " , typeof ( ArgumentException ) } ;
19+ yield return new object ? [ ] { "\0 title" , typeof ( ArgumentException ) } ;
20+ yield return new object ? [ ] { "\n title" , typeof ( ArgumentException ) } ;
21+ yield return new object ? [ ] { "\r title" , typeof ( ArgumentException ) } ;
22+ yield return new object ? [ ] { "\t title" , typeof ( ArgumentException ) } ;
23+ yield return new object ? [ ] { "title\0 " , typeof ( ArgumentException ) } ;
24+ yield return new object ? [ ] { "title\n " , typeof ( ArgumentException ) } ;
25+ yield return new object ? [ ] { "title\r " , typeof ( ArgumentException ) } ;
26+ yield return new object ? [ ] { "title\t " , typeof ( ArgumentException ) } ;
27+ }
28+
29+ private static System . Collections . IEnumerable YieldTestCases_WithTitle ( )
30+ {
31+ yield return new object [ ] { "t" } ;
32+ yield return new object [ ] { "title" } ;
33+ yield return new object [ ] { "Title" } ;
34+ yield return new object [ ] { "TITLE" } ;
35+ yield return new object [ ] { "title0" } ;
36+ yield return new object [ ] { "title9" } ;
37+ yield return new object [ ] { "0title" } ;
38+ yield return new object [ ] { "9title" } ;
39+ yield return new object [ ] { "title-x" } ;
40+ yield return new object [ ] { ".title." } ;
41+ yield return new object [ ] { "'title'" } ;
42+ yield return new object [ ] { "title - title" } ;
43+ yield return new object [ ] { "<title>" } ;
44+ yield return new object [ ] { "タイトル" } ;
45+ }
46+
47+ [ TestCaseSource ( nameof ( YieldTestCases_WithTitle_ArgumentException ) ) ]
2548 public void Ctor_ArgumentException ( string ? title , Type expectedTypeOfException )
2649 => Assert . That (
2750 ( ) => new PluginGraphAttributesBuilder (
@@ -43,20 +66,7 @@ IEnumerable<string> expectedAttributeList
4366 Is . EquivalentTo ( expectedAttributeList ) . Using ( ( IEqualityComparer < string > ) StringComparer . Ordinal )
4467 ) ;
4568
46- [ TestCase ( "t" ) ]
47- [ TestCase ( "title" ) ]
48- [ TestCase ( "Title" ) ]
49- [ TestCase ( "TITLE" ) ]
50- [ TestCase ( "title0" ) ]
51- [ TestCase ( "title9" ) ]
52- [ TestCase ( "0title" ) ]
53- [ TestCase ( "9title" ) ]
54- [ TestCase ( "title-x" ) ]
55- [ TestCase ( ".title." ) ]
56- [ TestCase ( "'title'" ) ]
57- [ TestCase ( "title - title" ) ]
58- [ TestCase ( "<title>" ) ]
59- [ TestCase ( "タイトル" ) ]
69+ [ TestCaseSource ( nameof ( YieldTestCases_WithTitle ) ) ]
6070 public void Ctor ( string title )
6171 => AssertBuiltGraphAttributes (
6272 new PluginGraphAttributesBuilder ( title ) ,
@@ -281,6 +291,25 @@ public void DisableUnitScaling()
281291 [ "graph_title title" , "graph_scale no" ]
282292 ) ;
283293
294+ [ TestCaseSource ( nameof ( YieldTestCases_WithTitle_ArgumentException ) ) ]
295+ public void WithTitle_ArgumentException ( string ? title , Type expectedTypeOfException )
296+ => Assert . That (
297+ ( ) => new PluginGraphAttributesBuilder ( "title" )
298+ . WithTitle ( title : title ! ) ,
299+ Throws
300+ . TypeOf ( expectedTypeOfException )
301+ . With
302+ . Property ( nameof ( ArgumentException . ParamName ) )
303+ . EqualTo ( "title" )
304+ ) ;
305+
306+ [ TestCaseSource ( nameof ( YieldTestCases_WithTitle ) ) ]
307+ public void WithTitle ( string title )
308+ => AssertBuiltGraphAttributes (
309+ new PluginGraphAttributesBuilder ( "title" ) . WithTitle ( title ) ,
310+ [ $ "graph_title { title } "]
311+ ) ;
312+
284313 [ TestCase ( null , typeof ( ArgumentNullException ) ) ]
285314 [ TestCase ( "" , typeof ( ArgumentException ) ) ]
286315 [ TestCase ( " " , typeof ( ArgumentException ) ) ]
0 commit comments