Skip to content

Commit d1f2ed7

Browse files
committed
fixing format_tools
1 parent 321d512 commit d1f2ed7

File tree

5 files changed

+89
-25
lines changed

5 files changed

+89
-25
lines changed

module/core/format_tools/src/format/md_math.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//! Provides functionality for converting multidimensional indices into flat offsets,
44
//! useful for operations involving multidimensional arrays or grids.
55
6+
// xxx : use crate mdmath
7+
68
/// Internal namespace.
79
mod private
810
{

module/core/format_tools/tests/inc/collection_test.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use the_module::
66
AsTable,
77
TableRows,
88
WithRef,
9-
print,
9+
// the_module::print,
1010
};
1111

1212
use std::
@@ -63,7 +63,7 @@ fn dlist_basic()
6363
assert_eq!( rows.len(), 2 );
6464

6565
let mut output = String::new();
66-
let mut context = print::Context::new( &mut output, Default::default() );
66+
let mut context = the_module::print::Context::new( &mut output, Default::default() );
6767
let _got = the_module::TableFormatter::fmt( &as_table, &mut context );
6868
let got = as_table.table_to_string();
6969
assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
@@ -119,7 +119,7 @@ fn hmap_basic()
119119
assert_eq!( rows.len(), 2 );
120120

121121
let mut output = String::new();
122-
let mut context = print::Context::new( &mut output, Default::default() );
122+
let mut context = the_module::print::Context::new( &mut output, Default::default() );
123123
let _got = the_module::TableFormatter::fmt( &as_table, &mut context );
124124
let got = as_table.table_to_string();
125125
assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
@@ -175,7 +175,7 @@ fn bmap_basic()
175175
assert_eq!( rows.len(), 2 );
176176

177177
let mut output = String::new();
178-
let mut context = print::Context::new( &mut output, Default::default() );
178+
let mut context = the_module::print::Context::new( &mut output, Default::default() );
179179
let _got = the_module::TableFormatter::fmt( &as_table, &mut context );
180180
let got = as_table.table_to_string();
181181
assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
@@ -229,7 +229,7 @@ fn bset_basic()
229229
assert_eq!( rows.len(), 2 );
230230

231231
let mut output = String::new();
232-
let mut context = print::Context::new( &mut output, Default::default() );
232+
let mut context = the_module::print::Context::new( &mut output, Default::default() );
233233
let _got = the_module::TableFormatter::fmt( &as_table, &mut context );
234234
let got = as_table.table_to_string();
235235
assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
@@ -283,7 +283,7 @@ fn deque_basic()
283283
assert_eq!( rows.len(), 2 );
284284

285285
let mut output = String::new();
286-
let mut context = print::Context::new( &mut output, Default::default() );
286+
let mut context = the_module::print::Context::new( &mut output, Default::default() );
287287
let _got = the_module::TableFormatter::fmt( &as_table, &mut context );
288288
let got = as_table.table_to_string();
289289
assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
@@ -337,7 +337,7 @@ fn hset_basic()
337337
assert_eq!( rows.len(), 2 );
338338

339339
let mut output = String::new();
340-
let mut context = print::Context::new( &mut output, Default::default() );
340+
let mut context = the_module::print::Context::new( &mut output, Default::default() );
341341
let _got = the_module::TableFormatter::fmt( &as_table, &mut context );
342342
let got = as_table.table_to_string();
343343
assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
@@ -391,7 +391,7 @@ fn llist_basic()
391391
assert_eq!( rows.len(), 2 );
392392

393393
let mut output = String::new();
394-
let mut context = print::Context::new( &mut output, Default::default() );
394+
let mut context = the_module::print::Context::new( &mut output, Default::default() );
395395
let _got = the_module::TableFormatter::fmt( &as_table, &mut context );
396396
let got = as_table.table_to_string();
397397
assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );

module/core/format_tools/tests/inc/table_test.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,65 @@ fn basic()
4545
dbg!( header.collect::< Vec< _ > >() );
4646

