@@ -19,17 +19,6 @@ public void Load_NullSeed()
1919 } ) ;
2020 }
2121
22- [ Test ]
23- public void Load_MissingModuleName ( )
24- {
25- var seed = WithSeed ( "MissingModuleName" ) ;
26-
27- Should . Throw < FormatException > ( ( ) =>
28- {
29- SeedLoader . Load ( seed ) ;
30- } ) ;
31- }
32-
3322 [ Test ]
3423 public void Load_Empty ( )
3524 {
@@ -57,40 +46,141 @@ public void Load_Typical()
5746 loadedSeed . Seed . ShouldBeSameAs ( seed ) ;
5847 loadedSeed . Modules . AssignTo ( out var modules ) ;
5948
60- modules . Length . ShouldBe ( 3 ) ;
49+ modules . Length . ShouldBe ( 4 ) ;
50+
6151 modules [ 0 ] . Name . ShouldBe ( "(init)" ) ;
52+ modules [ 0 ] . WorkerId . ShouldBe ( 0 ) ;
6253 modules [ 0 ] . Provides . ShouldBeEmpty ( ) ;
6354 modules [ 0 ] . Requires . ShouldBeEmpty ( ) ;
6455 modules [ 0 ] . Batches . ShouldHaveSingleItem ( ) ;
6556 modules [ 0 ] . Batches [ 0 ] . ShouldBe ( ""
6657 + "PRINT 'This is in the initial module.';" + Eol
6758 ) ;
6859
69- modules [ 1 ] . Name . ShouldBe ( "a" ) ;
70- modules [ 1 ] . Provides . ShouldBe ( ImmutableArray . Create ( "x" , "y" ) ) ;
60+ modules [ 1 ] . Name . ShouldBe ( "init-worker" ) ;
61+ modules [ 1 ] . WorkerId . ShouldBe ( - 1 ) ;
62+ modules [ 1 ] . Provides . ShouldBeEmpty ( ) ;
7163 modules [ 1 ] . Requires . ShouldBeEmpty ( ) ;
7264 modules [ 1 ] . Batches . ShouldHaveSingleItem ( ) ;
7365 modules [ 1 ] . Batches [ 0 ] . ShouldBe ( ""
66+ + "--# WORKER: all" + Eol
67+ + "PRINT 'This is in an all-worker module.';" + Eol
68+ ) ;
69+
70+ modules [ 2 ] . Name . ShouldBe ( "a" ) ;
71+ modules [ 2 ] . WorkerId . ShouldBe ( 0 ) ;
72+ modules [ 2 ] . Provides . ShouldBe ( ImmutableArray . Create ( "x" , "y" , "z" ) ) ;
73+ modules [ 2 ] . Requires . ShouldBeEmpty ( ) ;
74+ modules [ 2 ] . Batches . ShouldHaveSingleItem ( ) ;
75+ modules [ 2 ] . Batches [ 0 ] . ShouldBe ( ""
7476 + "--# PROVIDES: x y" + Eol
7577 + "--# provides: y x" + Eol
7678 + "--# Provides:" + Eol
7779 + "PRINT 'This is in module a.';" + Eol
7880 + "PRINT 'The value of ''foo'' is bar.';" + Eol
81+ + "-- The value of foo is bar." + Eol
7982 ) ;
8083 // TODO: I don't think the magic comment should be included in the batch text.
8184
82- modules [ 2 ] . Name . ShouldBe ( "b" ) ;
83- modules [ 2 ] . Provides . ShouldBeEmpty ( ) ;
84- modules [ 2 ] . Requires . ShouldBe ( ImmutableArray . Create ( "x" , "y" ) ) ;
85- modules [ 2 ] . Batches . ShouldHaveSingleItem ( ) ;
86- modules [ 2 ] . Batches [ 0 ] . ShouldBe ( ""
87- + "--# REQUIRES: x y" + Eol
88- + "--# requires: y x" + Eol
85+ modules [ 3 ] . Name . ShouldBe ( "b" ) ;
86+ modules [ 3 ] . WorkerId . ShouldBe ( 0 ) ;
87+ modules [ 3 ] . Provides . ShouldBeEmpty ( ) ;
88+ modules [ 3 ] . Requires . ShouldBe ( ImmutableArray . Create ( "x" , "y" , "z" ) ) ;
89+ modules [ 3 ] . Batches . ShouldHaveSingleItem ( ) ;
90+ modules [ 3 ] . Batches [ 0 ] . ShouldBe ( ""
91+ + "--# REQUIRES: x y z" + Eol
92+ + "--# requires: z y x" + Eol
8993 + "--# Requires: " + Eol
9094 + "PRINT 'This is in module b.';" + Eol
9195 ) ;
9296 }
9397
98+ [ Test ]
99+ public void Load_ModuleNameMissing ( )
100+ {
101+ var seed = WithSeed ( "MissingModuleName" ) ;
102+
103+ Should . Throw < FormatException > ( ( ) =>
104+ {
105+ SeedLoader . Load ( seed ) ;
106+ } ) ;
107+ }
108+
109+ [ Test ]
110+ public void Load_WorkerAll ( )
111+ {
112+ var seed = WithSeed ( "WorkerAll" ) ;
113+ var loaded = SeedLoader . Load ( seed ) ;
114+
115+ loaded . Seed . ShouldBeSameAs ( seed ) ;
116+ loaded . Modules . AssignTo ( out var modules ) ;
117+
118+ modules . Length . ShouldBe ( 2 ) ;
119+
120+ modules [ 0 ] . Name . ShouldBe ( "(init)" ) ;
121+ modules [ 0 ] . WorkerId . ShouldBe ( 0 ) ;
122+ modules [ 0 ] . Provides . ShouldBeEmpty ( ) ;
123+ modules [ 0 ] . Requires . ShouldBeEmpty ( ) ;
124+ modules [ 0 ] . Batches . ShouldBeEmpty ( ) ;
125+
126+ modules [ 1 ] . Name . ShouldBe ( "init-worker" ) ;
127+ modules [ 1 ] . WorkerId . ShouldBe ( - 1 ) ;
128+ modules [ 1 ] . Provides . ShouldBeEmpty ( ) ;
129+ modules [ 1 ] . Requires . ShouldBeEmpty ( ) ;
130+ modules [ 1 ] . Batches . ShouldHaveSingleItem ( ) ;
131+ modules [ 1 ] . Batches [ 0 ] . ShouldBe ( "--# WORKER: all" + Eol ) ;
132+ }
133+
134+ [ Test ]
135+ public void Load_WorkerAny ( )
136+ {
137+ var seed = WithSeed ( "WorkerAny" ) ;
138+ var loaded = SeedLoader . Load ( seed ) ;
139+
140+ loaded . Seed . ShouldBeSameAs ( seed ) ;
141+ loaded . Modules . AssignTo ( out var modules ) ;
142+
143+ modules . Length . ShouldBe ( 1 ) ;
144+
145+ modules [ 0 ] . Name . ShouldBe ( "(init)" ) ;
146+ modules [ 0 ] . WorkerId . ShouldBe ( 0 ) ;
147+ modules [ 0 ] . Provides . ShouldBeEmpty ( ) ;
148+ modules [ 0 ] . Requires . ShouldBeEmpty ( ) ;
149+ modules [ 0 ] . Batches . ShouldHaveSingleItem ( ) ;
150+ modules [ 0 ] . Batches [ 0 ] . ShouldBe (
151+ "--# worker: ANY" + Eol
152+ ) ;
153+ }
154+
155+ [ Test ]
156+ public void Load_WorkerMultipleArgs ( )
157+ {
158+ var path = WithSeed ( "WorkerMultipleArgs" ) ;
159+
160+ Should . Throw < FormatException > ( ( ) =>
161+ {
162+ SeedLoader . Load ( path ) ;
163+ } )
164+ . Message . ShouldBe (
165+ "The WORKER magic comment expects exactly one argument."
166+ ) ;
167+ }
168+
169+ [ Test ]
170+ public void Load_WorkerInvalid ( )
171+ {
172+ var seed = WithSeed ( "WorkerInvalid" ) ;
173+
174+ Should . Throw < FormatException > ( ( ) =>
175+ {
176+ SeedLoader . Load ( seed ) ;
177+ } )
178+ . Message . ShouldBe (
179+ "The WORKER magic comment argument must be 'all' or 'any', " +
180+ "case-insensitive, without quotes."
181+ ) ;
182+ }
183+
94184 private static Seed WithSeed ( string name )
95185 {
96186 var path = Path . Combine (
0 commit comments