@@ -203,4 +203,57 @@ load "test-helper"
203203 assert_equal " $expected " " $actual "
204204
205205 rm -f " $tmp_file "
206- }
206+ }
207+
208+ @test " file_fill_template non empty file, nothing to replace" {
209+ local -r tmp_file=$( mktemp)
210+ local -ar auto_fill=(" <__PLACEHOLDER__>=hello" )
211+ local -r file_contents=$( echo -e " abc\nhey world\nbaz" )
212+
213+ echo " $file_contents " > " $tmp_file "
214+
215+ run file_fill_template " $tmp_file " " ${auto_fill[@]} "
216+ assert_success
217+
218+ local -r actual=$( cat " $tmp_file " )
219+ local -r expected=$file_contents
220+ assert_equal " $expected " " $actual "
221+
222+ rm -f " $tmp_file "
223+ }
224+
225+ @test " file_fill_template non empty file, replace text" {
226+ local -r tmp_file=$( mktemp)
227+ local -ar auto_fill=(" <__PLACEHOLDER__>=hello" )
228+ local -r file_contents=$( echo -e " abc\n<__PLACEHOLDER__> world\nbaz" )
229+
230+ echo " $file_contents " > " $tmp_file "
231+
232+ run file_fill_template " $tmp_file " " ${auto_fill[@]} "
233+ assert_success
234+
235+ local -r actual=$( cat " $tmp_file " )
236+ local -r expected=$( echo -e " abc\nhello world\nbaz" )
237+ assert_equal " $expected " " $actual "
238+
239+ rm -f " $tmp_file "
240+ }
241+
242+ @test " file_fill_template non empty file, replace multiple" {
243+ local -r tmp_file=$( mktemp)
244+ local -a auto_fill=(" <__PLACEHOLDER__>=hello" )
245+ auto_fill+=(" <__PLACEHOLDER2__>=foo" )
246+
247+ local -r file_contents=$( echo -e " abc\n<__PLACEHOLDER__> world\n<__PLACEHOLDER2__> baz" )
248+
249+ echo " $file_contents " > " $tmp_file "
250+
251+ run file_fill_template " $tmp_file " " ${auto_fill[@]} "
252+ assert_success
253+
254+ local -r actual=$( cat " $tmp_file " )
255+ local -r expected=$( echo -e " abc\nhello world\nfoo baz" )
256+ assert_equal " $expected " " $actual "
257+
258+ rm -f " $tmp_file "
259+ }
0 commit comments