Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 15a78e1

Browse files
author
Mikhail Arkhipov
committed
Update test
1 parent 80aabe1 commit 15a78e1

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/Analysis/Engine/Test/AstAnalysisTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,13 +978,20 @@ public async Task TypeShedJsonMakeScanner() {
978978
scanner = _json.make_scanner()";
979979
var analysis = await server.OpenDefaultDocumentAndGetAnalysisAsync(code);
980980

981-
analysis.Should().HaveVariable("scanner").WithValue<IBuiltinInstanceInfo>()
982-
.Which.Should().HaveSingleOverload()
981+
var v0 = analysis.Should().HaveVariable("scanner").WithValueAt<IBuiltinInstanceInfo>(0);
982+
var v1 = analysis.Should().HaveVariable("scanner").WithValueAt<IBuiltinInstanceInfo>(1);
983+
984+
v0.Which.Should().HaveSingleOverload()
983985
.Which.Should().HaveName("__call__")
984986
.And.HaveParameters("string", "index")
985987
.And.HaveParameterAt(0).WithName("string").WithType("str").WithNoDefaultValue()
986988
.And.HaveParameterAt(1).WithName("index").WithType("int").WithNoDefaultValue()
987989
.And.HaveSingleReturnType("tuple[None, int]");
990+
991+
v1.Which.Should().HaveSingleOverload()
992+
.Which.Should().HaveName("__call__")
993+
.And.HaveParameters("*args", "**kwargs")
994+
.And.HaveSingleReturnType("type");
988995
}
989996
}
990997

src/Analysis/Engine/Test/FluentAssertions/VariableDefAssertions.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,19 @@ public AndWhichConstraint<VariableDefAssertions, AnalysisValueTestInfo<TValue>>
211211
var testInfo = new AnalysisValueTestInfo<TValue>((TValue)value, GetScopeDescription(), _scope);
212212
return new AndWhichConstraint<VariableDefAssertions, AnalysisValueTestInfo<TValue>>(this, testInfo);
213213
}
214-
214+
215+
public AndWhichConstraint<VariableDefAssertions, AnalysisValueTestInfo<TValue>> HaveValueAt<TValue>(int index, string because = "", params object[] reasonArgs)
216+
where TValue : IAnalysisValue {
217+
var value = FlattenAnalysisValues(Subject.Types).ToArray()[index];
218+
219+
Execute.Assertion.ForCondition(value is TValue)
220+
.BecauseOf(because, reasonArgs)
221+
.FailWith($"Expected {_moduleName}.{_name} to have value of type {typeof(TValue)}{{reason}}, but its value has type {value.GetType()}.");
222+
223+
var testInfo = new AnalysisValueTestInfo<TValue>((TValue)value, GetScopeDescription(), _scope);
224+
return new AndWhichConstraint<VariableDefAssertions, AnalysisValueTestInfo<TValue>>(this, testInfo);
225+
}
226+
215227
private IAnalysisValue AssertSingle(string because, object[] reasonArgs, IAnalysisValue[] values) {
216228
Execute.Assertion.ForCondition(values.Length == 1)
217229
.BecauseOf(because, reasonArgs)
@@ -222,6 +234,16 @@ private IAnalysisValue AssertSingle(string because, object[] reasonArgs, IAnalys
222234
return values[0];
223235
}
224236

237+
private IAnalysisValue[] AssertCount(int count, string because, object[] reasonArgs, IAnalysisValue[] values) {
238+
Execute.Assertion.ForCondition(values.Length != count)
239+
.BecauseOf(because, reasonArgs)
240+
.FailWith(values.Length == count
241+
? $"Expected variable '{_moduleName}.{_name}' to have {count} values{{reason}}, but found none."
242+
: $"Expected variable '{_moduleName}.{_name}' to have {count} values{{reason}}, but found {values.Length}: {GetQuotedNames(values)}");
243+
244+
return values;
245+
}
246+
225247
private string GetScopeDescription() {
226248
switch (_scope) {
227249
case IFunctionScope functionScope:

src/Analysis/Engine/Test/FluentAssertions/VariableDefAssertionsExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,23 @@ public static AndWhichConstraint<TAssertion, AnalysisValueTestInfo<TValue>>
122122
return new AndWhichConstraint<TAssertion, AnalysisValueTestInfo<TValue>>(andWhichConstraint.And, testInfo);
123123
}
124124

125+
public static AndWhichConstraint<TAssertion, AnalysisValueTestInfo<TValue>>
126+
WithValueAt<TAssertion, TValue>(this AndWhichConstraint<TAssertion, VariableDefTestInfo> andWhichConstraint, int index, string because = "", params object[] reasonArgs)
127+
where TValue : IAnalysisValue {
128+
var testInfo = andWhichConstraint.Which.Should().HaveValueAt<TValue>(index, because, reasonArgs).Which;
129+
return new AndWhichConstraint<TAssertion, AnalysisValueTestInfo<TValue>>(andWhichConstraint.And, testInfo);
130+
}
131+
125132
public static AndWhichConstraint<ModuleAnalysisAssertions, AnalysisValueTestInfo<TValue>>
126133
WithValue<TValue>(this AndWhichConstraint<ModuleAnalysisAssertions, VariableDefTestInfo> constraint, string because = "", params object[] reasonArgs)
127134
where TValue : IAnalysisValue
128135
=> constraint.WithValue<ModuleAnalysisAssertions, TValue>(because, reasonArgs);
129136

137+
public static AndWhichConstraint<ModuleAnalysisAssertions, AnalysisValueTestInfo<TValue>>
138+
WithValueAt<TValue>(this AndWhichConstraint<ModuleAnalysisAssertions, VariableDefTestInfo> constraint, int index, string because = "", params object[] reasonArgs)
139+
where TValue : IAnalysisValue
140+
=> constraint.WithValueAt<ModuleAnalysisAssertions, TValue>(index, because, reasonArgs);
141+
130142
public static AndWhichConstraint<ScopeAssertions, AnalysisValueTestInfo<TValue>>
131143
WithValue<TValue>(this AndWhichConstraint<ScopeAssertions, VariableDefTestInfo> constraint, string because = "", params object[] reasonArgs)
132144
where TValue : IAnalysisValue

0 commit comments

Comments
 (0)