import { Range , Position } from 'vscode-languageserver/node' ; import { TextDocument } from 'vscode-languageserver-textdocument' ; import * as vscode from 'vscode' ; import * as assert from 'assert' ; import * as path from 'path' ; import { isSystemVerilogDocument , isVerilogDocument } from '../utils/server' ; const testFolderLocation = '../../src/test' ; suite ( 'Utils Server Tests' , ( ) => { test ( 'test #1: isSystemVerilogDocument' , async ( ) => { const svUri = vscode . Uri . file ( path . join ( __dirname , testFolderLocation , 'test-files' , 'design.sv' ) ) ; const vUri = vscode . Uri . file ( path . join ( __dirname , testFolderLocation , 'test-files' , 'ModuleInstantiator.test.1.v' ) ) ; const nonSVUri = vscode . Uri . file ( path . join ( __dirname , testFolderLocation , 'test-files' , 'foo.txt' ) ) ; const sVDocument = await vscode . workspace . openTextDocument ( svUri ) ; const vDocument = await vscode . workspace . openTextDocument ( vUri ) ; const nonSVDocument = await vscode . workspace . openTextDocument ( nonSVUri ) ; assert . strictEqual ( true , isSystemVerilogDocument ( castTextDocument ( sVDocument ) ) ) ; assert . strictEqual ( false , isSystemVerilogDocument ( castTextDocument ( vDocument ) ) ) ; assert . strictEqual ( false , isSystemVerilogDocument ( castTextDocument ( nonSVDocument ) ) ) ; assert . strictEqual ( false , isSystemVerilogDocument ( undefined ) ) ; assert . strictEqual ( false , isSystemVerilogDocument ( null ) ) ; } ) ; test ( 'test #2: isVerilogDocument' , async ( ) => { const svUri = vscode . Uri . file ( path . join ( __dirname , testFolderLocation , 'test-files' , 'design.sv' ) ) ; const vUri = vscode . Uri . file ( path . join ( __dirname , testFolderLocation , 'test-files' , 'ModuleInstantiator.test.1.v' ) ) ; const nonSVUri = vscode . Uri . file ( path . join ( __dirname , testFolderLocation , 'test-files' , 'foo.txt' ) ) ; const sVDocument = await vscode . workspace . openTextDocument ( svUri ) ; const vDocument = await vscode . workspace . openTextDocument ( vUri ) ; const nonSVDocument = await vscode . workspace . openTextDocument ( nonSVUri ) ; assert . strictEqual ( false , isVerilogDocument ( castTextDocument ( sVDocument ) ) ) ; assert . strictEqual ( true , isVerilogDocument ( castTextDocument ( vDocument ) ) ) ; assert . strictEqual ( false , isVerilogDocument ( castTextDocument ( nonSVDocument ) ) ) ; assert . strictEqual ( false , isVerilogDocument ( undefined ) ) ; assert . strictEqual ( false , isVerilogDocument ( null ) ) ; } ) ; } ) ; param document returns function castTextDocument ( document ) { return { uri : document . uri . fsPath , languageId : document . languageId , version : document . version , getText ( range ? ) { return document . getText ( castRange ( range ) ) ; } , lineCount : document . lineCount , positionAt ( offset ) { const position = document . positionAt ( offset ) ; return { line : position . line , character : position . character } ; } , offsetAt ( position ) { return document . offsetAt ( castPosition ( position ) ) ; } } ; } param document returns function castRange ( range ) { const startOld = range . start ; const endOld = range . end ; const start = new vscode . Position ( startOld . line , startOld . character ) ; const end = new vscode . Position ( endOld . line , endOld . character ) ; return new vscode . Range ( start , end ) ; } param document returns function castPosition ( position ) { return new vscode . Position ( position . line , position . character ) ; }