@@ -351,6 +351,94 @@ generate_comments_test() ->
351351 Comments = generate_comments (SchemaElement ),
352352 ? assertEqual ([" ## Hi!" , " ## Bye!" , " ## " , " ## Acceptable values:" , " ## - text" ], Comments ).
353353
354+ normalize_newlines (Conf ) ->
355+ normalize_newlines (Conf , {os_type , os :type ()}).
356+
357+ normalize_newlines (Conf , {os_type , {win32 , _ }}) ->
358+ {ok , Regex } = re :compile (" \r\n " , [unicode ]),
359+ F = fun (V ) ->
360+ re :replace (V , Regex , " \n " , [global , {return , list }])
361+ end ,
362+ normalize_newlines (Conf , F , []);
363+ normalize_newlines (Conf , {os_type , _ }) ->
364+ normalize_newlines (Conf , fun (V ) -> V end , []).
365+
366+ normalize_newlines ([], _F , Acc ) ->
367+ Acc ;
368+ normalize_newlines ({errorlist , _ }= Errorlist , _F , _Acc ) ->
369+ throw (Errorlist );
370+ normalize_newlines ({error , _ }= Error , _F , _Acc ) ->
371+ throw (Error );
372+ normalize_newlines ([{KeyList , Value }|Rest ], F , Acc0 ) ->
373+ Acc1 = [{KeyList , F (Value )} | Acc0 ],
374+ normalize_newlines (Rest , F , Acc1 ).
375+
376+ multiline_test () ->
377+ Conf = normalize_newlines (file (" test/multiline.conf" )),
378+ ? assertEqual (1 , length (Conf )),
379+ ? assertMatch ([{[" a" ]," l0\n l1\n l2" }], Conf ).
380+
381+ multiline_empty_test () ->
382+ Conf = file (" test/multiline_empty.conf" ),
383+ ? assertEqual (1 , length (Conf )),
384+ ? assertMatch ([{[" a" ],[]}], Conf ).
385+
386+ multiline_same_line_test () ->
387+ Conf = file (" test/multiline_same_line.conf" ),
388+ ? assertEqual (1 , length (Conf )),
389+ ? assertMatch ([{[" a" ]," value" }], Conf ).
390+
391+ multiline_special_chars_test () ->
392+ Conf = normalize_newlines (file (" test/multiline_special_chars.conf" )),
393+ ? assertEqual (1 , length (Conf )),
394+ ? assertMatch ([{[" a" ], " key = value\n # comment\n 'quoted' = \" double\" " }], Conf ).
395+
396+ multiline_unclosed_test () ->
397+ Conf = file (" test/multiline_unclosed.conf" ),
398+ ? assertMatch ({errorlist , [{error , {conf_syntax , {" test/multiline_unclosed.conf" , _ }}}]}, Conf ).
399+
400+ multiline_embedded_delimiter_test () ->
401+ Conf = file (" test/multiline_embedded_delimiter.conf" ),
402+ ? assertMatch ({errorlist , [{error , {conf_syntax , {" test/multiline_embedded_delimiter.conf" , _ }}}]}, Conf ).
403+
404+ multiline_with_trailing_comment_test () ->
405+ Conf = normalize_newlines (file (" test/multiline_with_trailing_comment.conf" )),
406+ ? assertEqual (1 , length (Conf )),
407+ ? assertMatch ([{[" a" ]," value" }], Conf ).
408+
409+ multiline_multiple_test () ->
410+ Conf = normalize_newlines (file (" test/multiline_multiple.conf" )),
411+ ? assertEqual (2 , length (Conf )),
412+ ? assertMatch ([{[" b" ]," l3\n l4\n l5" },
413+ {[" a" ]," l0\n l1\n l2" }], Conf ).
414+
415+ multiline_mixed_test () ->
416+ Conf = normalize_newlines (file (" test/multiline_mixed.conf" )),
417+ ? assertEqual (3 , length (Conf )),
418+ ? assertMatch ([{[" another" ]," simple" },
419+ {[" regular" ]," value" },
420+ {[" a" ]," l0\n l1\n l2" }], Conf ).
421+
422+ multiline_whitespace_only_test () ->
423+ Conf = normalize_newlines (file (" test/multiline_whitespace_only.conf" )),
424+ ? assertEqual (1 , length (Conf )),
425+ ? assertMatch ([{[" a" ]," \t\n\r " }], Conf ).
426+
427+ multiline_with_include_test () ->
428+ Conf = normalize_newlines (file (" test/multiline_with_include.conf" )),
429+ ? assertEqual (1 , length (Conf )),
430+ ? assertMatch ([{[" a" ], " include other.conf\n include *.conf" }], Conf ).
431+
432+ multiline_eof_test () ->
433+ Conf = file (" test/multiline_eof.conf" ),
434+ ? assertEqual (1 , length (Conf )),
435+ ? assertMatch ([{[" a" ], " value" }], Conf ).
436+
437+ multiline_unicode_test () ->
438+ Conf = normalize_newlines (file (" test/multiline_unicode.conf" )),
439+ ? assertEqual (1 , length (Conf )),
440+ ? assertMatch ([{[" greeting" ], " Hello 世界! 🌍\n Привіт, світ!\n Привет, мир!\n مرحبا بالعالم\n こんにちは世界" }], Conf ).
441+
354442duplicates_test () ->
355443 Conf = file (" test/multi1.conf" ),
356444 ? assertEqual (2 , length (Conf )),
0 commit comments