@@ -4,7 +4,7 @@ module test_filesystem
44 join_path, is_absolute_path, get_home, &
55 delete_file, read_lines, get_temp_filename
66 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
88 implicit none
99 private
1010
@@ -23,6 +23,7 @@ subroutine collect_filesystem(tests)
2323 & new_unittest(" create-delete-directory" , test_mkdir_rmdir), &
2424 & new_unittest(" test-is-absolute-path" , test_is_absolute_path), &
2525 & new_unittest(" test-get-home" , test_get_home), &
26+ & new_unittest(" test-split-lines-first-last" , test_split_lines_first_last), &
2627 & new_unittest(" test-crlf-lines" , test_dir_with_crlf) &
2728 ]
2829
@@ -293,6 +294,42 @@ subroutine test_get_home(error)
293294
294295 end subroutine test_get_home
295296
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+
296333 ! On MS windows,
297334 subroutine test_dir_with_crlf (error )
298335 type (error_t), allocatable , intent (out ) :: error
0 commit comments