proxmox/proxmox-sortable-macro/tests/test.rs
Wolfgang Bumiller 7f4d223a4a rename sorted-data to proxmox-sortable_macro
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2019-11-21 13:10:37 +01:00

29 lines
801 B
Rust

use proxmox_sortable_macro::sortable;
// The way #[sorted] works we require an 'identity' macro due to the inability of the syntax tree
// visitor to change the type of a syntax tree element.
//
// Iow.: it replaces `sorted!([3, 2, 1])` with `identity!([1, 2, 3])`.
macro_rules! identity {
($($x:tt)*) => { $($x)* }
}
// In a normal project we would use this Cargo.toml line:
//
// [dependencies]
// proxmox = { version = "0.1", features = [ "sortable-macro" ] }
//
// Then:
// use proxmox::{sortable, identity};
#[test]
fn test_id() {
#[sortable]
const FOO: [&str; 3] = sorted!(["3", "2", "1"]);
assert_eq!(FOO, ["1", "2", "3"]);
#[sortable]
const FOO2: [(&str, usize); 3] = sorted!([("3", 1), ("2", 2), ("1", 3)]);
assert_eq!(FOO2, [("1", 3), ("2", 2), ("3", 1)]);
}