@@ -17,6 +17,7 @@ use gluon::{
1717 base:: {
1818 ast:: { Expr , Pattern , SpannedExpr } ,
1919 filename_to_module,
20+ metadata:: BaseMetadata ,
2021 symbol:: Symbol ,
2122 types:: { ArcType , Type } ,
2223 } ,
@@ -263,6 +264,18 @@ fn gather_doc_tests(expr: &SpannedExpr<Symbol>) -> Vec<(String, String)> {
263264 }
264265
265266 struct DocVisitor ( Vec < ( String , String ) > ) ;
267+
268+ impl DocVisitor {
269+ fn make_test_from_metadata ( & mut self , name : & str , metadata : & BaseMetadata < ' _ > ) {
270+ if let Some ( comment) = & metadata. comment ( ) {
271+ let source = make_test ( & comment. content ) ;
272+ if !source. is_empty ( ) {
273+ self . 0 . push ( ( format ! ( "{}" , name) , String :: from ( source) ) ) ;
274+ }
275+ }
276+ }
277+ }
278+
266279 impl Visitor < ' _ , ' _ > for DocVisitor {
267280 type Ident = Symbol ;
268281
@@ -282,19 +295,25 @@ fn gather_doc_tests(expr: &SpannedExpr<Symbol>) -> Vec<(String, String)> {
282295 }
283296 }
284297 }
298+
285299 Expr :: TypeBindings ( binds, _) => {
286300 for bind in & * * binds {
287- if let Some ( ref comment) = bind. metadata . comment ( ) {
288- let source = make_test ( & comment. content ) ;
289- if !source. is_empty ( ) {
290- self . 0 . push ( (
291- format ! ( "{}" , bind. name. value. declared_name( ) ) ,
292- String :: from ( source) ,
293- ) ) ;
294- }
295- }
301+ self . make_test_from_metadata (
302+ bind. name . value . declared_name ( ) ,
303+ & bind. metadata ,
304+ ) ;
305+ }
306+ }
307+
308+ Expr :: Record { types, exprs, .. } => {
309+ for field in & * * types {
310+ self . make_test_from_metadata ( field. name . declared_name ( ) , & field. metadata ) ;
311+ }
312+ for field in & * * exprs {
313+ self . make_test_from_metadata ( field. name . declared_name ( ) , & field. metadata ) ;
296314 }
297315 }
316+
298317 _ => ( ) ,
299318 }
300319 walk_expr ( self , expr) ;
0 commit comments