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

Fix clippy and tests fail due to simple problems #415

Merged
merged 22 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.61.0
- uses: dtolnay/rust-toolchain@1.62.1
- run: cargo build --manifest-path=./tabled/Cargo.toml --all-features

fmt:
Expand Down
2 changes: 1 addition & 1 deletion papergrid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ std = []
ansi = ["ansi-str", "ansitok"]

[dependencies]
unicode-width = "0.1"
unicode-width = "=0.1.11"
bytecount = "0.6"
fnv = "1.0"
ansi-str = { version = "0.8", optional = true }
Expand Down
5 changes: 2 additions & 3 deletions tabled/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ license = "MIT"
keywords = ["table", "print", "pretty-table", "format", "terminal"]
categories = ["text-processing", "visualization"]
readme = "README.md"
rust-version = "1.61.0"

[badges]
coveralls = { repository = "https://github.com/zhiburt/tabled", branch = "master", service = "github" }
Expand Down Expand Up @@ -307,11 +306,11 @@ ansi = ["papergrid/ansi", "ansi-str", "ansitok", "std"]
macros = ["std"]

[dependencies]
papergrid = { version = "0.11", default-features = false }
papergrid = { path="../papergrid", default-features = false }
tabled_derive = { path = "../tabled_derive", optional = true }
ansi-str = { version = "0.8", optional = true }
ansitok = { version = "0.2", optional = true }
unicode-width = "0.1"
unicode-width = "=0.1.11"

[dev-dependencies]
owo-colors = "3.5"
Expand Down
4 changes: 2 additions & 2 deletions tabled/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ pub use crate::{tabled::Tabled, tables::Table};
/// #[derive(Tabled)]
/// struct Record {
/// #[tabled(skip)]
/// id: [u8; 4],
/// #[tabled(format("{}.{}.{}.{}.{}", self.id[0], self.id[1], self.id[2], self.id[3], self.name)]
/// id: u8,
/// #[tabled(format("{}.{}", self.id, self.name))]
Comment on lines -442 to +443
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not support formatting using complex expressions like self.id[0] so I simplified this code a bit

Copy link
Owner

@zhiburt zhiburt Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually one of my endless (not released patches) 😄
I did rewrite this support more then a few times.

I wonder what do you think in this regard.
Shall we support functions calls, array index etc?

#[tabled(format("{}.{}", some_function(self.id), self.name.one_more_field[100]))]
id: u8,

Why I did rewrote it is cause it's impossible to support in inline enums 😞
And having 2 different approaches in 2 different places seeeems like not the right approach.

#[derive(Tabled)]
enum Something {
#[tabled(inline)]
A {
   #[tabled(format("{}", self.field1, func(0, 1, self)))]  // <- impossible to complex expressions with self 
   field1: usize,
},
B {}
}

So anyway maybe you have some thoughts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by rewriting? What do we have now if this is not possible to implement for inline structs? Is this the same functionality I assumed for the test fix? If so, I'm sure that supporting more advanced formatting functionality is a good feature, but obviously, there are many complications that can affect the decision of whether it's worth implementing or not.

If you have patches that extend this functionality beyond the scope of the changed test, what should this test look like to test as much of #[tabled(format()] as possible?

/// name: String,
/// }
/// ```
Expand Down
36 changes: 0 additions & 36 deletions tabled/src/settings/width/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,39 +1438,3 @@ mod tests {
);
}
}

// \u{1b}[37mReturns \u{1b}[39m\n
// \u{1b}[37mthe floor \u{1b}[39m\n
// \u{1b}[37mof a \u{1b}[39m\n
// \u{1b}[37mnumber \u{1b}[39m\u{1b}[49m\n
// \u{1b}[37m\u{1b}[41m(l\u{1b}[39m\u{1b}[37m\u{1b}[41marg\u{1b}[39m\u{1b}[49m\u{1b}[37mest \u{1b}[39m\n
// \u{1b}[37minteger \u{1b}[39m\n
// \u{1b}[37mless than \u{1b}[39m\n
// \u{1b}[37mor equal \u{1b}[39m\n
// \u{1b}[37mto that \u{1b}[39m\n
// \u{1b}[37mnumber).\u{1b}[39m "

//
//

