@@ -13,3 +13,87 @@ pub fn split_features(features: FeaturesMap) -> (FeaturesMap, FeaturesMap) {
1313 . any ( |v| v. starts_with ( "dep:" ) || v. contains ( "?/" ) )
1414 } )
1515}
16+
17+ #[ cfg( test) ]
18+ mod tests {
19+ use super :: * ;
20+ use insta:: assert_compact_debug_snapshot;
21+
22+ #[ test]
23+ fn test_split_features_no_deps ( ) {
24+ let mut features = FeaturesMap :: new ( ) ;
25+ features. insert (
26+ "feature1" . to_string ( ) ,
27+ vec ! [ "val1" . to_string( ) , "val2" . to_string( ) ] ,
28+ ) ;
29+ features. insert ( "feature2" . to_string ( ) , vec ! [ "val3" . to_string( ) ] ) ;
30+
31+ let ( features, features2) = split_features ( features) ;
32+
33+ assert_compact_debug_snapshot ! ( features, @r#"{"feature1": ["val1", "val2"], "feature2": ["val3"]}"# ) ;
34+ assert_compact_debug_snapshot ! ( features2, @"{}" ) ;
35+ }
36+
37+ #[ test]
38+ fn test_split_features_with_deps ( ) {
39+ let mut features = FeaturesMap :: new ( ) ;
40+ features. insert (
41+ "feature1" . to_string ( ) ,
42+ vec ! [ "dep:val1" . to_string( ) , "val2" . to_string( ) ] ,
43+ ) ;
44+ features. insert (
45+ "feature2" . to_string ( ) ,
46+ vec ! [ "val3" . to_string( ) , "val4?/val5" . to_string( ) ] ,
47+ ) ;
48+
49+ let ( features, features2) = split_features ( features) ;
50+
51+ assert_compact_debug_snapshot ! ( features, @"{}" ) ;
52+ assert_compact_debug_snapshot ! ( features2, @r#"{"feature1": ["dep:val1", "val2"], "feature2": ["val3", "val4?/val5"]}"# ) ;
53+ }
54+
55+ #[ test]
56+ fn test_split_features_mixed ( ) {
57+ let mut features = FeaturesMap :: new ( ) ;
58+ features. insert (
59+ "feature1" . to_string ( ) ,
60+ vec ! [ "val1" . to_string( ) , "val2" . to_string( ) ] ,
61+ ) ;
62+ features. insert ( "feature2" . to_string ( ) , vec ! [ "dep:val3" . to_string( ) ] ) ;
63+ features. insert (
64+ "feature3" . to_string ( ) ,
65+ vec ! [ "val4" . to_string( ) , "val5?/val6" . to_string( ) ] ,
66+ ) ;
67+
68+ let ( features, features2) = split_features ( features) ;
69+
70+ assert_compact_debug_snapshot ! ( features, @r#"{"feature1": ["val1", "val2"]}"# ) ;
71+ assert_compact_debug_snapshot ! ( features2, @r#"{"feature2": ["dep:val3"], "feature3": ["val4", "val5?/val6"]}"# ) ;
72+ }
73+
74+ #[ test]
75+ fn test_split_features_nested ( ) {
76+ let mut features = FeaturesMap :: new ( ) ;
77+ features. insert ( "feature1" . to_string ( ) , vec ! [ "feature2" . to_string( ) ] ) ;
78+ features. insert ( "feature2" . to_string ( ) , vec ! [ ] ) ;
79+ features. insert ( "feature3" . to_string ( ) , vec ! [ "feature1" . to_string( ) ] ) ;
80+
81+ let ( features, features2) = split_features ( features) ;
82+
83+ assert_compact_debug_snapshot ! ( features, @r#"{"feature1": ["feature2"], "feature2": [], "feature3": ["feature1"]}"# ) ;
84+ assert_compact_debug_snapshot ! ( features2, @"{}" ) ;
85+ }
86+
87+ #[ test]
88+ fn test_split_features_nested_mixed ( ) {
89+ let mut features = FeaturesMap :: new ( ) ;
90+ features. insert ( "feature1" . to_string ( ) , vec ! [ "feature2" . to_string( ) ] ) ;
91+ features. insert ( "feature2" . to_string ( ) , vec ! [ "feature3" . to_string( ) ] ) ;
92+ features. insert ( "feature3" . to_string ( ) , vec ! [ "dep:foo" . to_string( ) ] ) ;
93+
94+ let ( features, features2) = split_features ( features) ;
95+
96+ assert_compact_debug_snapshot ! ( features, @r#"{"feature1": ["feature2"], "feature2": ["feature3"]}"# ) ;
97+ assert_compact_debug_snapshot ! ( features2, @r#"{"feature3": ["dep:foo"]}"# ) ;
98+ }
99+ }
0 commit comments