Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUTO : Forward from refactoring_4 to alpha #1483

Merged
merged 12 commits into from
Nov 11, 2024
1 change: 0 additions & 1 deletion module/core/diagnostics_tools/src/diag/rta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,3 @@ pub mod prelude
};

}

3 changes: 0 additions & 3 deletions module/core/diagnostics_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub mod own
#[ doc( inline ) ]
pub use orphan::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::diag::orphan::*;
}

Expand All @@ -54,7 +53,6 @@ pub mod exposed
#[ doc( inline ) ]
pub use prelude::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::diag::exposed::*;
}

Expand All @@ -65,6 +63,5 @@ pub mod prelude
{
use super::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::diag::prelude::*;
}
2 changes: 1 addition & 1 deletion module/core/format_tools/src/format/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,4 @@ pub mod prelude
use super::*;
}

//
//
191 changes: 191 additions & 0 deletions module/core/format_tools/tests/inc/print_test.rs
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion module/core/mem_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ workspace = true
features = [ "full" ]
all-features = false


include = [
"/rust/impl/mem",
"/Cargo.toml",
Expand Down
3 changes: 0 additions & 3 deletions module/core/mem_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub mod own
#[ doc( inline ) ]
pub use orphan::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::mem::orphan::*;
}

Expand All @@ -60,7 +59,6 @@ pub mod exposed
#[ doc( inline ) ]
pub use prelude::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::mem::exposed::*;
}

Expand All @@ -71,6 +69,5 @@ pub mod prelude
{
use super::*;
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::mem::prelude::*;
}
13 changes: 7 additions & 6 deletions module/core/mem_tools/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand All @@ -103,6 +101,9 @@ pub mod orphan
pub mod exposed
{
use super::*;
// Expose itself.
pub use super::super::mem;

#[ doc( inline ) ]
pub use prelude::*;
}
Expand Down
5 changes: 2 additions & 3 deletions module/core/test_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 }
Expand All @@ -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"
15 changes: 10 additions & 5 deletions module/core/test_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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,
Expand Down Expand Up @@ -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::*,
Expand Down Expand Up @@ -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::*,
Expand All @@ -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::*,
Expand Down
Loading
Loading