@@ -89,10 +89,10 @@ public void VerifyParameterValues()
89
89
Action actual = ( ) => this . _service . GetSuggestion ( null , 1 , 1 , CancellationToken . None ) ;
90
90
Assert . Throws < ArgumentNullException > ( actual ) ;
91
91
92
- actual = ( ) => this . _service . GetSuggestion ( predictionContext . InputAst , 0 , 1 , CancellationToken . None ) ;
92
+ actual = ( ) => this . _service . GetSuggestion ( predictionContext , 0 , 1 , CancellationToken . None ) ;
93
93
Assert . Throws < ArgumentOutOfRangeException > ( actual ) ;
94
94
95
- actual = ( ) => this . _service . GetSuggestion ( predictionContext . InputAst , 1 , 0 , CancellationToken . None ) ;
95
+ actual = ( ) => this . _service . GetSuggestion ( predictionContext , 1 , 0 , CancellationToken . None ) ;
96
96
Assert . Throws < ArgumentOutOfRangeException > ( actual ) ;
97
97
}
98
98
@@ -110,8 +110,8 @@ public void VerifyParameterValues()
110
110
public void VerifyUsingCommandBasedPredictor ( string userInput )
111
111
{
112
112
var predictionContext = PredictionContext . Create ( userInput ) ;
113
- var commandAst = predictionContext . InputAst . FindAll ( p => p is CommandAst , true ) . LastOrDefault ( ) as CommandAst ;
114
- var commandName = ( commandAst ? . CommandElements ? . FirstOrDefault ( ) as StringConstantExpressionAst ) ? . Value ;
113
+ var commandAst = predictionContext . RelatedAsts . OfType < CommandAst > ( ) . LastOrDefault ( ) ;
114
+ var commandName = commandAst ? . GetCommandName ( ) ;
115
115
var inputParameterSet = new ParameterSet ( commandAst ) ;
116
116
var rawUserInput = predictionContext . InputAst . Extent . Text ;
117
117
var presentCommands = new Dictionary < string , int > ( ) ;
@@ -123,7 +123,7 @@ public void VerifyUsingCommandBasedPredictor(string userInput)
123
123
1 ,
124
124
CancellationToken . None ) ;
125
125
126
- var actual = this . _service . GetSuggestion ( predictionContext . InputAst , 1 , 1 , CancellationToken . None ) ;
126
+ var actual = this . _service . GetSuggestion ( predictionContext , 1 , 1 , CancellationToken . None ) ;
127
127
Assert . NotNull ( actual ) ;
128
128
Assert . True ( actual . Count > 0 ) ;
129
129
Assert . NotNull ( actual . PredictiveSuggestions . First ( ) ) ;
@@ -133,7 +133,7 @@ public void VerifyUsingCommandBasedPredictor(string userInput)
133
133
Assert . Equal < string > ( expected . SourceTexts , actual . SourceTexts ) ;
134
134
Assert . All < SuggestionSource > ( actual . SuggestionSources , ( source ) => Assert . Equal ( SuggestionSource . CurrentCommand , source ) ) ;
135
135
136
- actual = this . _noFallbackPredictorService . GetSuggestion ( predictionContext . InputAst , 1 , 1 , CancellationToken . None ) ;
136
+ actual = this . _noFallbackPredictorService . GetSuggestion ( predictionContext , 1 , 1 , CancellationToken . None ) ;
137
137
Assert . NotNull ( actual ) ;
138
138
Assert . True ( actual . Count > 0 ) ;
139
139
Assert . NotNull ( actual . PredictiveSuggestions . First ( ) ) ;
@@ -153,7 +153,7 @@ public void VerifyUsingCommandBasedPredictor(string userInput)
153
153
public void VerifyUsingFallbackPredictor ( string userInput )
154
154
{
155
155
var predictionContext = PredictionContext . Create ( userInput ) ;
156
- var commandAst = predictionContext . InputAst . FindAll ( p => p is CommandAst , true ) . LastOrDefault ( ) as CommandAst ;
156
+ var commandAst = predictionContext . RelatedAsts . OfType < CommandAst > ( ) . LastOrDefault ( ) ;
157
157
var commandName = ( commandAst ? . CommandElements ? . FirstOrDefault ( ) as StringConstantExpressionAst ) ? . Value ;
158
158
var inputParameterSet = new ParameterSet ( commandAst ) ;
159
159
var rawUserInput = predictionContext . InputAst . Extent . Text ;
@@ -166,7 +166,7 @@ public void VerifyUsingFallbackPredictor(string userInput)
166
166
1 ,
167
167
CancellationToken . None ) ;
168
168
169
- var actual = this . _service . GetSuggestion ( predictionContext . InputAst , 1 , 1 , CancellationToken . None ) ;
169
+ var actual = this . _service . GetSuggestion ( predictionContext , 1 , 1 , CancellationToken . None ) ;
170
170
Assert . NotNull ( actual ) ;
171
171
Assert . True ( actual . Count > 0 ) ;
172
172
Assert . NotNull ( actual . PredictiveSuggestions . First ( ) ) ;
@@ -176,7 +176,7 @@ public void VerifyUsingFallbackPredictor(string userInput)
176
176
Assert . Equal < string > ( expected . SourceTexts , actual . SourceTexts ) ;
177
177
Assert . All < SuggestionSource > ( actual . SuggestionSources , ( source ) => Assert . Equal ( SuggestionSource . StaticCommands , source ) ) ;
178
178
179
- actual = this . _noCommandBasedPredictorService . GetSuggestion ( predictionContext . InputAst , 1 , 1 , CancellationToken . None ) ;
179
+ actual = this . _noCommandBasedPredictorService . GetSuggestion ( predictionContext , 1 , 1 , CancellationToken . None ) ;
180
180
Assert . NotNull ( actual ) ;
181
181
Assert . True ( actual . Count > 0 ) ;
182
182
Assert . NotNull ( actual . PredictiveSuggestions . First ( ) ) ;
@@ -199,33 +199,43 @@ public void VerifyUsingFallbackPredictor(string userInput)
199
199
public void VerifyNoPrediction ( string userInput )
200
200
{
201
201
var predictionContext = PredictionContext . Create ( userInput ) ;
202
- var actual = this . _service . GetSuggestion ( predictionContext . InputAst , 1 , 1 , CancellationToken . None ) ;
202
+ var actual = this . _service . GetSuggestion ( predictionContext , 1 , 1 , CancellationToken . None ) ;
203
203
Assert . Equal ( 0 , actual . Count ) ;
204
204
205
- actual = this . _noFallbackPredictorService . GetSuggestion ( predictionContext . InputAst , 1 , 1 , CancellationToken . None ) ;
205
+ actual = this . _noFallbackPredictorService . GetSuggestion ( predictionContext , 1 , 1 , CancellationToken . None ) ;
206
206
Assert . Equal ( 0 , actual . Count ) ;
207
207
208
- actual = this . _noCommandBasedPredictorService . GetSuggestion ( predictionContext . InputAst , 1 , 1 , CancellationToken . None ) ;
208
+ actual = this . _noCommandBasedPredictorService . GetSuggestion ( predictionContext , 1 , 1 , CancellationToken . None ) ;
209
209
Assert . Equal ( 0 , actual . Count ) ;
210
210
211
- actual = this . _noPredictorService . GetSuggestion ( predictionContext . InputAst , 1 , 1 , CancellationToken . None ) ;
211
+ actual = this . _noPredictorService . GetSuggestion ( predictionContext , 1 , 1 , CancellationToken . None ) ;
212
+ Assert . Null ( actual ) ;
213
+ }
214
+
215
+ /// <summary>
216
+ /// Verify that it returns null when we cannot parse the user input.
217
+ /// </summary>
218
+ [ Theory ]
219
+ [ InlineData ( "git status" ) ]
220
+ public void VerifyFailToParseUserInput ( string userInput )
221
+ {
222
+ var predictionContext = PredictionContext . Create ( userInput ) ;
223
+ var actual = this . _service . GetSuggestion ( predictionContext , 1 , 1 , CancellationToken . None ) ;
212
224
Assert . Null ( actual ) ;
213
225
}
214
226
215
227
/// <summary>
216
228
/// Verify when we cannot parse the user input correctly.
217
229
/// </summary>
218
230
/// <remarks>
219
- /// When we can parse them correctly, please move the InlineData to the corresponding test methods, for example, "git status"
220
- /// doesn't have any prediction so it should move to <see cref="VerifyNoPrediction"/>.
231
+ /// When we can parse them correctly, please move the InlineData to the corresponding test methods.
221
232
/// </remarks>
222
233
[ Theory ]
223
- [ InlineData ( "git status" ) ]
224
234
[ InlineData ( "Get-AzContext Name" ) ]
225
235
public void VerifyMalFormattedCommandLine ( string userInput )
226
236
{
227
237
var predictionContext = PredictionContext . Create ( userInput ) ;
228
- Action actual = ( ) => this . _service . GetSuggestion ( predictionContext . InputAst , 1 , 1 , CancellationToken . None ) ;
238
+ Action actual = ( ) => this . _service . GetSuggestion ( predictionContext , 1 , 1 , CancellationToken . None ) ;
229
239
_ = Assert . Throws < InvalidOperationException > ( actual ) ;
230
240
}
231
241
}
0 commit comments