@@ -401,3 +401,105 @@ fn llist_basic()
401401}
402402
403403// qqq : xxx : implement for other containers
404+
405+ #[ test ]
406+ fn vec_of_hashmap ( )
407+ {
408+ let data : Vec < HashMap < String , String > > = vec !
409+ [
410+ {
411+ let mut map = HashMap :: new( ) ;
412+ map. insert( "id" . to_string( ) , "1" . to_string( ) ) ;
413+ map. insert( "created_at" . to_string( ) , "1627845583" . to_string( ) ) ;
414+ map. insert( "file_ids" . to_string( ) , "[ file1, file2 ]" . to_string( ) ) ;
415+ map. insert( "tools" . to_string( ) , "" . to_string( ) ) ;
416+ map
417+ } ,
418+ {
419+ let mut map = HashMap :: new( ) ;
420+ map. insert( "id" . to_string( ) , "2" . to_string( ) ) ;
421+ map. insert( "created_at" . to_string( ) , "13" . to_string( ) ) ;
422+ map. insert( "file_ids" . to_string( ) , "[ file3, file4 ]" . to_string( ) ) ;
423+ map. insert( "tools" . to_string( ) , "tool1" . to_string( ) ) ;
424+ map
425+ } ,
426+ ] ;
427+
428+ use the_module:: Fields ;
429+
430+ use std:: borrow:: Cow ;
431+
432+ // let _ = <HashMap<std::string::String, std::string::String> as Fields<String, Option<Cow<'_, str>>>>::fields(&map);
433+
434+ use the_module:: TableFormatter ;
435+ let _as_table : AsTable < ' _ , Vec < HashMap < String , String > > , & str , HashMap < String , String > , str > = AsTable :: new ( & data ) ;
436+
437+ /*
438+ let as_table = AsTable::new( &data );
439+
440+ let rows = TableRows::rows( &as_table );
441+ assert_eq!( rows.len(), 2 );
442+
443+ let mut output = String::new();
444+ let mut context = the_module::print::Context::new( &mut output, Default::default() );
445+
446+ let _got = the_module::TableFormatter::fmt( &as_table, &mut context );
447+
448+ let got = as_table.table_to_string();
449+
450+ assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
451+ assert!( got.contains( "│ 13 │ [ │ [ │" ) );
452+ assert!( got.contains( "│ 1627845583 │ [ │ │" ) );
453+ */
454+ }
455+
456+ #[ test ]
457+ fn vec_of_hashmap_str ( )
458+ {
459+ let data : Vec < HashMap < & str , String > > = vec !
460+ [
461+ {
462+ let mut map = HashMap :: new( ) ;
463+ map. insert( "id" , "1" . to_string( ) ) ;
464+ map. insert( "created_at" , "1627845583" . to_string( ) ) ;
465+ map. insert( "file_ids" , "[ file1, file2 ]" . to_string( ) ) ;
466+ map. insert( "tools" , "" . to_string( ) ) ;
467+ map
468+ } ,
469+ {
470+ let mut map = HashMap :: new( ) ;
471+ map. insert( "id" , "2" . to_string( ) ) ;
472+ map. insert( "created_at" , "13" . to_string( ) ) ;
473+ map. insert( "file_ids" , "[ file3, file4 ]" . to_string( ) ) ;
474+ map. insert( "tools" , "tool1" . to_string( ) ) ;
475+ map
476+ } ,
477+ ] ;
478+
479+ use the_module:: Fields ;
480+
481+ use std:: borrow:: Cow ;
482+
483+ // let _ = <HashMap<std::string::String, std::string::String> as Fields<String, Option<Cow<'_, str>>>>::fields(&map);
484+
485+ use the_module:: TableFormatter ;
486+ //let _as_table : AsTable< '_, Vec< HashMap< &str, String > >, &str, HashMap< &str, String >, str> = AsTable::new( &data );
487+
488+ /*
489+ let as_table = AsTable::new( &data );
490+
491+ let rows = TableRows::rows( &as_table );
492+ assert_eq!( rows.len(), 2 );
493+
494+ let mut output = String::new();
495+ let mut context = the_module::print::Context::new( &mut output, Default::default() );
496+
497+ let _got = the_module::TableFormatter::fmt( &as_table, &mut context );
498+
499+ let got = as_table.table_to_string();
500+
501+ assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
502+ assert!( got.contains( "│ 13 │ [ │ [ │" ) );
503+ assert!( got.contains( "│ 1627845583 │ [ │ │" ) );
504+ */
505+ }
0 commit comments