Skip to content

Commit 4f24f7b

Browse files
committed
test no-default-feature
1 parent 818de4e commit 4f24f7b

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,17 @@ pub mod tests {
515515

516516
// ** Test structs
517517

518+
#[cfg(feature = "map")]
519+
type Child2Map = HashMap<i32, Child2>;
520+
#[cfg(not(feature = "map"))]
521+
type Child2Map = ();
522+
518523
#[derive(Debug, Clone, PartialEq)]
519524
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
520525
pub struct Parent {
521526
pub c1: Child1,
522527
pub c2: Vec<Child1>,
523-
pub c3: HashMap<i32, Child2>,
528+
pub c3: Child2Map,
524529
pub val: String,
525530
}
526531

@@ -571,7 +576,7 @@ pub mod tests {
571576
pub struct ParentDiff<'a> {
572577
pub c1: <Child1 as Diffable<'a>>::Diff,
573578
pub c2: <Vec<Child1> as Diffable<'a>>::Diff,
574-
pub c3: <HashMap<i32, Child2> as Diffable<'a>>::Diff,
579+
pub c3: <Child2Map as Diffable<'a>>::Diff,
575580
pub val: <String as Diffable<'a>>::Diff,
576581
}
577582

@@ -708,6 +713,7 @@ pub mod tests {
708713

709714
#[test]
710715
fn smoke_test() {
716+
#[cfg(feature = "map")]
711717
fn dummy_child2() -> Child2 {
712718
Child2 {
713719
a: "ayeaye".into(),
@@ -728,6 +734,7 @@ pub mod tests {
728734
x: 234,
729735
y: "yazoo".into(),
730736
}],
737+
#[cfg(feature = "map")]
731738
c3: [(
732739
321,
733740
Child2 {
@@ -738,6 +745,8 @@ pub mod tests {
738745
)]
739746
.into_iter()
740747
.collect(),
748+
#[cfg(not(feature = "map"))]
749+
c3: (),
741750
val: "hello".into(),
742751
};
743752

@@ -760,14 +769,18 @@ pub mod tests {
760769
let expect = DeepDiff::Patched(ParentDiff {
761770
c1: DeepDiff::Unchanged,
762771
c2: VecDiff::Unchanged,
772+
#[cfg(feature = "map")]
763773
c3: DeepDiff::Unchanged,
774+
#[cfg(not(feature = "map"))]
775+
c3: Id::new(),
764776
val: AtomicDiff::Replaced(&mello),
765777
});
766778
assert_eq!(diff, expect);
767779
assert!(p3.apply(&diff).is_ok());
768780
assert_eq!(p3, p4);
769781
}
770782

783+
#[cfg(feature = "map")]
771784
{
772785
let mut p5 = base.clone();
773786
let dummy = dummy_child2();
@@ -789,6 +802,7 @@ pub mod tests {
789802
assert_eq!(err, [ApplyError::MissingKey, ApplyError::UnexpectedKey]);
790803
}
791804

805+
#[cfg(feature = "map")]
792806
{
793807
let mut map1 = BTreeMap::new();
794808
let map2 = BTreeMap::from([("hello", "world")]);

src/serde_visit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(feature = "map")]
12
use std::{
23
cmp::Ord,
34
collections::{BTreeMap, HashMap},
@@ -420,7 +421,10 @@ pub mod tests {
420421
y: "y2".into(),
421422
},
422423
],
424+
#[cfg(feature = "map")]
423425
c3: HashMap::new(),
426+
#[cfg(not(feature = "map"))]
427+
c3: (),
424428
val: "val".into(),
425429
};
426430

@@ -452,6 +456,7 @@ pub mod tests {
452456
}
453457

454458
#[test]
459+
#[cfg(feature = "map")]
455460
fn test_kv_visitor() {
456461
let map1: BTreeMap<_, _> = [("x", 123), ("y", 234)].into_iter().collect();
457462
let map2: BTreeMap<_, _> = [("x", 321), ("y", 234), ("z", 345)].into_iter().collect();

tests/integration.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct SingleFieldC {
7878
reason = "We are specifically testing this behavior"
7979
)]
8080
mod just_check_they_compile {
81+
#[cfg(feature = "map")]
8182
use std::collections::{BTreeMap, HashMap};
8283

8384
use crate::{NotDiffable, SimpleStruct};
@@ -120,6 +121,7 @@ mod just_check_they_compile {
120121
}
121122

122123
#[derive(difficient::Diffable, PartialEq, Debug, Clone)]
124+
#[cfg(feature = "map")]
123125
struct HasHashMap {
124126
map1: HashMap<i32, i32>,
125127
map2: BTreeMap<i32, i32>,

0 commit comments

Comments
 (0)