From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../tests/bool_property_macro.rs | 73 ++++++++++++++++++ .../tests/enum_property_macro.rs | 87 ++++++++++++++++++++++ .../tests/tables/property_table.rsv | 3 + vendor/unic-char-property/tests/tables_tests.rs | 43 +++++++++++ 4 files changed, 206 insertions(+) create mode 100644 vendor/unic-char-property/tests/bool_property_macro.rs create mode 100644 vendor/unic-char-property/tests/enum_property_macro.rs create mode 100644 vendor/unic-char-property/tests/tables/property_table.rsv create mode 100644 vendor/unic-char-property/tests/tables_tests.rs (limited to 'vendor/unic-char-property/tests') diff --git a/vendor/unic-char-property/tests/bool_property_macro.rs b/vendor/unic-char-property/tests/bool_property_macro.rs new file mode 100644 index 000000000..7b452eea9 --- /dev/null +++ b/vendor/unic-char-property/tests/bool_property_macro.rs @@ -0,0 +1,73 @@ +// Copyright 2017 The UNIC Project Developers. +// +// See the COPYRIGHT file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[macro_use] +extern crate unic_char_property; + +#[macro_use] +extern crate unic_char_range; + +char_property! { + /// This is a test property. + pub struct MyProp(bool) { + abbr => "mp"; + long => "My_Prop"; + human => "My Property"; + + data_table_path => "tables/property_table.rsv"; + } + + /// This is the shorthand function. + pub fn is_my_prop(char) -> bool; +} + +#[test] +fn test_basics() { + assert_eq!(MyProp::of('\u{0000}').as_bool(), false); + assert_eq!(MyProp::of('\u{0065}').as_bool(), true); + + assert_eq!(is_my_prop('\u{0000}'), false); + assert_eq!(is_my_prop('\u{0065}'), true); +} + +#[cfg_attr(feature = "cargo-clippy", allow(needless_bool))] +#[test] +fn test_into_bool() { + assert!(if MyProp::of('\u{0065}').into() { + true + } else { + false + }); +} + +#[test] +fn test_from_str() { + assert_eq!("y".parse(), Ok(MyProp(true))); + assert_eq!("yes".parse(), Ok(MyProp(true))); + assert_eq!("t".parse(), Ok(MyProp(true))); + assert_eq!("true".parse(), Ok(MyProp(true))); + + assert_eq!("N".parse(), Ok(MyProp(false))); + assert_eq!("NO".parse(), Ok(MyProp(false))); + assert_eq!("F".parse(), Ok(MyProp(false))); + assert_eq!("FALSE".parse(), Ok(MyProp(false))); +} + +#[test] +fn test_display() { + use unic_char_property::BinaryCharProperty; + + assert_eq!(MyProp::of('\u{0000}').abbr_name(), "N"); + assert_eq!(MyProp::of('\u{0065}').abbr_name(), "Y"); + assert_eq!(MyProp::of('\u{0000}').long_name(), "No"); + assert_eq!(MyProp::of('\u{0065}').long_name(), "Yes"); + assert_eq!(MyProp::of('\u{0000}').human_name(), "No"); + assert_eq!(MyProp::of('\u{0065}').human_name(), "Yes"); +} diff --git a/vendor/unic-char-property/tests/enum_property_macro.rs b/vendor/unic-char-property/tests/enum_property_macro.rs new file mode 100644 index 000000000..e1caa41f5 --- /dev/null +++ b/vendor/unic-char-property/tests/enum_property_macro.rs @@ -0,0 +1,87 @@ +// Copyright 2017 The UNIC Project Developers. +// +// See the COPYRIGHT file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[macro_use] +extern crate unic_char_property; + +use unic_char_property::PartialCharProperty; + +char_property! { + pub enum MyProp { + abbr => "mp"; + long => "My_Prop"; + human => "My Property"; + + /// Variants can have multi-line documentations, + /// and/or other attributes. + Variant1 { + abbr => V1, + long => Variant_1, + human => "Variant 1", + } + + /// One line works too, or... + Variant2 { + abbr => V2, + long => Variant_2, + human => "Variant 2", + } + + Variant3 { + abbr => V3, + long => Variant_3, + human => "Variant 3", + } + } + + pub mod abbr_names for abbr; + pub mod long_names for long; +} + +impl PartialCharProperty for MyProp { + fn of(_: char) -> Option { + None + } +} + +#[test] +fn test_basic_macro_use() { + use unic_char_property::EnumeratedCharProperty; + + assert_eq!(MyProp::Variant1, abbr_names::V1); + assert_eq!(MyProp::Variant2, abbr_names::V2); + assert_eq!(MyProp::Variant3, abbr_names::V3); + + assert_eq!(MyProp::Variant1, long_names::Variant_1); + assert_eq!(MyProp::Variant2, long_names::Variant_2); + assert_eq!(MyProp::Variant3, long_names::Variant_3); + + assert_eq!(MyProp::Variant1.abbr_name(), "V1"); + assert_eq!(MyProp::Variant2.abbr_name(), "V2"); + assert_eq!(MyProp::Variant3.abbr_name(), "V3"); + + assert_eq!(MyProp::Variant1.long_name(), "Variant_1"); + assert_eq!(MyProp::Variant2.long_name(), "Variant_2"); + assert_eq!(MyProp::Variant3.long_name(), "Variant_3"); + + assert_eq!(MyProp::Variant1.human_name(), "Variant 1"); + assert_eq!(MyProp::Variant2.human_name(), "Variant 2"); + assert_eq!(MyProp::Variant3.human_name(), "Variant 3"); +} + +#[test] +fn test_fromstr_ignores_case() { + use crate::abbr_names::V1; + + assert_eq!("variant_1".parse(), Ok(V1)); + assert_eq!("VaRiAnT_1".parse(), Ok(V1)); + assert_eq!("vArIaNt_1".parse(), Ok(V1)); + assert_eq!("VARIANT_1".parse(), Ok(V1)); +} diff --git a/vendor/unic-char-property/tests/tables/property_table.rsv b/vendor/unic-char-property/tests/tables/property_table.rsv new file mode 100644 index 000000000..a4391b162 --- /dev/null +++ b/vendor/unic-char-property/tests/tables/property_table.rsv @@ -0,0 +1,3 @@ +CharDataTable::Range(&[ + (chars!(' '..='~'), ()), +]) diff --git a/vendor/unic-char-property/tests/tables_tests.rs b/vendor/unic-char-property/tests/tables_tests.rs new file mode 100644 index 000000000..d20649587 --- /dev/null +++ b/vendor/unic-char-property/tests/tables_tests.rs @@ -0,0 +1,43 @@ +// Copyright 2017 The UNIC Project Developers. +// +// See the COPYRIGHT file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[macro_use] +extern crate unic_char_range; + +use unic_char_property::tables::CharDataTable; + +#[test] +fn test_range_value_table() { + const TABLE: CharDataTable = CharDataTable::Range(&[ + (chars!('a'..='g'), 1), + (chars!('j'..='q'), 2), + (chars!('w'..='z'), 3), + ]); + for ch in chars!('a'..='g') { + assert_eq!(TABLE.find(ch), Some(1)); + assert_eq!(TABLE.find_or_default(ch), 1); + } + for ch in chars!('h'..='i') { + assert_eq!(TABLE.find(ch), None); + assert_eq!(TABLE.find_or_default(ch), 0); + } + for ch in chars!('j'..='q') { + assert_eq!(TABLE.find(ch), Some(2)); + assert_eq!(TABLE.find_or_default(ch), 2); + } + for ch in chars!('r'..='v') { + assert_eq!(TABLE.find(ch), None); + assert_eq!(TABLE.find_or_default(ch), 0); + } + for ch in chars!('x'..='z') { + assert_eq!(TABLE.find(ch), Some(3)); + assert_eq!(TABLE.find_or_default(ch), 3); + } +} -- cgit v1.2.3