'use strict' ; import * as assert from 'assert' ; import { IGhcMod , GhcModCmdOpts } from '../src/interfaces' ; import { TestLogger } from './helpers/testLogger' ; import { InteractiveGhcModProcess } from '../src/ghcModProviders/interactiveGhcMod' ; describe ( 'InteractiveGhcModProcess' , function ( ) : void { this . timeout ( 0 ) ; let logger = new TestLogger ( ) ; let ghcMod = InteractiveGhcModProcess . create ( null , logger ) ; after ( ( ) => { ghcMod . killProcess ( ) ; } ) ; describe ( '#runGhcModCommand' , ( ) => { describe ( 'Check command' , ( ) => { let regex = /.+:\d+:\d+:(Warning: |Error: )?.+/ ; it ( 'should return an empty array for valid files' , ( ) => { let uri = 'test/fixtures/valid.hs' ; let opts = < GhcModCmdOpts > { command : 'check' , uri : uri } ; return ghcMod . runGhcModCommand ( opts ) . then ( ( lines ) => { assert . equal ( lines . length , 0 ) ; } ) ; } ) ; it ( 'should return messages without severity in an expected format' , ( ) => { let uri = 'test/fixtures/empty.hs' ; let opts = < GhcModCmdOpts > { command : 'check' , uri : uri } ; return ghcMod . runGhcModCommand ( opts ) . then ( ( lines ) => { assert . equal ( lines . length , 1 ) ; assert . ok ( regex . test ( lines [ 0 ] ) ) ; } ) ; } ) ; it ( 'should return warnings in an expected format' , ( ) => { let uri = 'test/fixtures/type.hs' ; let opts = < GhcModCmdOpts > { command : 'check' , uri : uri } ; return ghcMod . runGhcModCommand ( opts ) . then ( ( lines ) => { assert . equal ( lines . length , 1 ) ; assert . ok ( regex . test ( lines [ 0 ] ) ) ; } ) ; } ) ; } ) ; describe ( 'Type command' , ( ) => { it ( 'should return the expected output' , ( ) => { let uri = 'test/fixtures/type.hs' ; let opts = < GhcModCmdOpts > { command : 'type' , uri : uri , args : [ '3' , '8' ] } ; let output = [ '3 8 3 9 "a"' , '3 1 3 17 "a -> a"' ] ; return ghcMod . runGhcModCommand ( opts ) . then ( ( lines ) => { assert . deepEqual ( lines , output ) ; } ) ; } ) ; } ) ; describe ( 'Info command' , ( ) => { it ( 'should return "Cannot show info" if info unavailable' , ( ) => { let uri = 'test/fixtures/type.hs' ; let opts = < GhcModCmdOpts > { command : 'info' , uri : uri , args : [ 'bogus' ] } ; let output = [ 'Cannot show info' ] ; return ghcMod . runGhcModCommand ( opts ) . then ( ( lines ) => { assert . deepEqual ( lines , output ) ; } ) ; } ) ; it ( 'should return info if available' , ( ) => { let uri = 'test/fixtures/type.hs' ; let opts = < GhcModCmdOpts > { command : 'info' , uri : uri , args : [ 'Num' ] } ; return ghcMod . runGhcModCommand ( opts ) . then ( ( lines ) => { assert . equal ( lines . length , 1 ) ; assert . equal ( lines [ 0 ] . indexOf ( 'Cannot show info' ) , - 1 ) ; } ) ; } ) ; } ) ; } ) ; } ) ;