Skip to content

Commit e67220c

Browse files
committed
fixing format_tools
1 parent 41f1a9f commit e67220c

File tree

7 files changed

+52
-198
lines changed

7 files changed

+52
-198
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Customizable format of printing table.
22
//!
3-
//! # Example of ordinary format
3+
//! # Example of table format
44
//!
55
//! ```text
66
//! sid | sname | gap
@@ -74,13 +74,13 @@ mod private
7474
#[ inline( always ) ]
7575
fn default() -> Self
7676
{
77-
super::ordinary::Ordinary::instance()
77+
super::table::Table::instance()
7878
}
7979
}
8080

8181
}
8282

83-
mod ordinary;
83+
mod table;
8484
mod records;
8585

8686
#[ allow( unused_imports ) ]
@@ -97,7 +97,7 @@ pub mod own
9797
#[ doc( inline ) ]
9898
pub use
9999
{
100-
ordinary::Ordinary,
100+
table::Table,
101101
records::Records,
102102
};
103103

module/core/format_tools/src/format/output_format/ordinary.rs renamed to module/core/format_tools/src/format/output_format/table.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::sync::OnceLock;
2424

2525
/// A struct representing the classic table output format.
2626
///
27-
/// `Ordinary` provides a standard implementation for table formatting,
27+
/// `Table` provides a standard implementation for table formatting,
2828
/// supporting a classic style with default settings.
2929
///
3030
/// # Example
@@ -37,7 +37,7 @@ use std::sync::OnceLock;
3737
/// 10 | Boris | 5
3838
/// ```
3939
#[ derive( Debug ) ]
40-
pub struct Ordinary
40+
pub struct Table
4141
{
4242
/// Delimitting header with grid line or not.
4343
pub delimitting_header : bool,
@@ -77,7 +77,7 @@ pub struct Ordinary
7777
pub corner_rb : char,
7878
}
7979

80-
impl Default for Ordinary
80+
impl Default for Table
8181
{
8282
fn default() -> Self
8383
{
@@ -127,30 +127,30 @@ impl Default for Ordinary
127127
}
128128
}
129129

130-
impl Default for &'static Ordinary
130+
impl Default for &'static Table
131131
{
132132
fn default() -> Self
133133
{
134134
// qqq : find a better solution
135-
static STYLES : OnceLock< Ordinary > = OnceLock::new();
135+
static STYLES : OnceLock< Table > = OnceLock::new();
136136
STYLES.get_or_init( ||
137137
{
138-
Ordinary::default()
138+
Table::default()
139139
})
140140
}
141141
}
142142

