@@ -36,6 +36,58 @@ void testCommentSingleWithTrailingSpace() {
3636 assertComment (comment , " " , "This is a comment" , "\t \t " );
3737 }
3838
39+ @ Test
40+ void testHeaderStyleComments () {
41+ DockerfileParser parser = new DockerfileParser ();
42+ Docker .Document doc = parser .parse (new ByteArrayInputStream (
43+ """
44+ #
45+ # NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
46+ #
47+ # PLEASE DO NOT EDIT IT DIRECTLY.
48+ #
49+
50+ FROM alpine:3.21
51+ """ .getBytes (StandardCharsets .UTF_8 )));
52+
53+ Docker .Stage stage = assertSingleStageWithChildCount (doc , 6 );
54+ assertComment ((Docker .Comment ) stage .getChildren ().get (0 ), "" , "" , "" );
55+ assertComment ((Docker .Comment ) stage .getChildren ().get (1 ), " " , "NOTE: THIS DOCKERFILE IS GENERATED VIA \" apply-templates.sh\" " , "" );
56+ assertComment ((Docker .Comment ) stage .getChildren ().get (2 ), "" , "" , "" );
57+ assertComment ((Docker .Comment ) stage .getChildren ().get (3 ), " " , "PLEASE DO NOT EDIT IT DIRECTLY." , "" );
58+ assertComment ((Docker .Comment ) stage .getChildren ().get (4 ), "" , "" , "" );
59+
60+ Docker .From from = (Docker .From ) stage .getChildren ().get (5 );
61+ assertEquals (Space .EMPTY , from .getPrefix ());
62+ assertLiteral (from .getImage (), Quoting .UNQUOTED , " " , "alpine" , "" );
63+ assertEquals ("3.21" , from .getTag ());
64+ assertEquals ("" , from .getImage ().getTrailing ().getWhitespace ());
65+ assertEquals (" " , from .getImage ().getPrefix ().getWhitespace ());
66+ }
67+
68+ @ Test
69+ void testFlowerboxStyleComments () {
70+ DockerfileParser parser = new DockerfileParser ();
71+ Docker .Document doc = parser .parse (new ByteArrayInputStream (
72+ """
73+ ################################################
74+ # ####
75+ # This is a comment
76+ #####
77+ ################################################
78+ """ .getBytes (StandardCharsets .UTF_8 )));
79+
80+ Docker .Stage stage = assertSingleStageWithChildCount (doc , 5 );
81+ // note that this is one character less than the first line, because the first # is the "instruction"
82+ assertComment ((Docker .Comment ) stage .getChildren ().get (0 ), "" , "###############################################" , "" );
83+ assertComment ((Docker .Comment ) stage .getChildren ().get (1 ), " " , "####" , "" );
84+ assertComment ((Docker .Comment ) stage .getChildren ().get (2 ), " " , "This is a comment" , "" );
85+ // note the lack of the prefix space
86+ assertComment ((Docker .Comment ) stage .getChildren ().get (3 ), "" , "####" , "" );
87+ // note that this is one character less than the last line, because the first # is the "instruction"
88+ assertComment ((Docker .Comment ) stage .getChildren ().get (4 ), "" , "###############################################" , "" );
89+ }
90+
3991 @ Test
4092 void testRetainCarriageReturn () {
4193 DockerfileParser parser = new DockerfileParser ();
0 commit comments