diff --git a/module/core/diagnostics_tools/src/diag/rta.rs b/module/core/diagnostics_tools/src/diag/rta.rs index 46b21050a2..4bd27b3bba 100644 --- a/module/core/diagnostics_tools/src/diag/rta.rs +++ b/module/core/diagnostics_tools/src/diag/rta.rs @@ -289,4 +289,3 @@ pub mod prelude }; } - diff --git a/module/core/diagnostics_tools/src/lib.rs b/module/core/diagnostics_tools/src/lib.rs index a3415c710e..8ed4ccb486 100644 --- a/module/core/diagnostics_tools/src/lib.rs +++ b/module/core/diagnostics_tools/src/lib.rs @@ -31,7 +31,6 @@ pub mod own #[ doc( inline ) ] pub use orphan::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::diag::orphan::*; } @@ -54,7 +53,6 @@ pub mod exposed #[ doc( inline ) ] pub use prelude::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::diag::exposed::*; } @@ -65,6 +63,5 @@ pub mod prelude { use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::diag::prelude::*; } diff --git a/module/core/format_tools/src/format/print.rs b/module/core/format_tools/src/format/print.rs index bc49db448d..78ac91b294 100644 --- a/module/core/format_tools/src/format/print.rs +++ b/module/core/format_tools/src/format/print.rs @@ -658,4 +658,4 @@ pub mod prelude use super::*; } -// \ No newline at end of file +// diff --git a/module/core/format_tools/tests/inc/print_test.rs b/module/core/format_tools/tests/inc/print_test.rs new file mode 100644 index 0000000000..dd45f73de8 --- /dev/null +++ b/module/core/format_tools/tests/inc/print_test.rs @@ -0,0 +1,191 @@ +#[ allow( unused_imports ) ] +use super::*; + +use the_module:: +{ + Fields, + IteratorTrait, + AsTable, + Cells, + TableSize, + TableRows, + TableHeader, + Context, + WithRef, + MaybeAs, +}; + +use std:: +{ + collections::HashMap, + borrow::Cow, +}; + +/// Struct representing a test object with various fields. +#[ derive( Clone, Debug ) ] +pub struct TestObject +{ + pub id : String, + pub created_at : i64, + pub file_ids : Vec< String >, + pub tools : Option< Vec< HashMap< String, String > > >, +} + +impl Fields< &'static str, MaybeAs< '_, str, WithRef > > +for TestObject +{ + type Value< 'v > = MaybeAs< 'v, str, WithRef >; + + fn fields( &self ) -> impl IteratorTrait< Item = ( &'static str, MaybeAs< '_, str, WithRef > ) > + { + // use format_tools::ref_or_display_or_debug_multiline::field; + use format_tools::ref_or_display_or_debug::field; + let mut dst : Vec< ( &'static str, MaybeAs< '_, str, WithRef > ) > = Vec::new(); + + dst.push( field!( &self.id ) ); + dst.push( field!( &self.created_at ) ); + dst.push( field!( &self.file_ids ) ); + + if let Some( tools ) = &self.tools + { + dst.push( field!( tools ) ); + } + else + { + dst.push( ( "tools", MaybeAs::none() ) ); + } + + dst.into_iter() + } +} + +// + +fn test_objects_gen() -> Vec< TestObject > +{ + + vec! + [ + TestObject + { + id : "1".to_string(), + created_at : 1627845583, + file_ids : vec![ "file1".to_string(), "file2".to_string() ], + tools : None + }, + TestObject + { + id : "2".to_string(), + created_at : 13, + file_ids : vec![ "file3".to_string(), "file4\nmore details".to_string() ], + tools : Some + ( + vec! + [ + { + let mut map = HashMap::new(); + map.insert( "tool1".to_string(), "value1".to_string() ); + map + }, + { + let mut map = HashMap::new(); + map.insert( "tool2".to_string(), "value2".to_string() ); + map + } + ] + ), + }, + ] + +} + +// + +#[ test ] +fn table_to_string() +// where + // for< 'a > AsTable< 'a, Vec< TestObject >, usize, TestObject, &'static str, String, &'static str > : TableFormatter< 'a >, +{ + use the_module::TableToString; + let test_objects = test_objects_gen(); + + let cells = Cells::< &'static str, WithRef >::cells( &test_objects[ 0 ] ); + assert_eq!( cells.len(), 4 ); + let cells = Cells::< &'static str, WithRef >::cells( &test_objects[ 1 ] ); + assert_eq!( cells.len(), 4 ); + drop( cells ); + + let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, WithRef > = AsTable::new( &test_objects ); + let size = TableSize::mcells( &as_table ); + assert_eq!( size, [ 2, 4 ] ); + let rows = TableRows::rows( &as_table ); + assert_eq!( rows.len(), 2 ); + dbg!( rows.collect::< Vec< _ > >() ); + let header = TableHeader::header( &as_table ); + assert!( header.is_some() ); + let header = header.unwrap(); + assert_eq!( header.len(), 4 ); + assert_eq!( header.clone().collect::< Vec< _ > >(), vec! + [ + ( "id", Cow::Owned( "id".to_string() ) ), + ( "created_at", Cow::Owned( "created_at".to_string() ) ), + ( "file_ids", Cow::Owned( "file_ids".to_string() ) ), + ( "tools", Cow::Owned( "tools".to_string() ) ) + ]); + dbg!( header.collect::< Vec< _ > >() ); + + let mut output = String::new(); + let mut context = Context::new( &mut output, Default::default() ); + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + assert!( got.is_ok() ); + println!( "{}", &output ); + + // with explicit arguments + + let as_table : AsTable< '_, Vec< TestObject >, usize, TestObject, &str, WithRef > = AsTable::new( &test_objects ); + let table_string = as_table.table_to_string(); + assert!( table_string.contains( "id" ) ); + assert!( table_string.contains( "created_at" ) ); + assert!( table_string.contains( "file_ids" ) ); + assert!( table_string.contains( "tools" ) ); + + // without explicit arguments + + println!( "" ); + let as_table = AsTable::new( &test_objects ); + let table_string = as_table.table_to_string(); + assert!( table_string.contains( "id" ) ); + assert!( table_string.contains( "created_at" ) ); + assert!( table_string.contains( "file_ids" ) ); + assert!( table_string.contains( "tools" ) ); + println!( "{table_string}" ); + +} + +#[ test ] +fn custom_formatter() +{ + // use the_module::TableToString; + let test_objects = test_objects_gen(); + + let mut output = String::new(); + let mut formatter = the_module::Styles::default(); + formatter.cell_separator = " | ".into(); + formatter.row_prefix = "> ".into(); + formatter.row_postfix = " <".into(); + + let as_table = AsTable::new( &test_objects ); + let mut context = Context::new( &mut output, formatter ); + let got = the_module::TableFormatter::fmt( &as_table, &mut context ); + assert!( got.is_ok() ); + // let table_string = got.unwrap(); + + assert!( output.contains( "id" ) ); + assert!( output.contains( "created_at" ) ); + assert!( output.contains( "file_ids" ) ); + assert!( output.contains( "tools" ) ); + println!( "{output}" ); + +} + +// xxx diff --git a/module/core/mem_tools/Cargo.toml b/module/core/mem_tools/Cargo.toml index cec41724d4..ba71b5759a 100644 --- a/module/core/mem_tools/Cargo.toml +++ b/module/core/mem_tools/Cargo.toml @@ -24,7 +24,6 @@ workspace = true features = [ "full" ] all-features = false - include = [ "/rust/impl/mem", "/Cargo.toml", diff --git a/module/core/mem_tools/src/lib.rs b/module/core/mem_tools/src/lib.rs index 03270e0a05..141da61a9d 100644 --- a/module/core/mem_tools/src/lib.rs +++ b/module/core/mem_tools/src/lib.rs @@ -37,7 +37,6 @@ pub mod own #[ doc( inline ) ] pub use orphan::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::mem::orphan::*; } @@ -60,7 +59,6 @@ pub mod exposed #[ doc( inline ) ] pub use prelude::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::mem::exposed::*; } @@ -71,6 +69,5 @@ pub mod prelude { use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super::mem::prelude::*; } diff --git a/module/core/mem_tools/src/mem.rs b/module/core/mem_tools/src/mem.rs index 8a540d97e2..3a48ddad8b 100644 --- a/module/core/mem_tools/src/mem.rs +++ b/module/core/mem_tools/src/mem.rs @@ -64,30 +64,28 @@ mod private } +#[ doc( inline ) ] +#[ allow( unused_imports ) ] +pub use own::*; + /// Own namespace of the module. #[ allow( unused_imports ) ] pub mod own { use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super:: { orphan::*, }; } -#[ doc( inline ) ] -#[ allow( unused_imports ) ] -pub use own::*; - /// Orphan namespace of the module. #[ allow( unused_imports ) ] pub mod orphan { use super::*; #[ doc( inline ) ] - #[ allow( unused_imports ) ] pub use super:: { exposed::*, @@ -103,6 +101,9 @@ pub mod orphan pub mod exposed { use super::*; + // Expose itself. + pub use super::super::mem; + #[ doc( inline ) ] pub use prelude::*; } diff --git a/module/core/test_tools/Cargo.toml b/module/core/test_tools/Cargo.toml index 01ee46f740..4f17161640 100644 --- a/module/core/test_tools/Cargo.toml +++ b/module/core/test_tools/Cargo.toml @@ -80,7 +80,7 @@ standalone = [ "standalone_collection_tools", "standalone_impls_index", "standalone_mem_tools", - "dep:mem_tools", + # "dep:mem_tools", "dep:typing_tools", "dep:diagnostics_tools", "dep:process_tools", @@ -112,8 +112,8 @@ rand = { workspace = true } error_tools = { workspace = true, features = [ "full" ], optional = true } collection_tools = { workspace = true, features = [ "full" ], optional = true } impls_index = { workspace = true, features = [ "full" ], optional = true } - mem_tools = { workspace = true, features = [ "full" ], optional = true } + typing_tools = { workspace = true, features = [ "full" ], optional = true } diagnostics_tools = { workspace = true, features = [ "full" ], optional = true } process_tools = { workspace = true, features = [ "full" ], optional = true } @@ -129,7 +129,6 @@ thiserror = { workspace = true, optional = true } hashbrown = { workspace = true, optional = true } # impls_index impls_index_meta = { workspace = true, optional = true } -# mem_tools [build-dependencies] rustc_version = "0.4" diff --git a/module/core/test_tools/src/lib.rs b/module/core/test_tools/src/lib.rs index cb0d390392..4d1b25124e 100644 --- a/module/core/test_tools/src/lib.rs +++ b/module/core/test_tools/src/lib.rs @@ -112,11 +112,16 @@ mod standalone pub mod collection; pub use collection as collection_tools; - /// impl index macroc. + /// impl and index macros. #[ path = "../../../../core/impls_index/src/impls_index/mod.rs" ] pub mod impls_index; + /// Memory tools. + #[ path = "../../../../core/mem_tools/src/mem.rs" ] + pub mod mem_tools; + } + #[ cfg( feature = "enabled" ) ] #[ cfg( feature = "standalone" ) ] pub use standalone::*; @@ -128,12 +133,12 @@ pub use :: error_tools, collection_tools, impls_index, + mem_tools, }; #[ cfg( feature = "enabled" ) ] pub use :: { - mem_tools, typing_tools, diagnostics_tools, process_tools, @@ -162,7 +167,7 @@ pub mod own { error_tools::orphan::*, collection_tools::orphan::*, - // meta_tools::orphan::*, + impls_index::orphan::*, mem_tools::orphan::*, typing_tools::orphan::*, diagnostics_tools::orphan::*, @@ -203,7 +208,7 @@ pub mod exposed { error_tools::exposed::*, collection_tools::exposed::*, - // meta_tools::exposed::*, + impls_index::exposed::*, mem_tools::exposed::*, typing_tools::exposed::*, diagnostics_tools::exposed::*, @@ -226,7 +231,7 @@ pub mod prelude { error_tools::prelude::*, collection_tools::prelude::*, - // meta_tools::prelude::*, + impls_index::prelude::*, mem_tools::prelude::*, typing_tools::prelude::*, diagnostics_tools::prelude::*, diff --git a/module/core/test_tools/tests/inc/basic_test.rs b/module/core/test_tools/tests/inc/impls_index_test.rs similarity index 100% rename from module/core/test_tools/tests/inc/basic_test.rs rename to module/core/test_tools/tests/inc/impls_index_test.rs diff --git a/module/core/test_tools/tests/inc/mem_test.rs b/module/core/test_tools/tests/inc/mem_test.rs new file mode 100644 index 0000000000..1cf4a2b724 --- /dev/null +++ b/module/core/test_tools/tests/inc/mem_test.rs @@ -0,0 +1,26 @@ +use super::*; + +// + +#[ allow( dead_code ) ] +#[ test ] +fn same_data() +{ + let buf = [ 0u8; 128 ]; + assert!( the_module::mem::same_data( &buf, &buf ) ); + + let x = [ 0u8; 1 ]; + let y = 0u8; + + assert!( the_module::mem::same_data( &x, &y ) ); + + assert!( !the_module::mem::same_data( &buf, &x ) ); + assert!( !the_module::mem::same_data( &buf, &y ) ); + + struct H1( &'static str ); + struct H2( &'static str ); + + assert!( the_module::mem::same_data( &H1( "hello" ), &H2( "hello" ) ) ); + assert!( !the_module::mem::same_data( &H1( "qwerty" ), &H2( "hello" ) ) ); + +} diff --git a/module/core/test_tools/tests/inc/mod.rs b/module/core/test_tools/tests/inc/mod.rs index bf3d2e3d78..a6d6581d75 100644 --- a/module/core/test_tools/tests/inc/mod.rs +++ b/module/core/test_tools/tests/inc/mod.rs @@ -1,8 +1,26 @@ -#[ allow( unused_imports ) ] use super::*; -mod basic_test; +mod impls_index_test; +mod mem_test; mod try_build_test; // mod wtest_utility; // qqq : include tests of all internal dependencies + +// /// Error tools. +// #[ path = "../../../../core/error_tools/tests/inc/mod.rs" ] +// pub mod error; +// pub use error as error_tools; +// +// /// Collection tools. +// #[ path = "../../../../core/collection_tools/tests/inc/mod.rs" ] +// pub mod collection; +// pub use collection as collection_tools; + +// /// impl and index macros. +// #[ path = "../../../../core/impls_index/tests/inc/mod.rs" ] +// pub mod impls_index; + +// /// Memory tools. +// #[ path = "../../../../core/mem_tools/tests/inc/mod.rs" ] +// pub mod mem_tools; diff --git a/module/core/test_tools/tests/tests.rs b/module/core/test_tools/tests/tests.rs index 3cdbd75627..c9b1261fb2 100644 --- a/module/core/test_tools/tests/tests.rs +++ b/module/core/test_tools/tests/tests.rs @@ -1,12 +1,13 @@ +#![ allow( unused_imports ) ] + // #![ deny( rust_2018_idioms ) ] // #![ deny( missing_debug_implementations ) ] // #![ deny( missing_docs ) ] -#[ allow( unused_imports ) ] use test_tools as the_module; -#[ allow( unused_imports ) ] -#[ cfg( feature = "enabled" ) ] -#[ cfg( not( feature = "no_std" ) ) ] -use test_tools::exposed::*; + +// #[ cfg( feature = "enabled" ) ] +// #[ cfg( not( feature = "no_std" ) ) ] +// use test_tools::exposed::*; mod inc; diff --git a/module/move/assistant/Cargo.toml b/module/move/assistant/Cargo.toml index 479871b6f7..64396a499c 100644 --- a/module/move/assistant/Cargo.toml +++ b/module/move/assistant/Cargo.toml @@ -47,7 +47,7 @@ mod_interface = { workspace = true, features = [ "full" ] } former = { workspace = true, features = [ "full" ] } format_tools = { workspace = true, features = [ "full" ] } reflect_tools = { workspace = true, features = [ "full" ] } -openai-api-rs = { version = "=5.0.11" } +openai-api-rs = { version = "=5.0.14" } tokio = { version = "1", features = ["full"] } dotenv = "0.15" clap = { version = "4.5.20", features = ["derive"] } diff --git a/module/move/assistant/src/bin/main.rs b/module/move/assistant/src/bin/main.rs index 69843c1ed4..345e98f8c2 100644 --- a/module/move/assistant/src/bin/main.rs +++ b/module/move/assistant/src/bin/main.rs @@ -26,7 +26,7 @@ async fn main() -> Result< (), Box< dyn Error > > let secret = Secret::load()?; - let client = client( &secret )?; + let client = client::client( &secret )?; let cli = Cli::parse();