143-
impl Ordinary
143+
impl Table
144144
{
145145

146-
/// Returns a reference to a static instance of `Ordinary`.
146+
/// Returns a reference to a static instance of `Table`.
147147
///
148-
/// This method provides access to a single shared instance of `Ordinary`,
148+
/// This method provides access to a single shared instance of `Table`,
149149
/// ensuring efficient reuse of the classic table output format.
150150
pub fn instance() -> & 'static dyn TableOutputFormat
151151
{
152152

153-
static INSTANCE : OnceLock< Ordinary > = OnceLock::new();
153+
static INSTANCE : OnceLock< Table > = OnceLock::new();
154154
INSTANCE.get_or_init( ||
155155
{
156156
Self::default()
@@ -159,7 +159,7 @@ impl Ordinary
159159
}
160160
}
161161

162-
impl TableOutputFormat for Ordinary
162+
impl TableOutputFormat for Table
163163
{
164164
fn extract_write< 'buf, 'data >( &self, x : &InputExtract< 'data >, c : &mut Context< 'buf > ) -> fmt::Result
165165
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ mod private
166166
/// A `String` containing the formatted table.
167167
fn table_to_string( &'data self ) -> String
168168
{
169-
self.table_to_string_with_format( &output_format::Ordinary::default() )
169+
self.table_to_string_with_format( &output_format::Table::default() )
170170
}
171171

172172
/// Converts the table to a string representation specifying printer.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn custom_format()
9999
// use the_module::TableFormatter;
100100
let test_objects = test_object::test_objects_gen();
101101

102-
let mut format = output_format::Ordinary::default();
102+
let mut format = output_format::Table::default();
103103
format.cell_prefix = "( ".into();
104104
format.cell_postfix = " )".into();
105105
format.cell_separator = "|".into();
@@ -140,7 +140,7 @@ fn custom_format()
140140

141141
use the_module::TableFormatter;
142142

143-
let mut format = output_format::Ordinary::default();
143+
let mut format = output_format::Table::default();
144144
format.cell_prefix = "( ".into();
145145
format.cell_postfix = " )".into();
146146
format.cell_separator = "|".into();
@@ -175,7 +175,7 @@ fn filter_col_none()
175175
{
176176
let test_objects = test_object::test_objects_gen();
177177

178-
let mut format = output_format::Ordinary::default();
178+
let mut format = output_format::Table::default();
179179
format.cell_prefix = "( ".into();
180180
format.cell_postfix = " )".into();
181181
format.cell_separator = "|".into();
@@ -210,7 +210,7 @@ fn filter_col_callback()
210210
{
211211
let test_objects = test_object::test_objects_gen();
212212

213-
let mut format = output_format::Ordinary::default();
213+
let mut format = output_format::Table::default();
214214
format.cell_prefix = "( ".into();
215215
format.cell_postfix = " )".into();
216216
format.cell_separator = "|".into();
@@ -254,7 +254,7 @@ fn filter_row_none()
254254
{
255255
let test_objects = test_object::test_objects_gen();
256256

257-
let mut format = output_format::Ordinary::default();
257+
let mut format = output_format::Table::default();
258258
format.cell_prefix = "( ".into();
259259
format.cell_postfix = " )".into();
260260
format.cell_separator = "|".into();
@@ -286,7 +286,7 @@ fn filter_row_callback()
286286
{
287287
let test_objects = test_object::test_objects_gen();
288288

289-
let mut format = output_format::Ordinary::default();
289+
let mut format = output_format::Table::default();
290290
format.cell_prefix = "( ".into();
291291
format.cell_postfix = " )".into();
292292
format.cell_separator = "|".into();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ mod fundamental
77
use super::*;
88

99
mod test_object;
10-
mod test_object_without_impl;
1110

1211
mod table_test;
1312
mod tabe_foreign_test;

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#[ allow( unused_imports ) ]
21
use super::*;
32

43
use the_module::
@@ -18,7 +17,7 @@ use std::
1817
//
1918

2019
#[ test ]
21-
fn iterator_over_optional_cow()
20+
fn iterator_over_objects_without_impl()
2221
{
2322
use the_module::TestObjectWithoutImpl as TestObjectWithoutImpl;
2423
use the_module::
@@ -28,6 +27,7 @@ fn iterator_over_optional_cow()
2827
TableWithFields,
2928
WithRef,
3029
OptionalCow,
30+
output_format,
3131
};
3232

3333
#[ derive( Debug, Clone ) ]
@@ -78,7 +78,10 @@ fn iterator_over_optional_cow()
7878

7979
let mut output = String::new();
8080
let mut context = the_module::print::Context::new( &mut output, Default::default() );
81-
let _got = the_module::TableFormatter::fmt( &as_table, &mut context );
81+
let _result = the_module::TableFormatter::fmt( &as_table, &mut context );
82+
83+
// = output as table
84+
8285
let got = as_table.table_to_string();
8386
assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
8487
assert!( got.contains( "│ 13 │ [ │ [ │" ) );
@@ -89,4 +92,28 @@ fn iterator_over_optional_cow()
8992
assert!( got.contains( "│ 13 │ [ │ [ │" ) );
9093
assert!( got.contains( "│ 1627845583 │ [ │ │" ) );
9194

95+
let got = AsTable::new( &data ).table_to_string_with_format( &output_format::Table::default() );
96+
assert!( got.contains( "│ id │ created_at │ file_ids │ tools │" ) );
97+
assert!( got.contains( "│ 13 │ [ │ [ │" ) );
98+
assert!( got.contains( "│ 1627845583 │ [ │ │" ) );
99+
100+
// = output as records
101+
102+
// let format = output_format::Records::default();
103+
let mut output = String::new();
104+
let format = the_module::output_format::Records::default();
105+
let printer = the_module::print::Printer::with_format( &format );
106+
let mut context = the_module::print::Context::new( &mut output, printer );
107+
let got = the_module::TableFormatter::fmt( &as_table, &mut context );
108+
assert!( got.is_ok() );
109+
println!( "{}", &output );
110+
111+
let got = AsTable::new( &data ).table_to_string_with_format( &output_format::Records::default() );
112+
assert!( got.contains( "│ id │ 1 │" ) );
113+
assert!( got.contains( "│ created_at │ 1627845583 │" ) );
114+
assert!( got.contains( "│ id │ 2 │" ) );
115+
assert!( got.contains( "│ created_at │ 13 │" ) );
116+
117+
// assert!( false );
118+
92119
}

0 commit comments

Comments
 (0)