3
3
4
4
import { expect } from 'chai' ;
5
5
import * as TypeMoq from 'typemoq' ;
6
- import { Disposable , TextDocument , TextEditor , Uri , WorkspaceFolder } from 'vscode' ;
6
+ import { Disposable , Uri } from 'vscode' ;
7
+ import { IActiveResourceService } from '../../client/activation/types' ;
7
8
import { ICommandManager , IDocumentManager , IWorkspaceService } from '../../client/common/application/types' ;
8
9
import { Commands } from '../../client/common/constants' ;
9
10
import { IServiceContainer } from '../../client/ioc/types' ;
@@ -17,17 +18,20 @@ suite('REPL Provider', () => {
17
18
let workspace : TypeMoq . IMock < IWorkspaceService > ;
18
19
let codeExecutionService : TypeMoq . IMock < ICodeExecutionService > ;
19
20
let documentManager : TypeMoq . IMock < IDocumentManager > ;
21
+ let activeResourceService : TypeMoq . IMock < IActiveResourceService > ;
20
22
let replProvider : ReplProvider ;
21
23
setup ( ( ) => {
22
24
serviceContainer = TypeMoq . Mock . ofType < IServiceContainer > ( ) ;
23
25
commandManager = TypeMoq . Mock . ofType < ICommandManager > ( ) ;
24
26
workspace = TypeMoq . Mock . ofType < IWorkspaceService > ( ) ;
25
27
codeExecutionService = TypeMoq . Mock . ofType < ICodeExecutionService > ( ) ;
26
28
documentManager = TypeMoq . Mock . ofType < IDocumentManager > ( ) ;
29
+ activeResourceService = TypeMoq . Mock . ofType < IActiveResourceService > ( ) ;
27
30
serviceContainer . setup ( c => c . get ( ICommandManager ) ) . returns ( ( ) => commandManager . object ) ;
28
31
serviceContainer . setup ( c => c . get ( IWorkspaceService ) ) . returns ( ( ) => workspace . object ) ;
29
32
serviceContainer . setup ( c => c . get ( ICodeExecutionService , TypeMoq . It . isValue ( 'repl' ) ) ) . returns ( ( ) => codeExecutionService . object ) ;
30
33
serviceContainer . setup ( c => c . get ( IDocumentManager ) ) . returns ( ( ) => documentManager . object ) ;
34
+ serviceContainer . setup ( c => c . get ( IActiveResourceService ) ) . returns ( ( ) => activeResourceService . object ) ;
31
35
} ) ;
32
36
teardown ( ( ) => {
33
37
try {
@@ -51,86 +55,24 @@ suite('REPL Provider', () => {
51
55
disposable . verify ( d => d . dispose ( ) , TypeMoq . Times . once ( ) ) ;
52
56
} ) ;
53
57
54
- test ( 'Ensure resource is \'undefined\' if there\s no active document nor a workspace' , ( ) => {
58
+ test ( 'Ensure execution is carried smoothly in the handler if there are no errors' , ( ) => {
59
+ const resource = Uri . parse ( 'a' ) ;
55
60
const disposable = TypeMoq . Mock . ofType < Disposable > ( ) ;
56
61
let commandHandler : undefined | ( ( ) => void ) ;
57
62
commandManager . setup ( c => c . registerCommand ( TypeMoq . It . isValue ( Commands . Start_REPL ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( _cmd , callback ) => {
58
63
commandHandler = callback ;
59
64
return disposable . object ;
60
65
} ) ;
61
- documentManager . setup ( d => d . activeTextEditor ) . returns ( ( ) => undefined ) ;
66
+ activeResourceService
67
+ . setup ( a => a . getActiveResource ( ) )
68
+ . returns ( ( ) => resource )
69
+ . verifiable ( TypeMoq . Times . once ( ) ) ;
62
70
63
71
replProvider = new ReplProvider ( serviceContainer . object ) ;
64
72
expect ( commandHandler ) . not . to . be . equal ( undefined , 'Handler not set' ) ;
65
73
commandHandler ! . call ( replProvider ) ;
66
74
67
75
serviceContainer . verify ( c => c . get ( TypeMoq . It . isValue ( ICodeExecutionService ) , TypeMoq . It . isValue ( 'repl' ) ) , TypeMoq . Times . once ( ) ) ;
68
- codeExecutionService . verify ( c => c . initializeRepl ( TypeMoq . It . isValue ( undefined ) ) , TypeMoq . Times . once ( ) ) ;
69
- } ) ;
70
-
71
- test ( 'Ensure resource is uri of the active document' , ( ) => {
72
- const disposable = TypeMoq . Mock . ofType < Disposable > ( ) ;
73
- let commandHandler : undefined | ( ( ) => void ) ;
74
- commandManager . setup ( c => c . registerCommand ( TypeMoq . It . isValue ( Commands . Start_REPL ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( _cmd , callback ) => {
75
- commandHandler = callback ;
76
- return disposable . object ;
77
- } ) ;
78
- const documentUri = Uri . file ( 'a' ) ;
79
- const editor = TypeMoq . Mock . ofType < TextEditor > ( ) ;
80
- const document = TypeMoq . Mock . ofType < TextDocument > ( ) ;
81
- document . setup ( d => d . uri ) . returns ( ( ) => documentUri ) ;
82
- document . setup ( d => d . isUntitled ) . returns ( ( ) => false ) ;
83
- editor . setup ( e => e . document ) . returns ( ( ) => document . object ) ;
84
- documentManager . setup ( d => d . activeTextEditor ) . returns ( ( ) => editor . object ) ;
85
-
86
- replProvider = new ReplProvider ( serviceContainer . object ) ;
87
- expect ( commandHandler ) . not . to . be . equal ( undefined , 'Handler not set' ) ;
88
- commandHandler ! . call ( replProvider ) ;
89
-
90
- serviceContainer . verify ( c => c . get ( TypeMoq . It . isValue ( ICodeExecutionService ) , TypeMoq . It . isValue ( 'repl' ) ) , TypeMoq . Times . once ( ) ) ;
91
- codeExecutionService . verify ( c => c . initializeRepl ( TypeMoq . It . isValue ( documentUri ) ) , TypeMoq . Times . once ( ) ) ;
92
- } ) ;
93
-
94
- test ( 'Ensure resource is \'undefined\' if the active document is not used if it is untitled (new document)' , ( ) => {
95
- const disposable = TypeMoq . Mock . ofType < Disposable > ( ) ;
96
- let commandHandler : undefined | ( ( ) => void ) ;
97
- commandManager . setup ( c => c . registerCommand ( TypeMoq . It . isValue ( Commands . Start_REPL ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( _cmd , callback ) => {
98
- commandHandler = callback ;
99
- return disposable . object ;
100
- } ) ;
101
- const editor = TypeMoq . Mock . ofType < TextEditor > ( ) ;
102
- const document = TypeMoq . Mock . ofType < TextDocument > ( ) ;
103
- document . setup ( d => d . isUntitled ) . returns ( ( ) => true ) ;
104
- editor . setup ( e => e . document ) . returns ( ( ) => document . object ) ;
105
- documentManager . setup ( d => d . activeTextEditor ) . returns ( ( ) => editor . object ) ;
106
-
107
- replProvider = new ReplProvider ( serviceContainer . object ) ;
108
- expect ( commandHandler ) . not . to . be . equal ( undefined , 'Handler not set' ) ;
109
- commandHandler ! . call ( replProvider ) ;
110
-
111
- serviceContainer . verify ( c => c . get ( TypeMoq . It . isValue ( ICodeExecutionService ) , TypeMoq . It . isValue ( 'repl' ) ) , TypeMoq . Times . once ( ) ) ;
112
- codeExecutionService . verify ( c => c . initializeRepl ( TypeMoq . It . isValue ( undefined ) ) , TypeMoq . Times . once ( ) ) ;
113
- } ) ;
114
-
115
- test ( 'Ensure first available workspace folder is used if there no document' , ( ) => {
116
- const disposable = TypeMoq . Mock . ofType < Disposable > ( ) ;
117
- let commandHandler : undefined | ( ( ) => void ) ;
118
- commandManager . setup ( c => c . registerCommand ( TypeMoq . It . isValue ( Commands . Start_REPL ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) ) . returns ( ( _cmd , callback ) => {
119
- commandHandler = callback ;
120
- return disposable . object ;
121
- } ) ;
122
- documentManager . setup ( d => d . activeTextEditor ) . returns ( ( ) => undefined ) ;
123
-
124
- const workspaceUri = Uri . file ( 'a' ) ;
125
- const workspaceFolder = TypeMoq . Mock . ofType < WorkspaceFolder > ( ) ;
126
- workspaceFolder . setup ( w => w . uri ) . returns ( ( ) => workspaceUri ) ;
127
- workspace . setup ( w => w . workspaceFolders ) . returns ( ( ) => [ workspaceFolder . object ] ) ;
128
-
129
- replProvider = new ReplProvider ( serviceContainer . object ) ;
130
- expect ( commandHandler ) . not . to . be . equal ( undefined , 'Handler not set' ) ;
131
- commandHandler ! . call ( replProvider ) ;
132
-
133
- serviceContainer . verify ( c => c . get ( TypeMoq . It . isValue ( ICodeExecutionService ) , TypeMoq . It . isValue ( 'repl' ) ) , TypeMoq . Times . once ( ) ) ;
134
- codeExecutionService . verify ( c => c . initializeRepl ( TypeMoq . It . isValue ( workspaceUri ) ) , TypeMoq . Times . once ( ) ) ;
76
+ codeExecutionService . verify ( c => c . initializeRepl ( TypeMoq . It . isValue ( resource ) ) , TypeMoq . Times . once ( ) ) ;
135
77
} ) ;
136
78
} ) ;
0 commit comments