@@ -193,7 +193,7 @@ mod tests {
193193 location: ast:: Location :: new( 1 , 1 ) ,
194194 node: ast:: Statement :: Expression {
195195 expression: ast:: Expression :: Lambda {
196- args: vec![ String :: from( "x" ) , String :: from( "y" ) ] ,
196+ args: vec![ ( String :: from( "x" ) , None ) , ( String :: from( "y" ) , None ) ] ,
197197 body: Box :: new( ast:: Expression :: Binop {
198198 a: Box :: new( ast:: Expression :: Identifier {
199199 name: String :: from( "x" ) ,
@@ -211,25 +211,46 @@ mod tests {
211211
212212 #[ test]
213213 fn test_parse_class ( ) {
214- let source = String :: from ( "class Foo(A, B):\n def __init__(self):\n pass\n " ) ;
214+ let source = String :: from ( "class Foo(A, B):\n def __init__(self):\n pass\n def method_with_default(self, arg='default'): \n pass \n " ) ;
215215 assert_eq ! (
216216 parse_statement( & source) ,
217217 Ok ( ast:: LocatedStatement {
218218 location: ast:: Location :: new( 1 , 1 ) ,
219219 node: ast:: Statement :: ClassDef {
220220 name: String :: from( "Foo" ) ,
221- args: vec![ String :: from( "A" ) , String :: from( "B" ) ] ,
222- body: vec![ ast:: LocatedStatement {
223- location: ast:: Location :: new( 2 , 2 ) ,
224- node: ast:: Statement :: FunctionDef {
225- name: String :: from( "__init__" ) ,
226- args: vec![ String :: from( "self" ) ] ,
227- body: vec![ ast:: LocatedStatement {
228- location: ast:: Location :: new( 3 , 3 ) ,
229- node: ast:: Statement :: Pass ,
230- } ] ,
221+ args: vec![ ( String :: from( "A" ) , None ) , ( String :: from( "B" ) , None ) ] ,
222+ body: vec![
223+ ast:: LocatedStatement {
224+ location: ast:: Location :: new( 2 , 2 ) ,
225+ node: ast:: Statement :: FunctionDef {
226+ name: String :: from( "__init__" ) ,
227+ args: vec![ ( String :: from( "self" ) , None ) ] ,
228+ body: vec![ ast:: LocatedStatement {
229+ location: ast:: Location :: new( 3 , 3 ) ,
230+ node: ast:: Statement :: Pass ,
231+ } ] ,
232+ }
233+ } ,
234+ ast:: LocatedStatement {
235+ location: ast:: Location :: new( 4 , 2 ) ,
236+ node: ast:: Statement :: FunctionDef {
237+ name: String :: from( "method_with_default" ) ,
238+ args: vec![
239+ ( String :: from( "self" ) , None ) ,
240+ (
241+ String :: from( "arg" ) ,
242+ Some ( ast:: Expression :: String {
243+ value: "default" . to_string( )
244+ } )
245+ )
246+ ] ,
247+ body: vec![ ast:: LocatedStatement {
248+ location: ast:: Location :: new( 5 , 3 ) ,
249+ node: ast:: Statement :: Pass ,
250+ } ] ,
251+ }
231252 }
232- } ] ,
253+ ] ,
233254 }
234255 } )
235256 )
0 commit comments