Skip to content

Commit 2abb6a4

Browse files
update for no target-os
1 parent da98c89 commit 2abb6a4

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

core/src/target_os_check.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ impl Iterator for TargetOsIterator {
8282
}
8383

8484
pub(crate) fn accept_target_os(attrs: &[Attribute], target_os: &[String]) -> bool {
85+
if target_os.is_empty() {
86+
return true;
87+
}
88+
8589
let (accepted, rejected): (Vec<_>, Vec<_>) = attrs
8690
.iter()
8791
.inspect(|attr| {
@@ -124,7 +128,7 @@ mod test {
124128
use flexi_logger::DeferredNow;
125129
use log::Record;
126130
use std::{io::Write, sync::Once};
127-
use syn::{parse_quote, ItemStruct};
131+
use syn::{parse_quote, ItemEnum, ItemStruct};
128132

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

@@ -326,4 +330,27 @@ mod test {
326330

327331
assert!(accept_target_os(&test_struct.attrs, &["android".into()]))
328332
}
333+
334+
#[test]
335+
fn test_enum_no_target_os_enabled() {
336+
init_log();
337+
338+
let test_enum: ItemEnum = parse_quote! {
339+
#[typeshare]
340+
pub enum TestEnum {
341+
#[cfg(target_os = "ios")]
342+
Variant1,
343+
#[cfg(target_os = "android")]
344+
Variant2,
345+
}
346+
};
347+
348+
let variants = test_enum
349+
.variants
350+
.iter()
351+
.map(|v| accept_target_os(&v.attrs, &[]))
352+
.collect::<Vec<_>>();
353+
354+
assert_eq!(&variants, &[true, true]);
355+
}
329356
}

0 commit comments

Comments
 (0)