@@ -25,6 +25,8 @@ import {SnowflakeId} from "@akashrajpurohit/snowflake-id";
2525import { mapAsync } from "../util" ;
2626import { ParseErrorKind } from "../parse-error" ;
2727import { MarkersKind , ParseExceptionResult } from "../markers" ;
28+ import { JavaScriptVisitor } from "../javascript" ;
29+ import { J } from "../java" ;
2830
2931export interface SourceSpec < T extends SourceFile > {
3032 kind : string ,
@@ -73,6 +75,7 @@ export class RecipeSpec {
7375 const specs = specsByKind [ kind ] ;
7476 const parsed = await this . parse ( specs ) ;
7577 await this . expectNoParseFailures ( parsed ) ;
78+ await this . expectWhitespaceNotToContainNonwhitespaceCharacters ( parsed ) ;
7679 this . checkParsePrintIdempotence && await this . expectParsePrintIdempotence ( parsed ) ;
7780 const changeset = ( await scheduleRun ( this . recipe ,
7881 parsed . map ( ( [ _ , sourceFile ] ) => sourceFile ) ,
@@ -144,6 +147,7 @@ export class RecipeSpec {
144147
145148 private async expectAfter ( spec : SourceSpec < any > , after ?: SourceFile ) {
146149 expect ( after ) . toBeDefined ( ) ;
150+ await new ValidateWhitespaceVisitor ( ) . visit ( after ! , this . executionContext ) ;
147151 const actualAfter = await TreePrinters . print ( after ! ) ;
148152 const afterSource = typeof spec . after === "function" ?
149153 ( spec . after as ( actual : string ) => string ) ( actualAfter ) : spec . after as string ;
@@ -182,6 +186,21 @@ export class RecipeSpec {
182186 return [ spec , sourceFile ] ;
183187 } ) ;
184188 }
189+
190+ private async expectWhitespaceNotToContainNonwhitespaceCharacters ( parsed : [ SourceSpec < any > , SourceFile ] [ ] ) {
191+ const validator = new ValidateWhitespaceVisitor ( ) ;
192+ for ( const [ _ , sourceFile ] of parsed ) {
193+ await validator . visit ( sourceFile , this . executionContext ) ;
194+ }
195+ }
196+ }
197+
198+ class ValidateWhitespaceVisitor extends JavaScriptVisitor < ExecutionContext > {
199+ protected override async visitSpace ( space : J . Space , p : ExecutionContext ) : Promise < J . Space > {
200+ const ret = super . visitSpace ( space , p ) ;
201+ expect ( space . whitespace ) . toMatch ( / ^ \s * $ / ) ;
202+ return ret ;
203+ }
185204}
186205
187206class NoopRecipe extends Recipe {
0 commit comments