@@ -233,7 +233,7 @@ struct NoteSpec {
233
233
234
234
/// An abstract data structure to describe how a diagnostic produced by the parser should look like.
235
235
struct DiagnosticSpec {
236
- /// The name of a maker (of the form `1️⃣`) in the source code that marks the location where the diagnostis should be produced.
236
+ /// The name of a maker (of the form `1️⃣`) in the source code that marks the location where the diagnostic should be produced.
237
237
let locationMarker : String
238
238
/// If not `nil`, assert that the diagnostic has the given ID.
239
239
let id : MessageID ?
@@ -531,7 +531,7 @@ public struct AssertParseOptions: OptionSet {
531
531
extension ParserTestCase {
532
532
/// After a test case has been mutated, assert that the mutated source
533
533
/// round-trips and doesn’t hit any assertion failures in the parser.
534
- fileprivate func assertRoundTrip < S: SyntaxProtocol > (
534
+ fileprivate func assertMutatedSourceRoundTrips < S: SyntaxProtocol > (
535
535
source: [ UInt8 ] ,
536
536
_ parse: ( inout Parser ) -> S ,
537
537
experimentalFeatures: Parser . ExperimentalFeatures ,
@@ -564,23 +564,42 @@ extension ParserTestCase {
564
564
}
565
565
}
566
566
567
- /// Removes any test markers from `markedSource` (1) and parses the result
568
- /// using `parse`. By default it only checks if the parsed syntax tree is
569
- /// printable back to the origin source, ie. it round trips.
567
+ /// Verifies that parsing of `markedSource` produces expected results using a
568
+ /// combination of various testing techniques:
569
+ ///
570
+ /// 1. Asserts that parsing of `markedSource` round-trips, ie. that the printed
571
+ /// parsed tree is the same as the input.
572
+ /// 2. Checks that parsing produces the expected list of diagnostics. If no
573
+ /// diagnostics are passed, asserts that the input parses without any errors.
574
+ /// 3. Checks that applying all Fix-Its of the source code results in the
575
+ /// expected fixed source, effectively testing the Fix-Its.
576
+ /// 4. If a substructure is passed, asserts that the parsed tree contains a
577
+ /// subtree of that structure.
578
+ /// 5. Mutates the test input by flipping each token's presence (ie. for every
579
+ /// token, remove it from the input if it is present in the parsed tree and
580
+ /// synthesize a missing tokens into the input) and verifies that this
581
+ /// mutated input round-trips. This test is disabled if the
582
+ /// `SKIP_LONG_TESTS` environment variable is set.
583
+ /// 6. If swift-syntax is compiled with the
584
+ /// `SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION` environment variable
585
+ /// set, mutates the input based on tokens the parse is trying to parse.
586
+ /// See the *Test Case Mutation* section in CONTRIBUTING.md.
570
587
///
571
- /// (1) `markedSource` is source that can include markers of the form `1️⃣`,
572
- /// to be used as locations in the following parameters when they exist.
573
588
///
574
589
/// - Parameters:
575
- /// - substructure: Asserts the parsed syntax tree contains this structure.
590
+ /// - markedSource: source that can include markers of the form `1️⃣`,
591
+ /// to be used as locations in the following parameters.
592
+ /// - parse: The function with which the source code should be parsed.
593
+ /// Defaults to parsing as a source file.
594
+ /// - expectedSubstructure: Asserts the parsed syntax tree contains this structure.
576
595
/// - substructureAfterMarker: Changes the position to start the structure
577
596
/// assertion from, ie. allows matching a particular substructure rather
578
597
/// than the whole source.
579
- /// - diagnostics : Asserts the given diagnostics were output, by default it
598
+ /// - expectedDiagnostics : Asserts the given diagnostics were output, by default it
580
599
/// asserts the parse was successful (ie. it has no diagnostics). Note
581
600
/// that `DiagnosticsSpec` uses the location marked by `1️⃣` by default.
582
601
/// - applyFixIts: Applies only the fix-its with these messages.
583
- /// - fixedSource : Asserts that the source after applying fix-its matches
602
+ /// - expectedFixedSource : Asserts that the source after applying fix-its matches
584
603
/// this string.
585
604
/// - experimentalFeatures: A list of experimental features to enable, or
586
605
/// `nil` to enable the default set of features provided by the test case.
@@ -693,7 +712,7 @@ extension ParserTestCase {
693
712
DispatchQueue . concurrentPerform ( iterations: Array ( tree. tokens ( viewMode: . all) ) . count) { tokenIndex in
694
713
let flippedTokenTree = TokenPresenceFlipper ( flipTokenAtIndex: tokenIndex) . rewrite ( Syntax ( tree) )
695
714
_ = ParseDiagnosticsGenerator . diagnostics ( for: flippedTokenTree)
696
- assertRoundTrip ( source: flippedTokenTree. syntaxTextBytes, parse, experimentalFeatures: experimentalFeatures, file: file, line: line)
715
+ assertMutatedSourceRoundTrips ( source: flippedTokenTree. syntaxTextBytes, parse, experimentalFeatures: experimentalFeatures, file: file, line: line)
697
716
}
698
717
699
718
#if SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION
@@ -703,7 +722,7 @@ extension ParserTestCase {
703
722
DispatchQueue . concurrentPerform ( iterations: mutations. count) { index in
704
723
let mutation = mutations [ index]
705
724
let alternateSource = MutatedTreePrinter . print ( tree: Syntax ( tree) , mutations: [ mutation. offset: mutation. replacement] )
706
- assertRoundTrip ( source: alternateSource, parse, experimentalFeatures: experimentalFeatures, file: file, line: line)
725
+ assertMutatedSourceRoundTrips ( source: alternateSource, parse, experimentalFeatures: experimentalFeatures, file: file, line: line)
707
726
}
708
727
#endif
709
728
}
0 commit comments