4747
}
48+
49+
//
50+
51+
#[ test ]
52+
fn dlist_basic()
53+
{
54+
use test_object::TestObject;
55+
56+
let data : collection_tools::Vec< TestObject > = dlist!
57+
{
58+
TestObject
59+
{
60+
id : "1".to_string(),
61+
created_at : 1627845583,
62+
file_ids : vec![ "file1".to_string(), "file2".to_string() ],
63+
tools : None
64+
},
65+
TestObject
66+
{
67+
id : "2".to_string(),
68+
created_at : 13,
69+
file_ids : vec![ "file3".to_string(), "file4\nmore details".to_string() ],
70+
tools : Some
71+
(
72+
vec!
73+
[
74+
{
75+
let mut map = HashMap::new();
76+
map.insert( "tool1".to_string(), "value1".to_string() );
77+
map
78+
},
79+
{
80+
let mut map = HashMap::new();
81+
map.insert( "tool2".to_string(), "value2".to_string() );
82+
map
83+
}
84+
]
85+
),
86+
},
87+
};
88+
89+
use the_module::TableFormatter;
90+
let _as_table : AsTable< '_, Vec< TestObject >, &str, TestObject, str, WithRef > = AsTable::new( &data );
91+
let as_table = AsTable::new( &data );
92+
93+
let rows = TableRows::rows( &as_table );
94+
assert_eq!( rows.len(), 2 );
95+
96+
let mut output = String::new();
97+
let mut context = the_module::print::Context::new( &mut output, Default::default() );
98+
let _got = the_module::TableFormatter::fmt( &as_table, &mut context );
99+
let got = as_table.table_to_string();
100+
assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
101+
assert!( got.contains( "│ 13 │ [ │ [ │" ) );
102+
assert!( got.contains( "│ 1627845583 │ [ │ │" ) );
103+
104+
// let got = AsTable::new( &data ).table_to_string();
105+
// assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
106+
// assert!( got.contains( "│ 13 │ [ │ [ │" ) );
107+
// assert!( got.contains( "│ 1627845583 │ [ │ │" ) );
108+
109+
}

module/core/format_tools/tests/inc/test_object.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,38 +61,38 @@ for TestObject
6161

6262
}
6363

64-
impl Hash for TestObject
64+
impl Hash for TestObject
6565
{
6666

67-
fn hash< H: Hasher >( &self, state: &mut H )
67+
fn hash< H: Hasher >( &self, state: &mut H )
6868
{
6969
self.id.hash( state );
7070
self.created_at.hash( state );
7171
self.file_ids.hash( state );
7272

73-
if let Some( tools ) = &self.tools
73+
if let Some( tools ) = &self.tools
7474
{
75-
for tool in tools
75+
for tool in tools
7676
{
77-
for ( key, value ) in tool
77+
for ( key, value ) in tool
7878
{
7979
key.hash( state );
8080
value.hash( state );
8181
}
8282
}
83-
}
84-
else
83+
}
84+
else
8585
{
8686
state.write_u8( 0 );
8787
}
8888
}
8989

9090
}
9191

92-
impl PartialEq for TestObject
92+
impl PartialEq for TestObject
9393
{
9494

95-
fn eq( &self, other: &Self ) -> bool
95+
fn eq( &self, other: &Self ) -> bool
9696
{
9797
self.id == other.id &&
9898
self.created_at == other.created_at &&
@@ -102,31 +102,31 @@ impl PartialEq for TestObject
102102

103103
}
104104

105-
impl Eq for TestObject
105+
impl Eq for TestObject
106106
{
107107
}
108108

109-
impl PartialOrd for TestObject
109+
impl PartialOrd for TestObject
110110
{
111-
112-
fn partial_cmp( &self, other: &Self ) -> Option< Ordering >
111+
112+
fn partial_cmp( &self, other: &Self ) -> Option< Ordering >
113113
{
114114
Some( self.cmp( other ) )
115115
}
116116

117117
}
118118

119-
impl Ord for TestObject
119+
impl Ord for TestObject
120120
{
121121

122-
fn cmp( &self, other: &Self ) -> Ordering
122+
fn cmp( &self, other: &Self ) -> Ordering
123123
{
124124
self.id
125125
.cmp( &other.id )
126126
.then_with( | | self.created_at.cmp( &other.created_at ) )
127127
.then_with( | | self.file_ids.cmp( &other.file_ids ) )
128128
}
129-
129+
130130
}
131131

132132
//

module/core/test_tools/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ mod private {}
8787
prelude use ::collection_tools as collection;
8888
// prelude use ::process_tools as process;
8989

90-
use ::collection_tools;
90+
use ::collection_tools; // xxx : do that for all dependencies
9191

9292
prelude use ::meta_tools::
9393
{

0 commit comments

Comments
 (0)