@@ -4,7 +4,7 @@ module test_filesystem
4
4
join_path, is_absolute_path, get_home, &
5
5
delete_file, read_lines, get_temp_filename
6
6
use fpm_environment, only: OS_WINDOWS, get_os_type, os_is_unix
7
- use fpm_strings, only: string_t
7
+ use fpm_strings, only: string_t, split_lines_first_last
8
8
implicit none
9
9
private
10
10
@@ -23,6 +23,7 @@ subroutine collect_filesystem(tests)
23
23
& new_unittest(" create-delete-directory" , test_mkdir_rmdir), &
24
24
& new_unittest(" test-is-absolute-path" , test_is_absolute_path), &
25
25
& new_unittest(" test-get-home" , test_get_home), &
26
+ & new_unittest(" test-split-lines-first-last" , test_split_lines_first_last), &
26
27
& new_unittest(" test-crlf-lines" , test_dir_with_crlf) &
27
28
]
28
29
@@ -293,6 +294,42 @@ subroutine test_get_home(error)
293
294
294
295
end subroutine test_get_home
295
296
297
+ ! Test line splitting on MS windows
298
+ subroutine test_split_lines_first_last (error )
299
+ ! > Error handling
300
+ type (error_t), allocatable , intent (out ) :: error
301
+
302
+ character , parameter :: CR = achar (13 )
303
+ character , parameter :: LF = new_line(' A' )
304
+ integer , allocatable :: first(:), last(:)
305
+
306
+ call check_array(error, &
307
+ & split_lines_first_last(CR// LF// ' line1' // CR// ' line2' // LF// ' line3' // CR// LF// ' hello' , first, last), &
308
+ & [3 , 9 , 15 , 23 ], [7 , 13 , 21 , 27 ])
309
+ if (allocated (error)) return
310
+
311
+ call check_array(error, &
312
+ & split_lines_first_last(' single_line' , first, last), &
313
+ & [1 ], [11 ])
314
+ if (allocated (error)) return
315
+
316
+ call check_array(error, &
317
+ & split_lines_first_last(CR// LF// CR// LF// ' test' , first, last), &
318
+ & [5 ], [8 ])
319
+ if (allocated (error)) return
320
+
321
+ call check_array(error, &
322
+ & split_lines_first_last(' a' // CR// ' b' // LF// ' c' // CR// LF// ' d' , first, last), &
323
+ & [1 , 3 , 5 , 8 ], [1 , 3 , 5 , 8 ])
324
+ if (allocated (error)) return
325
+
326
+ call check_array(error, &
327
+ & split_lines_first_last(' ' , first, last), &
328
+ & [], [])
329
+ if (allocated (error)) return
330
+
331
+ end subroutine test_split_lines_first_last
332
+
296
333
! On MS windows,
297
334
subroutine test_dir_with_crlf (error )
298
335
type (error_t), allocatable , intent (out ) :: error
0 commit comments