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

Update ron to 0.9 #518

Merged
merged 2 commits into from
Mar 23, 2025
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 ron_to_table/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ derive = ["tabled/derive"]
macros = ["tabled/macros"]

[dependencies]
ron = "0.8"
ron = "0.9"
tabled = { path = "../tabled", features = ["std"], default-features = false }

[dev-dependencies]
Expand Down
38 changes: 34 additions & 4 deletions ron_to_table/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,25 @@ fn convert_value_to_table_value(value: &Value, ctx: CollapseCtx) -> TableValue {
Value::Seq(list) => convert_list(list, ctx),
Value::Bool(value) => TableValue::Cell(value.to_string()),
Value::Char(char) => TableValue::Cell(char.to_string()),
Value::Number(Number::Integer(number)) => TableValue::Cell(number.to_string()),
Value::Number(Number::Float(number)) => TableValue::Cell(number.get().to_string()),
Value::String(text) => TableValue::Cell(text.to_owned()),
Value::Unit => TableValue::Cell(String::new()),
Value::Bytes(bytes) => TableValue::Cell(format!("{:?}", bytes)),
Value::Number(num) => {
let value = match num {
Number::I8(num) => num.to_string(),
Number::I16(num) => num.to_string(),
Number::I32(num) => num.to_string(),
Number::I64(num) => num.to_string(),
Number::U8(num) => num.to_string(),
Number::U16(num) => num.to_string(),
Number::U32(num) => num.to_string(),
Number::U64(num) => num.to_string(),
Number::F32(num) => num.get().to_string(),
Number::F64(num) => num.get().to_string(),
};

TableValue::Cell(value)
}
}
}

Expand Down Expand Up @@ -386,8 +401,23 @@ fn _plain_table(value: &Value, cfg: &RonTable, outer: bool) -> String {
Value::String(text) => string_table(text.to_owned(), config, outer),
Value::Bool(val) => string_table(val.to_string(), config, outer),
Value::Char(char) => string_table(char.to_string(), config, outer),
Value::Number(Number::Integer(num)) => string_table(num.to_string(), config, outer),
Value::Number(Number::Float(num)) => string_table(num.get().to_string(), config, outer),
Value::Bytes(bytes) => string_table(format!("{:?}", bytes), config, outer),
Value::Number(num) => {
let value = match num {
Number::I8(num) => num.to_string(),
Number::I16(num) => num.to_string(),
Number::I32(num) => num.to_string(),
Number::I64(num) => num.to_string(),
Number::U8(num) => num.to_string(),
Number::U16(num) => num.to_string(),
Number::U32(num) => num.to_string(),
Number::U64(num) => num.to_string(),
Number::F32(num) => num.get().to_string(),
Number::F64(num) => num.get().to_string(),
};

string_table(value, config, outer)
}
}
}

Expand Down
20 changes: 14 additions & 6 deletions ron_to_table/tests/collapse_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::iter::FromIterator;

use ron::{value::Float, Map, Number, Value};
use ron::{value::F32, Map, Number, Value};
use tabled::assert::test_table;
use tabled::settings::Alignment;

Expand Down Expand Up @@ -48,18 +48,26 @@ test_table!(

test_table!(
test_int,
build_ron_table(Value::Number(Number::Integer(123456789))),
build_ron_table(Value::Number(Number::U64(123456789))),
"+-----------+"
"| 123456789 |"
"+-----------+"
);

test_table!(
test_float,
build_ron_table(Value::Number(Number::Float(Float::new(123.456789)))),
"+------------+"
"| 123.456789 |"
"+------------+"
build_ron_table(Value::Number(Number::F32(F32::new(123.45679)))),
"+-----------+"
"| 123.45679 |"
"+-----------+"
);

test_table!(
test_bytes,
build_ron_table(Value::Bytes(vec![1, 2, 3, 4, 5])),
"+-----------------+"
"| [1, 2, 3, 4, 5] |"
"+-----------------+"
);

test_table!(
Expand Down
38 changes: 29 additions & 9 deletions ron_to_table/tests/plain_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::iter::FromIterator;

use ron::{value::Float, Map, Number, Value};
use ron::{value::F32, Map, Number, Value};
use tabled::assert::test_table;
use tabled::settings::Alignment;

Expand All @@ -11,37 +11,57 @@ test_table!(test_unit, build_ron_table(Value::Unit).to_string(), "");
test_table!(
test_string,
build_ron_table(Value::String(String::from("123456789"))),
"+-----------+\n| 123456789 |\n+-----------+"
"+-----------+"
"| 123456789 |"
"+-----------+"
);

test_table!(
test_bool_true,
build_ron_table(Value::Bool(true)),
"+------+\n| true |\n+------+"
"+------+"
"| true |"
"+------+"
);

test_table!(
test_bool_false,
build_ron_table(Value::Bool(false)),
"+-------+\n| false |\n+-------+"
"+-------+"
"| false |"
"+-------+"
);

test_table!(
test_char,
build_ron_table(Value::Char('a')),
"+---+\n| a |\n+---+"
"+---+"
"| a |"
"+---+"
);

test_table!(
test_int,
build_ron_table(Value::Number(Number::Integer(123456789))),
"+-----------+\n| 123456789 |\n+-----------+"
build_ron_table(Value::Number(Number::U32(123456789))),
"+-----------+"
"| 123456789 |"
"+-----------+"
);

test_table!(
test_float,
build_ron_table(Value::Number(Number::Float(Float::new(123.456789)))),
"+------------+\n| 123.456789 |\n+------------+"
build_ron_table(Value::Number(Number::F32(F32(123.45679)))),
"+-----------+"
"| 123.45679 |"
"+-----------+"
);

test_table!(
test_bytes,
build_ron_table(Value::Bytes(vec![1, 2, 3, 4, 5])),
"+-----------------+"
"| [1, 2, 3, 4, 5] |"
"+-----------------+"
);

test_table!(
Expand Down
Loading