@@ -144,6 +144,9 @@ class ParserTests extends munit.FunSuite {
144
144
def parseExternDef (input : String , positions : Positions = new Positions ())(using munit.Location ): Def =
145
145
parse(input, _.externDef())
146
146
147
+ def parseInfo (input : String , positions : Positions = new Positions ())(using munit.Location ): Info =
148
+ parse(input, _.info(parseCaptures = true ))
149
+
147
150
// Custom asserts
148
151
//
149
152
//
@@ -997,7 +1000,8 @@ class ParserTests extends munit.FunSuite {
997
1000
IdDef (" foo" , Span (source, pos(0 ), pos(1 ))),
998
1001
None ,
999
1002
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)))
1001
1005
}
1002
1006
1003
1007
parseDefinition(
@@ -1079,6 +1083,17 @@ class ParserTests extends munit.FunSuite {
1079
1083
assertEquals(funDef.ret.span, Span (source, pos(1 ), pos(1 )))
1080
1084
}
1081
1085
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
+
1082
1097
test(" Function definition with whitespaces instead of return type" ) {
1083
1098
val (source, pos) =
1084
1099
raw """ def foo{b: => Unit / bar} = <>
@@ -1132,6 +1147,62 @@ class ParserTests extends munit.FunSuite {
1132
1147
assertEquals(valDef.span, span)
1133
1148
}
1134
1149
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
+ }
1135
1206
1136
1207
test(" Region definition parses with correct span" ) {
1137
1208
val (source, span) =
0 commit comments