@@ -8,7 +8,7 @@ mod scanner {
8
8
use tailwindcss_oxide:: * ;
9
9
use tempfile:: tempdir;
10
10
11
- fn create_files_in ( dir : & path:: PathBuf , paths : & [ ( & str , & str ) ] ) {
11
+ fn create_files_in ( dir : & path:: Path , paths : & [ ( & str , & str ) ] ) {
12
12
// Create the necessary files
13
13
for ( path, contents) in paths {
14
14
// Ensure we use the right path separator for the current platform
@@ -334,6 +334,53 @@ mod scanner {
334
334
) ;
335
335
}
336
336
337
+ #[ test]
338
+ fn it_should_be_possible_to_scan_in_the_parent_directory ( ) {
339
+ let candidates = scan_with_globs (
340
+ & [ ( "foo/bar/baz/foo.html" , "content-['foo.html']" ) ] ,
341
+ vec ! [ "./foo/bar/baz/.." ] ,
342
+ )
343
+ . 1 ;
344
+
345
+ assert_eq ! ( candidates, vec![ "content-['foo.html']" ] ) ;
346
+ }
347
+
348
+ #[ test]
349
+ fn it_should_scan_files_without_extensions ( ) {
350
+ // These look like folders, but they are files
351
+ let candidates =
352
+ scan_with_globs ( & [ ( "my-file" , "content-['my-file']" ) ] , vec ! [ "./my-file" ] ) . 1 ;
353
+
354
+ assert_eq ! ( candidates, vec![ "content-['my-file']" ] ) ;
355
+ }
356
+
357
+ #[ test]
358
+ fn it_should_scan_folders_with_extensions ( ) {
359
+ // These look like files, but they are folders
360
+ let candidates = scan_with_globs (
361
+ & [
362
+ (
363
+ "my-folder.templates/foo.html" ,
364
+ "content-['my-folder.templates/foo.html']" ,
365
+ ) ,
366
+ (
367
+ "my-folder.bin/foo.html" ,
368
+ "content-['my-folder.bin/foo.html']" ,
369
+ ) ,
370
+ ] ,
371
+ vec ! [ "./my-folder.templates" , "./my-folder.bin" ] ,
372
+ )
373
+ . 1 ;
374
+
375
+ assert_eq ! (
376
+ candidates,
377
+ vec![
378
+ "content-['my-folder.bin/foo.html']" ,
379
+ "content-['my-folder.templates/foo.html']" ,
380
+ ]
381
+ ) ;
382
+ }
383
+
337
384
#[ test]
338
385
fn it_should_scan_content_paths ( ) {
339
386
let candidates = scan_with_globs (
@@ -349,6 +396,44 @@ mod scanner {
349
396
assert_eq ! ( candidates, vec![ "content-['foo.styl']" ] ) ;
350
397
}
351
398
399
+ #[ test]
400
+ fn it_should_scan_absolute_paths ( ) {
401
+ // Create a temporary working directory
402
+ let dir = tempdir ( ) . unwrap ( ) . into_path ( ) ;
403
+
404
+ // Initialize this directory as a git repository
405
+ let _ = Command :: new ( "git" ) . arg ( "init" ) . current_dir ( & dir) . output ( ) ;
406
+
407
+ // Create files
408
+ create_files_in (
409
+ & dir,
410
+ & [
411
+ ( "project-a/index.html" , "content-['project-a/index.html']" ) ,
412
+ ( "project-b/index.html" , "content-['project-b/index.html']" ) ,
413
+ ] ,
414
+ ) ;
415
+
416
+ // Get POSIX-style absolute path
417
+ let full_path = format ! ( "{}" , dir. display( ) ) . replace ( '\\' , "/" ) ;
418
+
419
+ let sources = vec ! [ GlobEntry {
420
+ base: full_path. clone( ) ,
421
+ pattern: full_path. clone( ) ,
422
+ } ] ;
423
+
424
+ let mut scanner = Scanner :: new ( Some ( sources) ) ;
425
+ let candidates = scanner. scan ( ) ;
426
+
427
+ // We've done the initial scan and found the files
428
+ assert_eq ! (
429
+ candidates,
430
+ vec![
431
+ "content-['project-a/index.html']" . to_owned( ) ,
432
+ "content-['project-b/index.html']" . to_owned( ) ,
433
+ ]
434
+ ) ;
435
+ }
436
+
352
437
#[ test]
353
438
fn it_should_scan_content_paths_even_when_they_are_git_ignored ( ) {
354
439
let candidates = scan_with_globs (
0 commit comments