mod common;
use bc_envelope::prelude::*;
use bc_envelope_pattern::{DCBORPattern, Matcher, Pattern, format_paths};
use indoc::indoc;
#[test]
fn test_bool_pattern() {
let envelope = Envelope::new(42);
assert!(!Pattern::any_bool().matches(&envelope));
assert!(!Pattern::bool(true).matches(&envelope));
assert!(!Pattern::bool(false).matches(&envelope));
let envelope = Envelope::new(true);
assert!(Pattern::any_bool().matches(&envelope));
assert!(Pattern::bool(true).matches(&envelope));
assert!(!Pattern::bool(false).matches(&envelope));
assert!(Pattern::cbor(true).matches(&envelope));
assert!(!Pattern::cbor(false).matches(&envelope));
let envelope = envelope.add_assertion("an", "assertion");
assert!(Pattern::any_bool().matches(&envelope));
assert!(Pattern::bool(true).matches(&envelope));
assert!(!Pattern::bool(false).matches(&envelope));
assert!(Pattern::cbor(true).matches(&envelope));
assert!(!Pattern::cbor(false).matches(&envelope));
let paths = Pattern::any_bool().paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
50d1019e NODE true [ "an": "assertion" ]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let paths =
Pattern::traverse(vec![Pattern::any_bool(), Pattern::any_subject()])
.paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
50d1019e NODE true [ "an": "assertion" ]
27abdedd LEAF true
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
}
#[test]
fn test_number_pattern() {
let envelope = Envelope::new("string");
assert!(!Pattern::any_number().matches(&envelope));
assert!(!Pattern::number(42).matches(&envelope));
let envelope = Envelope::new(42);
assert!(Pattern::any_number().matches(&envelope));
assert!(Pattern::number(42).matches(&envelope));
assert!(!Pattern::number(43).matches(&envelope));
assert!(Pattern::cbor(42).matches(&envelope));
assert!(!Pattern::cbor(43).matches(&envelope));
assert!(Pattern::number_range(40..=50).matches(&envelope));
assert!(!Pattern::number_range(43..=50).matches(&envelope));
assert!(Pattern::number_greater_than(41).matches(&envelope));
assert!(!Pattern::number_greater_than(42).matches(&envelope));
assert!(Pattern::number_less_than(43).matches(&envelope));
assert!(!Pattern::number_less_than(42).matches(&envelope));
assert!(Pattern::number_greater_than_or_equal(42).matches(&envelope));
assert!(!Pattern::number_greater_than_or_equal(43).matches(&envelope));
let envelope = envelope.add_assertion("an", "assertion");
assert!(Pattern::any_number().matches(&envelope));
assert!(Pattern::number(42).matches(&envelope));
let paths = Pattern::any_number().paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
6cb2ea4a NODE 42 [ "an": "assertion" ]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let paths =
Pattern::traverse(vec![Pattern::any_number(), Pattern::any_subject()])
.paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
6cb2ea4a NODE 42 [ "an": "assertion" ]
7f83f7bd LEAF 42
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
}
#[test]
fn test_text_pattern() {
let envelope = Envelope::new(42);
assert!(!Pattern::any_text().matches(&envelope));
assert!(!Pattern::text("hello").matches(&envelope));
let envelope = Envelope::new("hello");
assert!(Pattern::any_text().matches(&envelope));
assert!(Pattern::text("hello").matches(&envelope));
assert!(!Pattern::text("world").matches(&envelope));
assert!(Pattern::cbor("hello").matches(&envelope));
assert!(!Pattern::cbor("world").matches(&envelope));
let regex = regex::Regex::new(r"^h.*o$").unwrap();
assert!(Pattern::text_regex(regex.clone()).matches(&envelope));
let envelope = envelope.add_assertion("greeting", "world");
assert!(Pattern::any_text().matches(&envelope));
assert!(Pattern::text("hello").matches(&envelope));
assert!(!Pattern::text("world").matches(&envelope));
assert!(Pattern::text_regex(regex).matches(&envelope));
let paths = Pattern::any_text().paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
80a8c700 NODE "hello" [ "greeting": "world" ]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let paths =
Pattern::traverse(vec![Pattern::any_text(), Pattern::any_subject()])
.paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
80a8c700 NODE "hello" [ "greeting": "world" ]
cb835593 LEAF "hello"
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
}
#[test]
fn test_date_pattern() {
let envelope = Envelope::new("2023-12-25");
assert!(!Pattern::any_date().matches(&envelope));
let date = Date::from_ymd(2023, 12, 25);
let envelope = Envelope::new(date);
assert!(Pattern::any_date().matches(&envelope));
assert!(Pattern::date(date).matches(&envelope));
assert!(!Pattern::date(Date::from_ymd(2023, 12, 24)).matches(&envelope));
assert!(Pattern::cbor(date).matches(&envelope));
assert!(!Pattern::cbor(Date::from_ymd(2023, 12, 24)).matches(&envelope));
let start = Date::from_ymd(2023, 12, 20);
let end = Date::from_ymd(2023, 12, 30);
assert!(Pattern::date_range(start..=end).matches(&envelope));
let start = Date::from_ymd(2023, 12, 26);
let end = Date::from_ymd(2023, 12, 30);
assert!(!Pattern::date_range(start..=end).matches(&envelope));
assert!(Pattern::date_iso8601("2023-12-25").matches(&envelope));
assert!(!Pattern::date_iso8601("2023-12-24").matches(&envelope));
let regex = regex::Regex::new(r"^2023-.*").unwrap();
assert!(Pattern::date_regex(regex).matches(&envelope));
let regex = regex::Regex::new(r"^2024-.*").unwrap();
assert!(!Pattern::date_regex(regex).matches(&envelope));
let envelope = envelope.add_assertion("type", "christmas");
assert!(Pattern::any_date().matches(&envelope));
assert!(Pattern::date(date).matches(&envelope));
let paths = Pattern::any_date().paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
20f45d77 NODE 2023-12-25 [ "type": "christmas" ]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let paths =
Pattern::traverse(vec![Pattern::any_date(), Pattern::any_subject()])
.paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
20f45d77 NODE 2023-12-25 [ "type": "christmas" ]
3854ff69 LEAF 2023-12-25
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let date_with_time = Date::from_ymd_hms(2023, 12, 25, 15, 30, 45);
let envelope_with_time = Envelope::new(date_with_time);
assert!(Pattern::any_date().matches(&envelope_with_time));
assert!(
Pattern::date_iso8601("2023-12-25T15:30:45Z")
.matches(&envelope_with_time)
);
let regex = regex::Regex::new(r".*T15:30:45Z$").unwrap();
assert!(Pattern::date_regex(regex).matches(&envelope_with_time));
}
#[test]
fn test_known_value_pattern() {
use known_values;
let envelope = Envelope::new("test");
assert!(!Pattern::any_known_value().matches(&envelope));
assert!(!Pattern::known_value(known_values::DATE).matches(&envelope));
assert!(!Pattern::known_value_named("date").matches(&envelope));
let envelope = Envelope::new(known_values::DATE);
assert!(Pattern::any_known_value().matches(&envelope));
assert!(Pattern::known_value(known_values::DATE).matches(&envelope));
assert!(!Pattern::known_value(known_values::LANGUAGE).matches(&envelope));
assert!(Pattern::cbor(known_values::DATE).matches(&envelope));
assert!(!Pattern::cbor(known_values::LANGUAGE).matches(&envelope));
assert!(Pattern::known_value_named("date").matches(&envelope));
assert!(!Pattern::known_value_named("language").matches(&envelope));
let envelope = envelope.add_assertion("meaning", "timestamp");
assert!(Pattern::any_known_value().matches(&envelope));
assert!(Pattern::known_value(known_values::DATE).matches(&envelope));
assert!(Pattern::known_value_named("date").matches(&envelope));
assert!(!Pattern::known_value(known_values::LANGUAGE).matches(&envelope));
assert!(!Pattern::known_value_named("language").matches(&envelope));
let paths = Pattern::any_known_value().paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
813f39cd NODE 'date' [ "meaning": "timestamp" ]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let paths = Pattern::known_value_named("date").paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
813f39cd NODE 'date' [ "meaning": "timestamp" ]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let paths = Pattern::traverse(vec![
Pattern::any_known_value(),
Pattern::any_subject(),
])
.paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
813f39cd NODE 'date' [ "meaning": "timestamp" ]
2e40139b KNOWN_VALUE 'date'
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
assert!(!Pattern::known_value_named("unknown_name").matches(&envelope));
}
#[test]
fn test_known_value_regex_pattern() {
use regex::Regex;
let value = known_values::DATE;
let envelope =
Envelope::new(value.clone()).add_assertion("meaning", "timestamp");
let regex = Regex::new(r"^da.*").unwrap();
assert!(Pattern::known_value_regex(regex).matches(&envelope));
let regex = Regex::new(r".*te$").unwrap();
assert!(Pattern::known_value_regex(regex).matches(&envelope));
let regex = Regex::new(r"^date$").unwrap();
assert!(Pattern::known_value_regex(regex).matches(&envelope));
let regex = Regex::new(r"^lang.*").unwrap();
assert!(!Pattern::known_value_regex(regex).matches(&envelope));
let language_value = known_values::LANGUAGE;
let language_envelope = Envelope::new(language_value.clone());
let regex = Regex::new(r"lang.*").unwrap();
assert!(Pattern::known_value_regex(regex).matches(&language_envelope));
let regex = Regex::new(r"^da.*").unwrap();
assert!(!Pattern::known_value_regex(regex).matches(&language_envelope));
let text_envelope = Envelope::new("test");
let regex = Regex::new(r".*").unwrap();
assert!(!Pattern::known_value_regex(regex).matches(&text_envelope));
let regex = Regex::new(r".*te$").unwrap();
let paths = Pattern::traverse(vec![
Pattern::known_value_regex(regex),
Pattern::any_subject(),
])
.paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
813f39cd NODE 'date' [ "meaning": "timestamp" ]
2e40139b KNOWN_VALUE 'date'
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
}
#[test]
fn test_byte_string_pattern() {
let envelope = Envelope::new("string");
assert!(!Pattern::any_byte_string().matches(&envelope));
assert!(!Pattern::byte_string(vec![1, 2, 3]).matches(&envelope));
let hello_bytes = vec![0x48, 0x65, 0x6c, 0x6c, 0x6f]; let envelope = Envelope::new(CBOR::to_byte_string(hello_bytes.clone()));
assert!(Pattern::any_byte_string().matches(&envelope));
assert!(Pattern::byte_string(hello_bytes.clone()).matches(&envelope));
assert!(
Pattern::cbor(CBOR::to_byte_string(hello_bytes.clone()))
.matches(&envelope)
);
assert!(!Pattern::byte_string(vec![1, 2, 3]).matches(&envelope));
let regex = regex::bytes::Regex::new(r"^He.*o$").unwrap();
assert!(Pattern::byte_string_binary_regex(regex).matches(&envelope));
let non_matching_regex = regex::bytes::Regex::new(r"^World").unwrap();
assert!(
!Pattern::byte_string_binary_regex(non_matching_regex)
.matches(&envelope)
);
let envelope = envelope.add_assertion("type", "greeting");
assert!(Pattern::any_byte_string().matches(&envelope));
assert!(Pattern::byte_string(hello_bytes.clone()).matches(&envelope));
let regex = regex::bytes::Regex::new(r".*llo.*").unwrap();
assert!(Pattern::byte_string_binary_regex(regex).matches(&envelope));
let paths = Pattern::any_byte_string().paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
19c2bef3 NODE Bytes(5) [ "type": "greeting" ]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let paths = Pattern::traverse(vec![
Pattern::any_byte_string(),
Pattern::any_subject(),
])
.paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
19c2bef3 NODE Bytes(5) [ "type": "greeting" ]
3a91d2eb LEAF Bytes(5)
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let binary_data = vec![0x00, 0x01, 0xFF, 0xAB, 0xCD];
let binary_envelope =
Envelope::new(CBOR::to_byte_string(binary_data.clone()));
let regex = regex::bytes::Regex::new(r"(?s-u).*\xFF.*").unwrap();
assert!(Pattern::byte_string_binary_regex(regex).matches(&binary_envelope));
let regex = regex::bytes::Regex::new(r"(?s-u)\x00\x01").unwrap();
assert!(Pattern::byte_string_binary_regex(regex).matches(&binary_envelope));
let regex = regex::bytes::Regex::new(r"(?s-u)^.{5}$").unwrap();
assert!(Pattern::byte_string_binary_regex(regex).matches(&binary_envelope));
let regex = regex::bytes::Regex::new(r"(?s-u)^\xFF").unwrap();
assert!(
!Pattern::byte_string_binary_regex(regex).matches(&binary_envelope)
);
let regex = regex::bytes::Regex::new(r"(?s-u)[\x80-\xFF]").unwrap();
assert!(Pattern::byte_string_binary_regex(regex).matches(&binary_envelope));
}
#[test]
fn test_array_pattern() {
let envelope = Envelope::new("string");
assert!(!Pattern::any_array().matches(&envelope));
assert!(!Pattern::array_with_count(3).matches(&envelope));
let array = vec![1, 2, 3];
let envelope = Envelope::new(array.clone());
assert!(Pattern::cbor(array).matches(&envelope));
assert!(Pattern::any_array().matches(&envelope));
assert!(Pattern::array_with_count(3).matches(&envelope));
assert!(!Pattern::array_with_count(5).matches(&envelope));
assert!(Pattern::array_with_range(2..=4).matches(&envelope));
assert!(!Pattern::array_with_range(5..=10).matches(&envelope));
let envelope = envelope.add_assertion("type", "list");
assert!(Pattern::any_array().matches(&envelope));
assert!(Pattern::array_with_count(3).matches(&envelope));
let paths = Pattern::any_array().paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
70db8c16 NODE [1, 2, 3] [ "type": "list" ]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let empty_array = Vec::<i32>::new().to_cbor();
let empty_envelope = Envelope::new(empty_array);
assert!(Pattern::any_array().matches(&empty_envelope));
assert!(Pattern::array_with_count(0).matches(&empty_envelope));
assert!(!Pattern::array_with_count(1).matches(&empty_envelope));
let paths =
Pattern::traverse(vec![Pattern::any_array(), Pattern::any_subject()])
.paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
70db8c16 NODE [1, 2, 3] [ "type": "list" ]
4abc3113 LEAF [1, 2, 3]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
}
#[test]
fn test_map_pattern() {
let envelope = Envelope::new("string");
assert!(!Pattern::any_map().matches(&envelope));
assert!(!Pattern::map_with_count(2).matches(&envelope));
let mut map = Map::new();
map.insert("key1", "value1");
map.insert("key2", "value2");
let envelope = Envelope::new(map.clone());
assert!(Pattern::cbor(map).matches(&envelope));
assert!(Pattern::any_map().matches(&envelope));
assert!(Pattern::map_with_count(2).matches(&envelope));
assert!(!Pattern::map_with_count(3).matches(&envelope));
assert!(Pattern::map_with_range(1..=3).matches(&envelope));
assert!(!Pattern::map_with_range(5..=10).matches(&envelope));
let envelope = envelope.add_assertion("type", "dictionary");
assert!(Pattern::any_map().matches(&envelope));
assert!(Pattern::map_with_count(2).matches(&envelope));
let paths = Pattern::any_map().paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
1d96ee45 NODE {"key1": "value1", "key2": "value2"} [ "type": "dictionary" ]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let empty_map = Map::new();
let empty_envelope = Envelope::new(empty_map);
assert!(Pattern::any_map().matches(&empty_envelope));
assert!(Pattern::map_with_count(0).matches(&empty_envelope));
assert!(!Pattern::map_with_count(1).matches(&empty_envelope));
let paths =
Pattern::traverse(vec![Pattern::any_map(), Pattern::any_subject()])
.paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
1d96ee45 NODE {"key1": "value1", "key2": "value2"} [ "type": "dictionary" ]
0e16f9b4 LEAF {"key1": "value1", "key2": "value2"}
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
}
#[test]
fn test_null_pattern() {
let envelope = Envelope::new("string");
assert!(!Pattern::null().matches(&envelope));
let envelope = Envelope::null();
assert!(Pattern::null().matches(&envelope));
assert!(Pattern::cbor(CBOR::null()).matches(&envelope));
let envelope = envelope.add_assertion("type", "null_value");
assert!(Pattern::null().matches(&envelope));
let paths = Pattern::null().paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
a72948d7 NODE null [ "type": "null_value" ]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let paths =
Pattern::traverse(vec![Pattern::null(), Pattern::any_subject()])
.paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
a72948d7 NODE null [ "type": "null_value" ]
b0b2988b LEAF null
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
}
#[test]
fn test_tag_pattern() {
let envelope = Envelope::new("string");
assert!(!Pattern::any_tag().matches(&envelope));
assert!(!Pattern::tagged(100, DCBORPattern::any()).matches(&envelope));
let tagged_cbor = CBOR::to_tagged_value(100, "tagged_content");
let envelope = Envelope::new(tagged_cbor.clone());
assert!(Pattern::cbor(tagged_cbor).matches(&envelope));
assert!(Pattern::any_tag().matches(&envelope));
assert!(Pattern::tagged(100, DCBORPattern::any()).matches(&envelope));
assert!(!Pattern::tagged(200, DCBORPattern::any()).matches(&envelope));
let tag = Tag::with_value(100);
assert!(Pattern::tagged(tag, DCBORPattern::any()).matches(&envelope));
let different_tag = Tag::with_value(200);
assert!(
!Pattern::tagged(different_tag, DCBORPattern::any()).matches(&envelope)
);
let envelope = envelope.add_assertion("format", "tagged");
assert!(Pattern::any_tag().matches(&envelope));
assert!(Pattern::tagged(100, DCBORPattern::any()).matches(&envelope));
let paths = Pattern::any_tag().paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
b9457c8d NODE 100("tagged_content") [ "format": "tagged" ]
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
let paths =
Pattern::traverse(vec![Pattern::any_tag(), Pattern::any_subject()])
.paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
b9457c8d NODE 100("tagged_content") [ "format": "tagged" ]
a8e58a0d LEAF 100("tagged_content")
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
}
#[test]
fn test_tag_pattern_named() {
bc_envelope::register_tags();
let tagged_cbor = Date::from_ymd(2023, 12, 25).to_cbor();
let envelope = Envelope::new(tagged_cbor);
assert!(
Pattern::tagged_name("date", DCBORPattern::any()).matches(&envelope)
);
assert!(
!Pattern::tagged_name("unknown_tag", DCBORPattern::any())
.matches(&envelope)
);
let unregistered_tagged_cbor =
CBOR::to_tagged_value(999, "unregistered_content");
let unregistered_envelope = Envelope::new(unregistered_tagged_cbor);
assert!(
!Pattern::tagged_name("date", DCBORPattern::any())
.matches(&unregistered_envelope)
);
assert!(
!Pattern::tagged_name("unknown_tag", DCBORPattern::any())
.matches(&unregistered_envelope)
);
let text_envelope = Envelope::new("just text");
assert!(
!Pattern::tagged_name("date", DCBORPattern::any())
.matches(&text_envelope)
);
let paths =
Pattern::tagged_name("date", DCBORPattern::any()).paths(&envelope);
#[rustfmt::skip]
let expected = indoc! {r#"
3854ff69 LEAF 2023-12-25
"#}.trim();
assert_actual_expected!(format_paths(&paths), expected);
assert_eq!(paths.len(), 1);
assert_eq!(paths[0].len(), 1);
assert_eq!(paths[0][0], envelope);
let paths = Pattern::traverse(vec![
Pattern::tagged_name("date", DCBORPattern::any()),
Pattern::any_subject(),
])
.paths(&envelope);
assert_actual_expected!(format_paths(&paths), expected);
}
#[test]
fn test_tag_pattern_regex() {
bc_envelope::register_tags();
let tagged_cbor = Date::from_ymd(2023, 12, 25).to_cbor();
let envelope = Envelope::new(tagged_cbor);
let regex = regex::Regex::new(r"^da.*").unwrap();
assert!(
Pattern::tagged_regex(regex.clone(), DCBORPattern::any())
.matches(&envelope)
);
let regex = regex::Regex::new(r".*te$").unwrap();
assert!(
Pattern::tagged_regex(regex.clone(), DCBORPattern::any())
.matches(&envelope)
);
let regex = regex::Regex::new(r"^time.*").unwrap();
assert!(
!Pattern::tagged_regex(regex.clone(), DCBORPattern::any())
.matches(&envelope)
);
let unregistered_tagged_cbor =
CBOR::to_tagged_value(999, "unregistered_content");
let unregistered_envelope = Envelope::new(unregistered_tagged_cbor);
let regex = regex::Regex::new(r".*").unwrap(); assert!(
!Pattern::tagged_regex(regex.clone(), DCBORPattern::any())
.matches(&unregistered_envelope)
);
let text_envelope = Envelope::new("just text");
let regex = regex::Regex::new(r".*").unwrap();
assert!(
!Pattern::tagged_regex(regex.clone(), DCBORPattern::any())
.matches(&text_envelope)
);
let regex = regex::Regex::new(r"^da.*").unwrap();
let paths =
Pattern::tagged_regex(regex, DCBORPattern::any()).paths(&envelope);
assert_eq!(paths.len(), 1);
assert_eq!(paths[0].len(), 1);
assert_eq!(paths[0][0], envelope);
let regex = regex::Regex::new(r".*te$").unwrap();
let paths = Pattern::traverse(vec![
Pattern::tagged_regex(regex, DCBORPattern::any()),
Pattern::any_subject(),
])
.paths(&envelope);
assert_eq!(paths.len(), 1);
assert_eq!(paths[0].len(), 1);
assert_eq!(paths[0][0], envelope);
}
#[test]
fn test_tag_pattern_with_bc_components_tags() {
bc_envelope::register_tags();
let digest_tag_value = 40001u64; let tagged_cbor =
CBOR::to_tagged_value(digest_tag_value, [1u8, 2, 3, 4].as_slice());
let envelope = Envelope::new(tagged_cbor);
let pattern = Pattern::tagged_name("digest", DCBORPattern::any());
let matches = pattern.matches(&envelope);
let regex = regex::Regex::new(r".*digest.*").unwrap();
let pattern_regex = Pattern::tagged_regex(regex, DCBORPattern::any());
let matches_regex = pattern_regex.matches(&envelope);
assert!(
Pattern::tagged(digest_tag_value, DCBORPattern::any())
.matches(&envelope)
);
assert!(Pattern::any_tag().matches(&envelope));
println!(
"Digest tag {} matches by name: {}",
digest_tag_value, matches
);
println!(
"Digest tag {} matches by regex: {}",
digest_tag_value, matches_regex
);
}