@@ -233,5 +233,374 @@ class StandardizeDocumentationCommentsTests: LintOrFormatRuleTestCase {
233
233
)
234
234
}
235
235
236
+ // MARK: Nominal decl tests
237
+
238
+ func testActorDecl( ) {
239
+ assertFormatting (
240
+ StandardizeDocumentationComments . self,
241
+ input: """
242
+ /// An actor declaration
243
+ /// with documentation
244
+ /// that needs to be
245
+ /// rewrapped to
246
+ /// the correct width.
247
+ package actor MyActor {}
248
+ """ ,
249
+ expected: """
250
+ /// An actor declaration with documentation that needs to be rewrapped to the
251
+ /// correct width.
252
+ package actor MyActor {}
253
+ """ ,
254
+ findings: [ ] ,
255
+ configuration: Self . configuration
256
+ )
257
+ }
258
+
259
+ func testAssociatedTypeDecl( ) {
260
+ assertFormatting (
261
+ StandardizeDocumentationComments . self,
262
+ input: """
263
+ /// An associated type declaration
264
+ /// with documentation
265
+ /// that needs to be
266
+ /// rewrapped to
267
+ /// the correct width.
268
+ associatedtype MyAssociatedType = Int
269
+ """ ,
270
+ expected: """
271
+ /// An associated type declaration with documentation that needs to be
272
+ /// rewrapped to the correct width.
273
+ associatedtype MyAssociatedType = Int
274
+ """ ,
275
+ findings: [ ] ,
276
+ configuration: Self . configuration
277
+ )
278
+ }
279
+
280
+ func testClassDecl( ) {
281
+ assertFormatting (
282
+ StandardizeDocumentationComments . self,
283
+ input: """
284
+ /// A class declaration
285
+ /// with documentation
286
+ /// that needs to be
287
+ /// rewrapped to
288
+ /// the correct width.
289
+ public class MyClass {}
290
+ """ ,
291
+ expected: """
292
+ /// A class declaration with documentation that needs to be rewrapped to the
293
+ /// correct width.
294
+ public class MyClass {}
295
+ """ ,
296
+ findings: [ ] ,
297
+ configuration: Self . configuration
298
+ )
299
+ }
300
+
301
+ func testEnumAndEnumCaseDecl( ) {
302
+ assertFormatting (
303
+ StandardizeDocumentationComments . self,
304
+ input: """
305
+ /// An enum declaration
306
+ /// with documentation
307
+ /// that needs to be
308
+ /// rewrapped to
309
+ /// the correct width.
310
+ public enum MyEnum {
311
+ /// An enum case declaration
312
+ /// with documentation
313
+ /// that needs to be
314
+ /// rewrapped to
315
+ /// the correct width.
316
+ case myCase
317
+ }
318
+ """ ,
319
+ expected: """
320
+ /// An enum declaration with documentation that needs to be rewrapped to the
321
+ /// correct width.
322
+ public enum MyEnum {
323
+ /// An enum case declaration with documentation that needs to be rewrapped to
324
+ /// the correct width.
325
+ case myCase
326
+ }
327
+ """ ,
328
+ findings: [ ] ,
329
+ configuration: Self . configuration
330
+ )
331
+ }
332
+
333
+ func testExtensionDecl( ) {
334
+ assertFormatting (
335
+ StandardizeDocumentationComments . self,
336
+ input: """
337
+ /// An extension
338
+ /// with documentation
339
+ /// that needs to be
340
+ /// rewrapped to
341
+ /// the correct width.
342
+ extension MyClass {}
343
+ """ ,
344
+ expected: """
345
+ /// An extension with documentation that needs to be rewrapped to the correct
346
+ /// width.
347
+ extension MyClass {}
348
+ """ ,
349
+ findings: [ ] ,
350
+ configuration: Self . configuration
351
+ )
352
+ }
353
+
354
+ func testFunctionDecl( ) {
355
+ assertFormatting (
356
+ StandardizeDocumentationComments . self,
357
+ input: """
358
+ /// A function declaration
359
+ /// with documentation
360
+ /// that needs to be
361
+ /// rewrapped to
362
+ /// the correct width.
363
+ ///
364
+ /// - Returns: A value.
365
+ /// - Throws: An error.
366
+ ///
367
+ /// - Parameters:
368
+ /// - param: A single parameter.
369
+ /// - Parameter another: A second single parameter.
370
+ func myFunction(param: String, and another: Int) -> Value {}
371
+ """ ,
372
+ expected: """
373
+ /// A function declaration with documentation that needs to be rewrapped to the
374
+ /// correct width.
375
+ ///
376
+ /// - Parameters:
377
+ /// - param: A single parameter.
378
+ /// - another: A second single parameter.
379
+ /// - Returns: A value.
380
+ /// - Throws: An error.
381
+ func myFunction(param: String, and another: Int) -> Value {}
382
+ """ ,
383
+ findings: [ ] ,
384
+ configuration: Self . configuration
385
+ )
386
+ }
387
+
388
+ func testInitializerDecl( ) {
389
+ assertFormatting (
390
+ StandardizeDocumentationComments . self,
391
+ input: """
392
+ /// An initializer declaration
393
+ /// with documentation
394
+ /// that needs to be
395
+ /// rewrapped to
396
+ /// the correct width.
397
+ ///
398
+ /// - Throws: An error.
399
+ ///
400
+ /// - Parameters:
401
+ /// - param: A single parameter.
402
+ /// - Parameter another: A second single parameter.
403
+ public init(param: String, and another: Int) {}
404
+ """ ,
405
+ expected: """
406
+ /// An initializer declaration with documentation that needs to be rewrapped to
407
+ /// the correct width.
408
+ ///
409
+ /// - Parameters:
410
+ /// - param: A single parameter.
411
+ /// - another: A second single parameter.
412
+ /// - Throws: An error.
413
+ public init(param: String, and another: Int) {}
414
+ """ ,
415
+ findings: [ ] ,
416
+ configuration: Self . configuration
417
+ )
418
+ }
236
419
420
+ func testMacroDecl( ) {
421
+ assertFormatting (
422
+ StandardizeDocumentationComments . self,
423
+ input: """
424
+ /// A macro declaration
425
+ /// with documentation
426
+ /// that needs to be
427
+ /// rewrapped to
428
+ /// the correct width.
429
+ ///
430
+ /// - Throws: An error.
431
+ ///
432
+ /// - Parameters:
433
+ /// - param: A single parameter.
434
+ /// - Parameter another: A second single parameter.
435
+ @freestanding(expression)
436
+ public macro prohibitBinaryOperators<T>(_ param: T, another: [String]) -> T =
437
+ #externalMacro(module: " ExampleMacros " , type: " ProhibitBinaryOperators " )
438
+ """ ,
439
+ expected: """
440
+ /// A macro declaration with documentation that needs to be rewrapped to the
441
+ /// correct width.
442
+ ///
443
+ /// - Parameters:
444
+ /// - param: A single parameter.
445
+ /// - another: A second single parameter.
446
+ /// - Throws: An error.
447
+ @freestanding(expression)
448
+ public macro prohibitBinaryOperators<T>(_ param: T, another: [String]) -> T =
449
+ #externalMacro(module: " ExampleMacros " , type: " ProhibitBinaryOperators " )
450
+ """ ,
451
+ findings: [ ] ,
452
+ configuration: Self . configuration
453
+ )
454
+ }
455
+
456
+ func testOperatorDecl( ) {
457
+ assertFormatting (
458
+ StandardizeDocumentationComments . self,
459
+ input: """
460
+ extension Int {
461
+ /// An operator declaration
462
+ /// with documentation
463
+ /// that needs to be
464
+ /// rewrapped to
465
+ /// the correct width.
466
+ ///
467
+ /// - Parameters:
468
+ /// - lhs: A single parameter.
469
+ /// - Parameter rhs: A second single parameter.
470
+ static func -+-(lhs: Int, rhs: Int) -> Int {}
471
+ }
472
+ """ ,
473
+ expected: """
474
+ extension Int {
475
+ /// An operator declaration with documentation that needs to be rewrapped to
476
+ /// the correct width.
477
+ ///
478
+ /// - Parameters:
479
+ /// - lhs: A single parameter.
480
+ /// - rhs: A second single parameter.
481
+ static func -+-(lhs: Int, rhs: Int) -> Int {}
482
+ }
483
+ """ ,
484
+ findings: [ ] ,
485
+ configuration: Self . configuration
486
+ )
487
+ }
488
+
489
+ func testProtocolDecl( ) {
490
+ assertFormatting (
491
+ StandardizeDocumentationComments . self,
492
+ input: """
493
+ /// A protocol declaration
494
+ /// with documentation
495
+ /// that needs to be
496
+ /// rewrapped to
497
+ /// the correct width.
498
+ protocol MyProto {}
499
+ """ ,
500
+ expected: """
501
+ /// A protocol declaration with documentation that needs to be rewrapped to the
502
+ /// correct width.
503
+ protocol MyProto {}
504
+ """ ,
505
+ findings: [ ] ,
506
+ configuration: Self . configuration
507
+ )
508
+ }
509
+
510
+ func testStructDecl( ) {
511
+ assertFormatting (
512
+ StandardizeDocumentationComments . self,
513
+ input: """
514
+ /// A struct declaration
515
+ /// with documentation
516
+ /// that needs to be
517
+ /// rewrapped to
518
+ /// the correct width.
519
+ struct MyStruct {}
520
+ """ ,
521
+ expected: """
522
+ /// A struct declaration with documentation that needs to be rewrapped to the
523
+ /// correct width.
524
+ struct MyStruct {}
525
+ """ ,
526
+ findings: [ ] ,
527
+ configuration: Self . configuration
528
+ )
529
+ }
530
+
531
+ func testSubscriptDecl( ) {
532
+ assertFormatting (
533
+ StandardizeDocumentationComments . self,
534
+ input: """
535
+ /// A subscript declaration
536
+ /// with documentation
537
+ /// that needs to be
538
+ /// rewrapped to
539
+ /// the correct width.
540
+ ///
541
+ /// - Returns: A value.
542
+ /// - Throws: An error.
543
+ ///
544
+ /// - Parameters:
545
+ /// - param: A single parameter.
546
+ /// - Parameter another: A second single parameter.
547
+ public subscript(param: String, and another: Int) -> Value {}
548
+ """ ,
549
+ expected: """
550
+ /// A subscript declaration with documentation that needs to be rewrapped to
551
+ /// the correct width.
552
+ ///
553
+ /// - Parameters:
554
+ /// - param: A single parameter.
555
+ /// - another: A second single parameter.
556
+ /// - Returns: A value.
557
+ /// - Throws: An error.
558
+ public subscript(param: String, and another: Int) -> Value {}
559
+ """ ,
560
+ findings: [ ] ,
561
+ configuration: Self . configuration
562
+ )
563
+ }
564
+
565
+ func testTypeAliasDecl( ) {
566
+ assertFormatting (
567
+ StandardizeDocumentationComments . self,
568
+ input: """
569
+ /// A type alias declaration
570
+ /// with documentation
571
+ /// that needs to be
572
+ /// rewrapped to
573
+ /// the correct width.
574
+ typealias MyAlias {}
575
+ """ ,
576
+ expected: """
577
+ /// A type alias declaration with documentation that needs to be rewrapped to
578
+ /// the correct width.
579
+ typealias MyAlias {}
580
+ """ ,
581
+ findings: [ ] ,
582
+ configuration: Self . configuration
583
+ )
584
+ }
585
+
586
+ func testVariableDecl( ) {
587
+ assertFormatting (
588
+ StandardizeDocumentationComments . self,
589
+ input: """
590
+ /// A variable declaration
591
+ /// with documentation
592
+ /// that needs to be
593
+ /// rewrapped to
594
+ /// the correct width.
595
+ var myVariable: Int = 5
596
+ """ ,
597
+ expected: """
598
+ /// A variable declaration with documentation that needs to be rewrapped to the
599
+ /// correct width.
600
+ var myVariable: Int = 5
601
+ """ ,
602
+ findings: [ ] ,
603
+ configuration: Self . configuration
604
+ )
605
+ }
237
606
}
0 commit comments