11import { getContentAsString } from "../../../lib/extractor" ;
22import { ExtractAction , ExtractedLayers } from "../../../lib/extractor/types" ;
3+ import { isWhitedOutFile } from "../../../lib/extractor" ;
34
45describe ( "index" , ( ) => {
56 test ( "getContentAsString() does matches when a pattern is used in the extract action" , async ( ) => {
@@ -18,3 +19,39 @@ describe("index", () => {
1819 expect ( result ) . toEqual ( "Hello, world!" ) ;
1920 } ) ;
2021} ) ;
22+
23+ describe ( "isWhitedOutFile" , ( ) => {
24+ test ( "should return true for files containing .wh. in their path" , ( ) => {
25+ expect ( isWhitedOutFile ( "/etc/.wh.hosts" ) ) . toBe ( true ) ;
26+ expect ( isWhitedOutFile ( "/var/lib/.wh.data" ) ) . toBe ( true ) ;
27+ expect ( isWhitedOutFile ( "/.wh.config" ) ) . toBe ( true ) ;
28+ } ) ;
29+
30+ test ( "should return false for files not containing .wh." , ( ) => {
31+ expect ( isWhitedOutFile ( "/etc/hosts" ) ) . toBe ( false ) ;
32+ expect ( isWhitedOutFile ( "" ) ) . toBe ( false ) ;
33+ expect ( isWhitedOutFile ( "/" ) ) . toBe ( false ) ;
34+ } ) ;
35+
36+ test ( "should return false for similar but different patterns" , ( ) => {
37+ // make sure the dots are literal and not match all
38+ expect ( isWhitedOutFile ( "/etc/wh.hosts" ) ) . toBe ( false ) ;
39+ expect ( isWhitedOutFile ( "/etc/.whosts" ) ) . toBe ( false ) ;
40+ expect ( isWhitedOutFile ( "/etc/whhosts" ) ) . toBe ( false ) ;
41+
42+ // dots in wrong places
43+ expect ( isWhitedOutFile ( "/etc/.w.h.hosts" ) ) . toBe ( false ) ;
44+ expect ( isWhitedOutFile ( "/etc/..wh..hosts" ) ) . toBe ( false ) ;
45+
46+ // case sensitive
47+ expect ( isWhitedOutFile ( "/etc/.WH.hosts" ) ) . toBe ( false ) ;
48+ expect ( isWhitedOutFile ( "/etc/.Wh.hosts" ) ) . toBe ( false ) ;
49+ } ) ;
50+
51+ test ( "should handle .wh. at different positions" , ( ) => {
52+ expect ( isWhitedOutFile ( ".wh.start" ) ) . toBe ( true ) ;
53+ expect ( isWhitedOutFile ( "middle.wh.file" ) ) . toBe ( true ) ;
54+ expect ( isWhitedOutFile ( "end.wh." ) ) . toBe ( true ) ;
55+ expect ( isWhitedOutFile ( "/deeply/nested/path/.wh.present" ) ) . toBe ( true ) ;
56+ } ) ;
57+ } ) ;
0 commit comments