// \u{1b}[37mReturns \u{1b}[39m\n
// \u{1b}[37mthe floor \u{1b}[39m\n
// \u{1b}[37mof a \u{1b}[39m\n
// \u{1b}[37mnumber \u{1b}[39m\u{1b}[49m\n
// \u{1b}[37m\u{1b}[41m(l\u{1b}[39m\u{1b}[37m\u{1b}[41marg\u{1b}[39m\u{1b}[49m\u{1b}[37mest \u{1b}[39m\n
// \u{1b}[37minteger \u{1b}[39m\n
// \u{1b}[37mless than \u{1b}[39m\n
// \u{1b}[37mor equal \u{1b}[39m\n
// \u{1b}[37mto that \u{1b}[39m\n
// \u{1b}[37mnumber).\u{1b}[39m "

// "\u{1b}[37mReturns\u{1b}[37m \u{1b}[39m\n
// \u{1b}[37mthe\u{1b}[37m floor\u{1b}[37m \u{1b}[39m\n
// \u{1b}[37mof\u{1b}[37m a\u{1b}[37m \u{1b}[39m\n
// \u{1b}[37mnumber\u{1b}[37m \u{1b}[39m\u{1b}[49m\n
// \u{1b}[37m\u{1b}[41m(l\u{1b}[39m\u{1b}[37m\u{1b}[41marg\u{1b}[39m\u{1b}[49m\u{1b}[37mest\u{1b}[37m \u{1b}[39m\n
// \u{1b}[37minteger\u{1b}[37m \u{1b}[39m\n
// \u{1b}[37mless\u{1b}[37m than\u{1b}[37m \u{1b}[39m\n
// \u{1b}[37mor\u{1b}[37m equal\u{1b}[37m \u{1b}[39m\n
// \u{1b}[37mto\u{1b}[37m that\u{1b}[37m \u{1b}[39m\n
// \u{1b}[37mnumber).\u{1b}[39m "
4 changes: 2 additions & 2 deletions tabled/src/tables/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
//! assert_eq!(table, expected);
//! ```

use crate::grid::util::string::string_width;
use crate::Tabled;
use std::cell::RefCell;
use std::fmt::{self, Debug, Display};
use std::rc::Rc;
use crate::grid::util::string::string_width;
use crate::Tabled;

/// `ExtendedTable` display data in a 'expanded display mode' from postgresql.
/// It may be useful for a large data sets with a lot of fields.
Expand Down
8 changes: 4 additions & 4 deletions tabled/src/tables/table_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,10 +1625,10 @@ mod print {
pad_color: Sides<ANSIStr<'static>>,
) -> Sides<Option<ANSIStr<'static>>> {
Sides::new(
(!pad_color.left.is_empty()).then(|| pad_color.left),
(!pad_color.right.is_empty()).then(|| pad_color.right),
(!pad_color.top.is_empty()).then(|| pad_color.top),
(!pad_color.bottom.is_empty()).then(|| pad_color.bottom),
(!pad_color.left.is_empty()).then_some(pad_color.left),
(!pad_color.right.is_empty()).then_some(pad_color.right),
(!pad_color.top.is_empty()).then_some(pad_color.top),
(!pad_color.bottom.is_empty()).then_some(pad_color.bottom),
)
}

Expand Down
4 changes: 2 additions & 2 deletions tabled/src/util/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ mod tests {
assert_eq!(cut_str("🏳️🏳️", 0), "");
assert_eq!(cut_str("🏳️🏳️", 1), "🏳");
assert_eq!(cut_str("🏳️🏳️", 2), "🏳\u{fe0f}🏳");
assert_eq!(string_width("🏳️🏳️"), string_width("🏳\u{fe0f}🏳"));
assert_eq!(string_width("🏳️🏳️"), string_width("🏳\u{fe0f}🏳\u{fe0f}"));

assert_eq!(cut_str("🎓", 1), "�");
assert_eq!(cut_str("🎓", 2), "🎓");
Expand Down Expand Up @@ -258,7 +258,7 @@ mod tests {
);
assert_eq!(
string_width(&emojies),
string_width("\u{1b}[31;100m🏳\u{fe0f}🏳\u{1b}[39m\u{1b}[49m")
string_width("\u{1b}[31;100m🏳\u{fe0f}🏳\u{fe0f}\u{1b}[39m\u{1b}[49m")
);
}

