@@ -747,6 +747,119 @@ public function shouldHandleWhitespace(): void
747747 );
748748 }
749749
750+ /**
751+ * @test
752+ */
753+ public function shouldParseComments (): void
754+ {
755+ $ parser = new Parser ('<!-- lorem ipsum --> ' );
756+ $ this ->assertEquals (
757+ [
758+ [
759+ 'type ' => 'comment ' ,
760+ 'payload ' => ' lorem ipsum '
761+ ]
762+ ],
763+ $ parser ->parse ()
764+ );
765+ }
766+
767+ /**
768+ * @test
769+ */
770+ public function shouldIgnoreTagsAndExpressionsInComments (): void
771+ {
772+ $ parser = new Parser ('<!-- <foo>{bar}</foo> --> ' );
773+ $ this ->assertEquals (
774+ [
775+ [
776+ 'type ' => 'comment ' ,
777+ 'payload ' => ' <foo>{bar}</foo> '
778+ ]
779+ ],
780+ $ parser ->parse ()
781+ );
782+ }
783+
784+ /**
785+ * @test
786+ */
787+ public function shouldParseCommentsBeforeContent (): void
788+ {
789+ $ parser = new Parser ('<!--lorem ipsum--><div /> ' );
790+ $ this ->assertEquals (
791+ [
792+ [
793+ 'type ' => 'comment ' ,
794+ 'payload ' => 'lorem ipsum '
795+ ],
796+ [
797+ 'type ' => 'node ' ,
798+ 'payload ' => [
799+ 'identifier ' => 'div ' ,
800+ 'attributes ' => [],
801+ 'selfClosing ' => true ,
802+ 'children ' => []
803+ ]
804+ ]
805+ ],
806+ $ parser ->parse ()
807+ );
808+ }
809+
810+ /**
811+ * @test
812+ */
813+ public function shouldParseCommentsAfterContent (): void
814+ {
815+ $ parser = new Parser ('<div/><!--lorem ipsum--> ' );
816+ $ this ->assertEquals (
817+ [
818+ [
819+ 'type ' => 'node ' ,
820+ 'payload ' => [
821+ 'identifier ' => 'div ' ,
822+ 'attributes ' => [],
823+ 'selfClosing ' => true ,
824+ 'children ' => []
825+ ]
826+ ],
827+ [
828+ 'type ' => 'comment ' ,
829+ 'payload ' => 'lorem ipsum '
830+ ]
831+ ],
832+ $ parser ->parse ()
833+ );
834+ }
835+
836+ /**
837+ * @test
838+ */
839+ public function shouldParseCommentsInsideContent (): void
840+ {
841+ $ parser = new Parser ('<div><!--lorem ipsum--></div> ' );
842+ $ this ->assertEquals (
843+ [
844+ [
845+ 'type ' => 'node ' ,
846+ 'payload ' => [
847+ 'identifier ' => 'div ' ,
848+ 'attributes ' => [],
849+ 'selfClosing ' => false ,
850+ 'children ' => [
851+ [
852+ 'type ' => 'comment ' ,
853+ 'payload ' => 'lorem ipsum '
854+ ]
855+ ]
856+ ]
857+ ]
858+ ],
859+ $ parser ->parse ()
860+ );
861+ }
862+
750863 /**
751864 * @test
752865 */
@@ -806,4 +919,24 @@ public function shouldThrowExceptionForUnclosedSpreadExpression(): void
806919 $ parser = new Parser ('<div {...bar() /> ' );
807920 $ parser ->parse ();
808921 }
922+
923+ /**
924+ * @test
925+ */
926+ public function shouldThrowExceptionForWronglyStartedComment ()
927+ {
928+ $ this ->expectException (AfxParserException::class);
929+ $ parser = new Parser ('<div><! foo --></div> ' );
930+ $ parser ->parse ();
931+ }
932+
933+ /**
934+ * @test
935+ */
936+ public function shouldThrowExceptionForCommentWithoutProperEnd ()
937+ {
938+ $ this ->expectException (AfxParserException::class);
939+ $ parser = new Parser ('<div><!-- foo </div> ' );
940+ $ parser ->parse ();
941+ }
809942}
0 commit comments