@@ -144,6 +144,9 @@ class ParserTests extends munit.FunSuite {
144144 def parseExternDef (input : String , positions : Positions = new Positions ())(using munit.Location ): Def =
145145 parse(input, _.externDef())
146146
147+ def parseInfo (input : String , positions : Positions = new Positions ())(using munit.Location ): Info =
148+ parse(input, _.info(parseCaptures = true ))
149+
147150 // Custom asserts
148151 //
149152 //
@@ -997,7 +1000,8 @@ class ParserTests extends munit.FunSuite {
9971000 IdDef (" foo" , Span (source, pos(0 ), pos(1 ))),
9981001 None ,
9991002 Var (IdRef (Nil , " f" , Span (source, pos(2 ), pos(3 ))), Span (source, pos(2 ), pos(3 ))),
1000- None , Span (source, 0 , pos.last)))
1003+ Info .empty(Span (source, 0 , 0 )),
1004+ Span (source, 0 , pos.last)))
10011005 }
10021006
10031007 parseDefinition(
@@ -1079,6 +1083,17 @@ class ParserTests extends munit.FunSuite {
10791083 assertEquals(funDef.ret.span, Span (source, pos(1 ), pos(1 )))
10801084 }
10811085
1086+ test(" Function definition with comment" ) {
1087+ val (source, pos) =
1088+ raw """ /// Calculate the answer to the ultimate question of life, the universe, and everything
1089+ |def calculate() = 42
1090+ | """ .sourceAndPositions
1091+
1092+ val definition = parseDefinition(source.content)
1093+
1094+ assertEquals(definition.doc, Some (" Calculate the answer to the ultimate question of life, the universe, and everything" ))
1095+ }
1096+
10821097 test(" Function definition with whitespaces instead of return type" ) {
10831098 val (source, pos) =
10841099 raw """ def foo{b: => Unit / bar} = <>
@@ -1132,6 +1147,62 @@ class ParserTests extends munit.FunSuite {
11321147 assertEquals(valDef.span, span)
11331148 }
11341149
1150+ test(" Declaration info with capture set" ) {
1151+ val (source, pos) =
1152+ raw """ /// Some doc comment
1153+ |private extern {a, b, c}
1154+ |↑ ↑↑ ↑↑ ↑
1155+ | """ .sourceAndPositions
1156+
1157+ parseInfo(source.content) match {
1158+ case Info (
1159+ Some (doc),
1160+ isPrivate,
1161+ isExtern,
1162+ Some (CaptureSet (captures, Span (_, captFrom, captTo, _)))) =>
1163+
1164+ assertEquals(doc, " Some doc comment" )
1165+ assertEquals(isPrivate, Maybe (Some (()), Span (source, pos(0 ), pos(1 ))))
1166+ assertEquals(isExtern, Maybe (Some (()), Span (source, pos(2 ), pos(3 ))))
1167+ assertEquals(captures.map(_.name), List (" a" , " b" , " c" ))
1168+ assertEquals(captFrom, pos(4 ))
1169+ assertEquals(captTo, pos(5 ))
1170+
1171+ case info => fail(s " Wrong info: ${info}" )
1172+ }
1173+ }
1174+
1175+ test(" Only private" ) {
1176+ val (source, pos) =
1177+ raw """ /// Some doc comment
1178+ |private
1179+ |↑ ↑
1180+ | """ .sourceAndPositions
1181+
1182+ parseInfo(source.content) match {
1183+ case Info (doc, isPrivate, isExtern, externCapture) =>
1184+
1185+ assertEquals(doc, Some (" Some doc comment" ))
1186+ assertEquals(isPrivate, Maybe (Some (()), Span (source, pos(0 ), pos(1 ))))
1187+ assertEquals(isExtern, Maybe (None , Span (source, pos(1 ), pos(1 ))))
1188+ assertEquals(externCapture, None )
1189+ }
1190+ }
1191+
1192+ test(" Only doc comment" ) {
1193+ val (source, pos) =
1194+ raw """ /// Some doc comment
1195+ | ↑
1196+ | """ .sourceAndPositions
1197+
1198+ parseInfo(source.content) match {
1199+ case Info (doc, isPrivate, isExtern, externCapture) =>
1200+ assertEquals(doc, Some (" Some doc comment" ))
1201+ assertEquals(isPrivate, Maybe (None , Span (source, pos(0 ), pos(0 ))))
1202+ assertEquals(isExtern, Maybe (None , Span (source, pos(0 ), pos(0 ))))
1203+ assertEquals(externCapture, None )
1204+ }
1205+ }
11351206
11361207 test(" Region definition parses with correct span" ) {
11371208 val (source, span) =
0 commit comments