@@ -182,24 +182,32 @@ def test_evaluator_bytes():
182182def test_evaluator_format ():
183183 """ Representable Object : tests that format() works """
184184
185- s = InputVar ('s' , str )
185+ # (1) the variable is the template
186+ s_tpl = InputVar ('s_tpl' , str )
186187
187188 # the str operator cannot be overloaded
188- formatted_string = s .format ('yes' )
189- formatted_string = formatted_string .as_function ()
189+ format_my_yes = s_tpl .format ('yes' )
190+ format_my_yes = format_my_yes .as_function ()
191+
192+ assert format_my_yes ('{} sure' ) == 'yes sure'
190193
191- assert formatted_string ('{}' ) == 'yes'
194+ # (2) the variable is the value
195+ s = InputVar ('s' , str )
192196
193197 # the str operator cannot be overloaded
194198 with pytest .raises (FunctionDefinitionError ):
195199 '{} {}' .format (s , s )
196200
197201 # so we provide this equivalent
198- reasonable_string = Format ('{} {}' , s , s )
202+ reasonable_string = Str . format ('{} {}' , s , s )
199203 reasonable_string = reasonable_string .as_function ()
200204
201205 assert reasonable_string ('hello' ) == 'hello hello'
202206
207+ # and there is also a Format method replacing `format`
208+ stringify = Format (s ).as_function ()
209+ assert stringify (12 ) == '12'
210+
203211
204212def test_evaluator_sizeof ():
205213 """ Object : tests that sys.getsizeof() raises the correct error message and that the equivalent Getsizeof()
0 commit comments