@@ -38,3 +38,56 @@ impl SizTypesBuilder {
38
38
Ok ( self . builder . build ( ) ?)
39
39
}
40
40
}
41
+
42
+ #[ cfg( test) ]
43
+ mod tests {
44
+ use super :: * ;
45
+
46
+ #[ test]
47
+ fn test_filter_types_single ( ) -> Result < ( ) > {
48
+ let mut stb = SizTypesBuilder :: new ( ) ;
49
+
50
+ assert ! ( stb. builder. definitions( ) . len( ) == 0 ) ;
51
+
52
+ let matcher = stb. filter_types ( & vec ! [ String :: from( "rust" ) ] ) ?;
53
+
54
+ // requested types are whitelisted
55
+ assert ! ( matcher. matched( "foo.rs" , false ) . is_whitelist( ) ) ;
56
+ assert ! ( matcher. matched( "foo.py" , false ) . is_ignore( ) ) ;
57
+ // and non-requested types are ignored
58
+ assert ! ( matcher. matched( "foo" , false ) . is_ignore( ) ) ;
59
+ Ok ( ( ) )
60
+ }
61
+
62
+ #[ test]
63
+ fn test_filter_types_multiple ( ) -> Result < ( ) > {
64
+ let mut stb = SizTypesBuilder :: new ( ) ;
65
+
66
+ assert ! ( stb. builder. definitions( ) . len( ) == 0 ) ;
67
+
68
+ let matcher = stb. filter_types ( & vec ! [ String :: from( "rust" ) , String :: from( "py" ) ] ) ?;
69
+
70
+ // requested types are whitelisted
71
+ assert ! ( matcher. matched( "foo.rs" , false ) . is_whitelist( ) ) ;
72
+ assert ! ( matcher. matched( "foo.py" , false ) . is_whitelist( ) ) ;
73
+ // and non-requested types are ignored
74
+ assert ! ( matcher. matched( "foo" , false ) . is_ignore( ) ) ;
75
+ Ok ( ( ) )
76
+ }
77
+
78
+ #[ test]
79
+ fn test_filter_types_missing_type ( ) -> Result < ( ) > {
80
+ let mut stb = SizTypesBuilder :: new ( ) ;
81
+
82
+ assert ! ( stb. builder. definitions( ) . len( ) == 0 ) ;
83
+
84
+ // unsupported types raise an error
85
+ assert ! ( stb. filter_types( & vec![ String :: from( "bogus" ) ] ) . is_err( ) ) ;
86
+ // including when chained with types that are supported
87
+ assert ! ( stb
88
+ . filter_types( & vec![ String :: from( "rust" ) , String :: from( "bogus" ) ] )
89
+ . is_err( ) ) ;
90
+
91
+ Ok ( ( ) )
92
+ }
93
+ }
0 commit comments