Expand Down
9 changes: 2 additions & 7 deletions tabled/tests/core/extended_table_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,11 @@ fn display_with_truncate_colored() {

#[test]
fn record_template() {
build_tabled_type!(
TestType,
3,
["1", "2", "3"],
["a", "b", "c"]
);
build_tabled_type!(TestType, 3, ["1", "2", "3"], ["a", "b", "c"]);
let data: Vec<TestType> = vec![TestType, TestType];

let description = "ROW";
let table = ExtendedTable::new(&data)
let table = ExtendedTable::new(data)
.template(move |index| format!("< {} {} >", description, index + 1));
let table = table.to_string();

Expand Down
16 changes: 11 additions & 5 deletions tabled/tests/derive/derive_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ macro_rules! test_tuple {
$($($init_block)*)?

#[derive(Tabled)]
struct TestType(
$( $(#[$attr])* $ty, )*
#[allow(dead_code)]
pub struct TestType(
$( $(#[$attr]) * $ty, )*
);

let value = TestType($($init,)*);
Expand Down Expand Up @@ -244,7 +245,12 @@ mod tuple {
#[test]
fn format3() {
#[derive(Debug, Tabled)]
struct StructName(u8, #[tabled(format("foo {} {:?}", 2, self))] String);
pub struct StructName(
u8,
#[allow(dead_code)]
#[tabled(format("foo {} {:?}", 2, self))]
String,
);

let value = StructName(0, String::from("string"));

Expand Down Expand Up @@ -1055,7 +1061,7 @@ fn rename_all_variants() {
( $name:ident, $case:expr ) => {
#[derive(Tabled)]
#[tabled(rename_all = $case)]
struct $name {
pub struct $name {
field: usize,
}
};
Expand Down Expand Up @@ -1211,7 +1217,7 @@ fn test_reimport_trait_by_crate_attribute() {
#[test]
fn test_display_with_2() {
#[derive(tabled::Tabled)]
struct Struct<'a> {
pub struct Struct<'a> {
#[tabled(display_with("std::path::Path::display"))]
path: &'a std::path::Path,
}
Expand Down
2 changes: 1 addition & 1 deletion tabled/tests/settings/column_names_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ test_table!(
test_table!(
colors_empty,
Table::new([("Hello", "World"), ("and", "looooong\nword")])
.with(ColumnNames::default().color(vec![Color::default(); 0])),
.with(ColumnNames::default().color({ Color::default(); vec![] as std::vec::Vec<tabled::settings::Color> })),
"+&str---+&str------+"
"| Hello | World |"
"+-------+----------+"
Expand Down
43 changes: 20 additions & 23 deletions tabled_derive/src/parse/field_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ pub fn parse_field_attributes(
}

pub struct FieldAttr {
pub ident: Ident,
pub kind: FieldAttrKind,
}

impl FieldAttr {
pub fn new(ident: Ident, kind: FieldAttrKind) -> Self {
Self { ident, kind }
pub fn new(kind: FieldAttrKind) -> Self {
Self { kind }
}
}

Expand Down Expand Up @@ -50,14 +49,12 @@ impl Parse for FieldAttr {
let lit = input.parse::<LitStr>()?;

match name_str.as_str() {
"rename" => return Ok(Self::new(name, Rename(lit))),
"rename_all" => return Ok(Self::new(name, RenameAll(lit))),
"rename" => return Ok(Self::new(Rename(lit))),
"rename_all" => return Ok(Self::new(RenameAll(lit))),
"display_with" => {
return Ok(Self::new(name, DisplayWith(lit, None, Punctuated::new())))
}
"format" => {
return Ok(Self::new(name, FormatWith(lit, None, Punctuated::new())))
return Ok(Self::new(DisplayWith(lit, None, Punctuated::new())))
}
"format" => return Ok(Self::new(FormatWith(lit, None, Punctuated::new()))),
_ => {}
}
}
Expand All @@ -66,8 +63,8 @@ impl Parse for FieldAttr {
let lit = input.parse::<LitBool>()?;

match name_str.as_str() {
"skip" => return Ok(Self::new(name, Skip(lit))),
"inline" => return Ok(Self::new(name, Inline(lit, None))),
"skip" => return Ok(Self::new(Skip(lit))),
"inline" => return Ok(Self::new(Inline(lit, None))),
_ => {}
}
}
Expand All @@ -76,7 +73,7 @@ impl Parse for FieldAttr {
let lit = input.parse::<LitInt>()?;

if let "order" = name_str.as_str() {
return Ok(Self::new(name, Order(lit)));
return Ok(Self::new(Order(lit)));
}
}

Expand Down Expand Up @@ -111,16 +108,16 @@ impl Parse for FieldAttr {
};

if name_str.as_str() == "format" {
return Ok(Self::new(name, FormatWith(lit, comma, args)));
return Ok(Self::new(FormatWith(lit, comma, args)));
}

return Ok(Self::new(name, DisplayWith(lit, comma, args)));
return Ok(Self::new(DisplayWith(lit, comma, args)));
}
"inline" => {
return Ok(Self::new(
name,
Inline(LitBool::new(true, Span::call_site()), Some(lit)),
))
return Ok(Self::new(Inline(
LitBool::new(true, Span::call_site()),
Some(lit),
)))
}
_ => {}
}
Expand All @@ -133,12 +130,12 @@ impl Parse for FieldAttr {
}

match name_str.as_str() {
"skip" => return Ok(Self::new(name, Skip(LitBool::new(true, Span::call_site())))),
"skip" => return Ok(Self::new(Skip(LitBool::new(true, Span::call_site())))),
"inline" => {
return Ok(Self::new(
name,
Inline(LitBool::new(true, Span::call_site()), None),
))
return Ok(Self::new(Inline(
LitBool::new(true, Span::call_site()),
None,
)))
}
_ => {}
}
Expand Down
32 changes: 14 additions & 18 deletions tabled_derive/src/parse/type_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ pub fn parse_type_attributes(
}

pub struct TypeAttr {
pub ident: Ident,
pub kind: TypeAttrKind,
}

impl TypeAttr {
pub fn new(ident: Ident, kind: TypeAttrKind) -> Self {
Self { ident, kind }
pub fn new(kind: TypeAttrKind) -> Self {
Self { kind }
}
}

Expand All @@ -36,14 +35,11 @@ impl Parse for TypeAttr {
use TypeAttrKind::*;

if input.peek(syn::token::Crate) {
let crate_token: syn::token::Crate = input.parse()?;
let _: syn::token::Crate = input.parse()?;
let _ = input.parse::<Token![=]>()?;
let value = input.parse::<LitStr>()?;

return Ok(Self::new(
Ident::new("crate", crate_token.span),
Crate(value),
));
return Ok(Self::new(Crate(value)));
}

let name: Ident = input.parse()?;
Expand All @@ -56,15 +52,15 @@ impl Parse for TypeAttr {
let lit = input.parse::<LitStr>()?;

if let "rename_all" = name_str.as_str() {
return Ok(Self::new(name, RenameAll(lit)));
return Ok(Self::new(RenameAll(lit)));
}
}

if input.peek(LitBool) {
let lit = input.parse::<LitBool>()?;

if let "inline" = name_str.as_str() {
return Ok(Self::new(name, Inline(lit, None)));
return Ok(Self::new(Inline(lit, None)));
}
}

Expand All @@ -82,10 +78,10 @@ impl Parse for TypeAttr {
let lit = nested.parse::<LitStr>()?;

if let "inline" = name_str.as_str() {
return Ok(Self::new(
name,
Inline(LitBool::new(true, Span::call_site()), Some(lit)),
));
return Ok(Self::new(Inline(
LitBool::new(true, Span::call_site()),
Some(lit),
)));
}
}

Expand All @@ -96,10 +92,10 @@ impl Parse for TypeAttr {
}

if let "inline" = name_str.as_str() {
return Ok(Self::new(
name,
Inline(LitBool::new(true, Span::call_site()), None),
));
return Ok(Self::new(Inline(
LitBool::new(true, Span::call_site()),
None,
)));
}

Err(syn::Error::new(
Expand Down
2 changes: 1 addition & 1 deletion testing_table/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ ansi = ["ansitok"]

[dependencies]
ansitok = { version = "0.2", optional = true }
unicode-width = "0.1"
unicode-width = "=0.1.11"
Loading