cli-table
cli-table copied to clipboard
binary operation `==` cannot be applied to type `TableStruct`
Hi again! :)
In my other issue I was trying to write an integration test and verify that the correct std output was printed to the console.
Now I would like to write a unit test for my function that returns a TableStruct.
My function render_table uses some hardcoded data to return a TableStruct. I was thinking that it could be nice to recreate the proper TableStruct, with bold settings and all, in my unit test and then assert that the actual returned TableStruct is the same as the expected TableStruct.
#[cfg(test)]
mod table_renderer_tests {
use crate::table_renderer::render_table;
use cli_table::{Cell, Style, Table, TableStruct, format::Justify};
#[test]
fn renders_table() {
assert_eq!(render_table(), expected_table());
Ok(());
}
fn expected_table() -> TableStruct {
vec![
vec!(
"Ergonomic Office Chair".cell(),
"$199.99".cell().justify(Justify::Center),
"Black".cell().justify(Justify::Center),
20.cell().justify(Justify::Right),
),
vec!(
"Bucket Seat Gaming Chair".cell(),
"$249.99".cell().justify(Justify::Center),
"Turquoise".cell().justify(Justify::Center),
3.cell().justify(Justify::Right),
),
vec!(
"Curl Swivel Accent Chair".cell(),
"$407.96".cell().justify(Justify::Center),
"Orange".cell().justify(Justify::Center),
2.cell().justify(Justify::Right),
),
vec!(
"Velvet High Back Rocking Chair".cell(),
"$113.99".cell().justify(Justify::Center),
"Blue".cell().justify(Justify::Center),
1.cell().justify(Justify::Right),
),
vec!(
"Velvet High Back Rocking Chair".cell(),
"$27.99".cell().justify(Justify::Center),
"Grey".cell().justify(Justify::Center),
5.cell().justify(Justify::Right),
),
]
.table()
.title(vec![
"Name".cell().bold(true),
"Price".cell().bold(true),
"Color".cell().bold(true),
"Quantity".cell().bold(true),
])
.bold(true)
}
}
When I run this though, I get the error that I can't compare TableStructs with assert_eq!... 🤔
error[E0369]: binary operation `==` cannot be applied to type `TableStruct`
--> src/bin/table_of_chairs/table_renderer.rs:37:9
|
37 | assert_eq!(render_table(), expected_table());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| TableStruct
| TableStruct
|
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
Is there any recommended way for me to easily compare two TableStructs?
Thanks!