Skip to content

Commit cf4c472

Browse files
authored
display arguments as term lists in docc-flavored markdown generation (#754)
* display arguments as term lists in docc-flavored markdown generation - added a Boolean to distinguish regular (GH-flavored) markdown from docc-flavored markdown - represent the arguments in generated files with term lists for the docc-flavored variant - updated the snapshot tests to work both GH and DocC flavored markdown generation - removed an added "\n" in the recording of content for snapshot tests, which caused the snapshot tests some issues (recorded tests with new values wouldn't pass on second-run) * applying formatting using Script/format * resolve soundness check issue for throwing function * switches argument to --style, defaulting to github flavored markdown, and accepting as 'docc' as an alternative * adding comments for future-me to understand flow in generate manual to match generate reference
1 parent d67151b commit cf4c472

15 files changed

+530
-67
lines changed

Sources/ArgumentParserTestHelpers/TestHelpers.swift

+16-6
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ extension XCTest {
448448
ProcessInfo.processInfo.environment["RECORD_SNAPSHOTS"] != nil
449449

450450
if record || recordEnvironment || !snapshotExists {
451-
let recordedValue = actual + "\n"
451+
let recordedValue = actual
452452
try FileManager.default.createDirectory(
453453
at: snapshotDirectoryURL,
454454
withIntermediateDirectories: true,
@@ -507,8 +507,9 @@ extension XCTest {
507507
line: line)
508508
}
509509

510-
public func assertGenerateDoccReference(
510+
public func assertGeneratedReference(
511511
command: String,
512+
doccFlavored: Bool,
512513
record: Bool = false,
513514
test: StaticString = #function,
514515
file: StaticString = #filePath,
@@ -519,10 +520,19 @@ extension XCTest {
519520
#endif
520521

521522
let commandURL = debugURL.appendingPathComponent(command)
522-
let command = [
523-
"generate-docc-reference", commandURL.path,
524-
"--output-directory", "-",
525-
]
523+
let command: [String]
524+
if doccFlavored {
525+
command = [
526+
"generate-docc-reference", commandURL.path,
527+
"--output-directory", "-",
528+
"--style", "docc",
529+
]
530+
} else {
531+
command = [
532+
"generate-docc-reference", commandURL.path,
533+
"--output-directory", "-",
534+
]
535+
}
526536
let actual = try AssertExecuteCommand(
527537
command: command,
528538
file: file,

Tests/ArgumentParserGenerateDoccReferenceTests/GenerateDoccReferenceTests.swift

+22-5
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,42 @@ import XCTest
1414

1515
final class GenerateDoccReferenceTests: XCTestCase {
1616
#if os(macOS)
17+
func testCountLinesMarkdownReference() throws {
18+
guard #available(macOS 12, *) else { return }
19+
try assertGeneratedReference(command: "count-lines", doccFlavored: false)
20+
}
21+
1722
func testCountLinesDoccReference() throws {
1823
guard #available(macOS 12, *) else { return }
19-
try assertGenerateDoccReference(command: "count-lines")
24+
try assertGeneratedReference(command: "count-lines", doccFlavored: true)
2025
}
2126
#endif
2227

28+
func testColorMarkdownReference() throws {
29+
try assertGeneratedReference(command: "color", doccFlavored: false)
30+
}
2331
func testColorDoccReference() throws {
24-
try assertGenerateDoccReference(command: "color")
32+
try assertGeneratedReference(command: "color", doccFlavored: true)
2533
}
2634

35+
func testMathMarkdownReference() throws {
36+
try assertGeneratedReference(command: "math", doccFlavored: false)
37+
}
2738
func testMathDoccReference() throws {
28-
try assertGenerateDoccReference(command: "math")
39+
try assertGeneratedReference(command: "math", doccFlavored: true)
2940
}
3041

42+
func testRepeatMarkdownReference() throws {
43+
try assertGeneratedReference(command: "repeat", doccFlavored: false)
44+
}
3145
func testRepeatDoccReference() throws {
32-
try assertGenerateDoccReference(command: "repeat")
46+
try assertGeneratedReference(command: "repeat", doccFlavored: true)
3347
}
3448

49+
func testRollMarkdownReference() throws {
50+
try assertGeneratedReference(command: "roll", doccFlavored: false)
51+
}
3552
func testRollDoccReference() throws {
36-
try assertGenerateDoccReference(command: "roll")
53+
try assertGeneratedReference(command: "roll", doccFlavored: true)
3754
}
3855
}

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testColorDoccReference().md

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
color --fav=<fav> [--second=<second>] [--help]
77
```
88

9-
**--fav=\<fav\>:**
9+
- term **--fav=\<fav\>:**
1010

1111
*Your favorite color.*
1212

1313

14-
**--second=\<second\>:**
14+
- term **--second=\<second\>:**
1515

1616
*Your second favorite color.*
1717

1818
This is optional.
1919

2020

21-
**--help:**
21+
- term **--help:**
2222

2323
*Show help information.*
2424

@@ -31,7 +31,7 @@ Show subcommand help information.
3131
color help [<subcommands>...]
3232
```
3333

34-
**subcommands:**
34+
- term **subcommands:**
3535

3636

3737

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# color
2+
3+
<!-- Generated by swift-argument-parser -->
4+
5+
```
6+
color --fav=<fav> [--second=<second>] [--help]
7+
```
8+
9+
**--fav=\<fav\>:**
10+
11+
*Your favorite color.*
12+
13+
14+
**--second=\<second\>:**
15+
16+
*Your second favorite color.*
17+
18+
This is optional.
19+
20+
21+
**--help:**
22+
23+
*Show help information.*
24+
25+
26+
## color.help
27+
28+
Show subcommand help information.
29+
30+
```
31+
color help [<subcommands>...]
32+
```
33+
34+
**subcommands:**
35+
36+
37+
38+
39+

Tests/ArgumentParserGenerateDoccReferenceTests/Snapshots/testCountLinesDoccReference().md

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
count-lines [<input-file>] [--prefix=<prefix>] [--verbose] [--help]
77
```
88

9-
**input-file:**
9+
- term **input-file:**
1010

1111
*A file to count lines in. If omitted, counts the lines of stdin.*
1212

1313

14-
**--prefix=\<prefix\>:**
14+
- term **--prefix=\<prefix\>:**
1515

1616
*Only count lines with this prefix.*
1717

1818

19-
**--verbose:**
19+
- term **--verbose:**
2020

2121
*Include extra information in the output.*
2222

2323

24-
**--help:**
24+
- term **--help:**
2525

2626
*Show help information.*
2727

@@ -34,7 +34,7 @@ Show subcommand help information.
3434
count-lines help [<subcommands>...]
3535
```
3636

37-
**subcommands:**
37+
- term **subcommands:**
3838

3939

4040

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# count-lines
2+
3+
<!-- Generated by swift-argument-parser -->
4+
5+
```
6+
count-lines [<input-file>] [--prefix=<prefix>] [--verbose] [--help]
7+
```
8+
9+
**input-file:**
10+
11+
*A file to count lines in. If omitted, counts the lines of stdin.*
12+
13+
14+
**--prefix=\<prefix\>:**
15+
16+
*Only count lines with this prefix.*
17+
18+
19+
**--verbose:**
20+
21+
*Include extra information in the output.*
22+
23+
24+
**--help:**
25+
26+
*Show help information.*
27+
28+
29+
## count-lines.help
30+
31+
Show subcommand help information.
32+
33+
```
34+
count-lines help [<subcommands>...]
35+
```
36+
37+
**subcommands:**
38+
39+
40+
41+
42+

0 commit comments

Comments
 (0)