Skip to content

Commit

Permalink
update for no target-os
Browse files Browse the repository at this point in the history
  • Loading branch information
darrell-roberts committed Nov 11, 2024
1 parent da98c89 commit 2abb6a4
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion core/src/target_os_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ impl Iterator for TargetOsIterator {
}

pub(crate) fn accept_target_os(attrs: &[Attribute], target_os: &[String]) -> bool {
if target_os.is_empty() {
return true;
}

let (accepted, rejected): (Vec<_>, Vec<_>) = attrs
.iter()
.inspect(|attr| {
Expand Down Expand Up @@ -124,7 +128,7 @@ mod test {
use flexi_logger::DeferredNow;
use log::Record;
use std::{io::Write, sync::Once};
use syn::{parse_quote, ItemStruct};
use syn::{parse_quote, ItemEnum, ItemStruct};

static INIT: Once = Once::new();

Expand Down Expand Up @@ -326,4 +330,27 @@ mod test {

assert!(accept_target_os(&test_struct.attrs, &["android".into()]))
}

#[test]
fn test_enum_no_target_os_enabled() {
init_log();

let test_enum: ItemEnum = parse_quote! {
#[typeshare]
pub enum TestEnum {
#[cfg(target_os = "ios")]
Variant1,
#[cfg(target_os = "android")]
Variant2,
}
};

let variants = test_enum
.variants
.iter()
.map(|v| accept_target_os(&v.attrs, &[]))
.collect::<Vec<_>>();

assert_eq!(&variants, &[true, true]);
}
}

0 comments on commit 2abb6a4

Please sign in to comment.