import * as assert from "assert" ; import * as vscode from "vscode" ; import * as TestUtils from "./testUtils" ; suite ( "Should get diagnostics" , async ( ) => { const docUri = TestUtils . getDocUri ( "diagnostics.pq" ) ; vscode . window . showInformationMessage ( `Starting tests using based file: ${ docUri }` ) ; test ( "Simple diagnostics test" , async ( ) => { await testDiagnostics ( docUri , [ { message : "Expected to find a equal operator <'='>, but a not equal to operator ('<>') was found instead" , range : toRange ( 0 , 9 , 0 , 12 ) , severity : vscode . DiagnosticSeverity . Error } , ] ) ; } ) ; } ) ; suite ( "No errors" , async ( ) => { const docUri = TestUtils . getDocUri ( "Diagnostics.NoErrors.pq" ) ; vscode . window . showInformationMessage ( `Starting tests using based file: ${ docUri }` ) ; test ( "No errors" , async ( ) => { await testDiagnostics ( docUri , [ ] ) ; } ) ; } ) ; suite ( "Experimental diagnostics" , async ( ) => { const docUri = TestUtils . getDocUri ( "Diagnostics.TableIsEmpty.Error.pq" ) ; test ( "No error reported with default settings" , async ( ) => { await testDiagnostics ( docUri , [ ] ) ; } ) ; } ) ; function toRange ( sLine , sChar , eLine , eChar ) { const start = new vscode . Position ( sLine , sChar ) ; const end = new vscode . Position ( eLine , eChar ) ; return new vscode . Range ( start , end ) ; } async function testDiagnostics ( docUri , expectedDiagnostics ) { await TestUtils . activate ( docUri ) ; const actualDiagnostics = vscode . languages . getDiagnostics ( docUri ) ; if ( expectedDiagnostics . length === 0 && actualDiagnostics . length !== 0 ) { assert . fail ( `Expected 0 diagnostics but received: ${ JSON . stringify ( actualDiagnostics , undefined , 2 ) }` ) ; } assert . equal ( actualDiagnostics . length , expectedDiagnostics . length ) ; expectedDiagnostics . forEach ( ( expectedDiagnostic , index ) => { const actualDiagnostic = actualDiagnostics . at ( index ) ; assert . equal ( actualDiagnostic ?. message , expectedDiagnostic . message ) ; assert . deepEqual ( actualDiagnostic ?. range , expectedDiagnostic . range ) ; assert . equal ( actualDiagnostic ?. severity , expectedDiagnostic . severity ) ; } ) ; }