@@ -23,6 +23,8 @@ def setUp(self):
2323 self .o = VariousParameters ()
2424
2525 def test_0_1_args (self ):
26+ import System
27+ from Merlin .Testing import Flag
2628
2729 # public void M100() { Flag.Set(10); }
2830 f = self .o .M100
@@ -95,6 +97,9 @@ def test_0_1_args(self):
9597 self .assertRaisesMessage (TypeError , "M202() got an unexpected keyword argument 'arg'" , lambda : f (** {'arg' : 3 }))# msg
9698 self .assertRaisesMessage (TypeError , "M202() got an unexpected keyword argument 'other'" , lambda : f (** {'other' : 4 }))
9799
100+ ar_int = System .Array [System .Int32 ](3 )
101+ f (ar_int ); Flag .Check (3 )
102+
98103 # public void M203([ParamDictionaryAttribute] IDictionary<object, object> arg) { Flag.Set(arg.Count); }
99104 f = self .o .M203
100105 f ()
@@ -106,8 +111,17 @@ def test_0_1_args(self):
106111 f (** {'a' :2 , 'b' :3 })
107112 f (a = 1 , ** {'b' :2 , 'c' :5 })
108113 self .assertRaisesMessage (TypeError , "M203() got multiple values for keyword argument 'a'" , lambda : f (a = 1 , ** {'a' :2 , 'c' :5 }))
109- self .assertRaisesMessage (TypeError , "M203() takes no arguments (3 given)" , lambda : f (* (1 ,2 ,3 )))
114+ self .assertRaisesMessage (TypeError , "M203() takes no arguments (3 given)" , lambda : f (* (1 ,2 ,3 ))) # msg: no positional arguments
115+ dict_obj = System .Collections .Generic .Dictionary [System .Object , System .Object ]()
116+ self .assertRaisesMessage (TypeError , "M203() takes no arguments (1 given)" , lambda : f (dict_obj )) # msg: no positional arguments
110117
118+ # public void M204(params object[] arg)
119+ f = self .o .M204
120+
121+ ar_obj = System .Array [System .Object ](3 )
122+ f (ar_obj ); Flag .Check (3 )
123+ f (ar_obj , ar_obj ); Flag .Check (2 )
124+ f (ar_int ); Flag .Check (1 )
111125
112126 def test_optional (self ):
113127 import System
@@ -230,7 +244,7 @@ def test_two_args(self):
230244 # TODO: mixed
231245 f (x = 1 ) # check the value
232246
233- #public void M351(int x, [ParamDictionary] IDictionary<object, object> arg ) { Flag<object>.Set(arg ); }
247+ #public void M351(int x, [ParamDictionary] IDictionary<object, object> y ) { Flag<object>.Set(y ); }
234248 f = self .o .M351
235249 self .assertRaisesMessage (TypeError , "M351() takes exactly 1 argument (0 given)" , lambda : f ())
236250 f (1 ); self .assertEqual (Flag [object ].Value1 , {})
@@ -240,7 +254,7 @@ def test_two_args(self):
240254 f (x = 1 ); self .assertEqual (Flag [object ].Value1 , {})
241255 f (** {'x' : 1 }); self .assertEqual (Flag [object ].Value1 , {})
242256
243- #public void M352([ParamDictionary] IDictionary<object, object> arg , params int [] x ) { Flag<object>.Set(arg ); }
257+ #public void M352([ParamDictionary] IDictionary<object, object> x , params object [] y ) { Flag<object>.Set(x ); }
244258
245259 f = self .o .M352
246260 f (); self .assertEqual (Flag [object ].Value1 , {})
@@ -269,20 +283,22 @@ def test_default_values_2(self):
269283
270284 f (1 , ** {'y' :2 }); Flag .Check (3 )
271285
272- # public void M320([DefaultParameterValue(40)] int y , int x ) { Flag.Set(x + y); }
286+ # public void M320([DefaultParameterValue(40)] int x , int y ) { Flag.Set(x + y); }
273287 f = self .o .M320
274288 self .assertRaisesMessage (TypeError , "M320() takes at least 1 argument (0 given)" , f )
275289 f (1 ); Flag .Check (41 ) # !!!
276290 f (2 , 3 ); Flag .Check (5 )
277291 self .assertRaisesMessage (TypeError , "M320() takes at most 2 arguments (3 given)" , lambda : f (1 , 2 , 3 ))
278292
279- f (x = 2 ); Flag .Check (42 )
293+ f (y = 2 ); Flag .Check (42 )
294+ f (y = 2 , x = 3 ); Flag .Check (5 )
280295 f (x = 2 , y = 3 ); Flag .Check (5 )
281296 f (* (1 ,)); Flag .Check (41 )
282297 f (* (1 , 2 )); Flag .Check (3 )
283298
284- self .assertRaisesMessage (TypeError , "Argument for M320() given by name ('y') and position (1)" , lambda : f (5 , y = 6 )) # !!!
285- f (6 , x = 7 ); Flag .Check (13 )
299+ self .assertRaisesMessage (TypeError , "Argument for M320() given by name ('x') and position (1)" , lambda : f (5 , x = 6 )) # !!!
300+ self .assertRaisesMessage (TypeError , "M320() got an unexpected keyword argument 'x'" , lambda : f (x = 6 )) # !!!
301+ f (6 , y = 7 ); Flag .Check (13 )
286302
287303 # public void M330([DefaultParameterValue(50)] int x, [DefaultParameterValue(60)] int y) { Flag.Set(x + y); }
288304 f = self .o .M330
@@ -362,6 +378,13 @@ def test_3_args(self):
362378 #f(*(1, 2, 0, 1), **{'z':3, 'y':4}) # FIXME: M550() takes at least 2 arguments (6 given) => e.g. Argument for M550() given by name ('x') and position (1)
363379 #f(*(1, 2, 0, 1), **{'z':3, 'x':4}) # FIXME: M550() takes at least 2 arguments (6 given) => e.g. Argument for M550() given by name ('x') and position (1)
364380
381+ # public void M560(int x, [ParamDictionary] IDictionary<string, int> y, params int[] z) { Flag.Set(x * 100 + y.Count * 10 + z.Length); }
382+ f = self .o .M560
383+ f (2 , 3 , 4 , a = 5 , b = 6 , c = 7 ); Flag .Check (2 * 100 + 3 * 10 + 2 )
384+ self .assertRaisesMessage (TypeError , "Argument for M560() given by name ('x') and position (1)" , lambda : f (2 , 3 , 4 , x = 4 , b = 6 , c = 7 ))
385+ f (2 , 3 , 4 , y = 5 , b = 6 , c = 7 ); Flag .Check (2 * 100 + 3 * 10 + 2 )
386+ f (2 , 3 , 4 , z = 5 , b = 6 , c = 7 ); Flag .Check (2 * 100 + 3 * 10 + 2 )
387+
365388 def test_many_args (self ):
366389 from Merlin .Testing import Flag
367390 #public void M650(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10) { }
0 commit comments