public async Task CloneContextVariablesAsync(string expr, string transformedExpr, string expectedValue) { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateClass("MyType", "myType", "myValue"); RemoteValueFake exprResult = RemoteValueFakeUtil.CreateSimpleInt("x", 1); exprResult.SetClone(RemoteValueFakeUtil.CreateSimpleInt("y", 2)); remoteValue.AddValueFromExpression(transformedExpr, exprResult); IVariableInformation varInfo = _varInfoFactory.Create(remoteValue); var natvisScope = new NatvisScope(); natvisScope.AddScopedName("$i", "1U"); natvisScope.AddScopedName("var", "$var_0"); natvisScope.AddContextVariable("$var_0", exprResult); IVariableInformation result = await _evaluator.EvaluateExpressionAsync(expr, varInfo, natvisScope, "myVar"); Assert.That(await result.ValueAsync(), Is.EqualTo(expectedValue)); Assert.That(result.DisplayName, Is.EqualTo("myVar")); }
public void DeclareVariableWithErrorRemoteValue() { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateClass("MyType", "myType", "myValue"); remoteValue.AddValueFromExpression($"auto $test=5; $test", RemoteValueFakeUtil.CreateError("declaration error")); var natvisScope = new NatvisScope(); natvisScope.AddScopedName("test", "$test"); IVariableInformation varInfo = _varInfoFactory.Create(remoteValue); var exception = Assert.ThrowsAsync <ExpressionEvaluationFailed>( async() => await _evaluator.DeclareVariableAsync(varInfo, "test", "5", natvisScope)); Assert.That(exception.Message, Does.Contain("test")); Assert.That(exception.Message, Does.Contain("5")); Assert.That(exception.Message, Does.Contain("declaration error")); string logOutput = _nLogSpy.GetOutput(); Assert.That(logOutput, Does.Contain("test")); Assert.That(logOutput, Does.Contain("5")); Assert.That(logOutput, Does.Contain("declaration error")); }
public async Task LldbEvalWithContextVarsAsync() { _optionPageGrid.ExpressionEvaluationEngine = ExpressionEvaluationEngineFlag.LLDB_EVAL_WITH_FALLBACK; RemoteValue mockVariable = CreateMockVariable(); var natvisScope = new NatvisScope(); var contextVar = RemoteValueFakeUtil.CreateSimpleInt("var", 14); natvisScope.AddScopedName("var", "$var_0"); natvisScope.AddContextVariable("$var_0", contextVar); await _evaluator.EvaluateExpressionAsync( "2 + var", _varInfoFactory.Create(mockVariable), natvisScope, "result"); await mockVariable.Received(1).EvaluateExpressionLldbEvalAsync( Arg.Is("2 + $var_0"), Arg.Is(natvisScope.ContextVariables)); Assert.That(natvisScope.ContextVariables.Count, Is.EqualTo(1)); Assert.That(natvisScope.ContextVariables.ContainsKey("$var_0")); Assert.That(natvisScope.ContextVariables["$var_0"], Is.EqualTo(contextVar)); await mockVariable.DidNotReceive().EvaluateExpressionAsync(Arg.Any <string>()); }
public async Task UseLldbEvalWithConstantSubstituteTokensAsync() { _optionPageGrid.ExpressionEvaluationEngine = ExpressionEvaluationEngineFlag.LLDB_EVAL; RemoteValue mockVariable = CreateMockVariable(); var natvisScope = new NatvisScope(); natvisScope.AddScopedName("$T1", "int"); natvisScope.AddScopedName("$i", "2U"); await _evaluator.EvaluateExpressionAsync( "($T1)3.14 + $i", _varInfoFactory.Create(mockVariable), natvisScope, "result"); await mockVariable.Received(1).EvaluateExpressionLldbEvalAsync( Arg.Is("(int)3.14 + 2U"), Arg.Is(natvisScope.ContextVariables)); }
public async Task IndexerAccessWithTokenReplacementAsync() { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateSimpleIntArray("myArray", 3, 4, 5, 6); var natvisScope = new NatvisScope(); natvisScope.AddScopedName("$i", "2"); IVariableInformation varInfo = _varInfoFactory.Create(remoteValue); IVariableInformation exprVarInfo = await _evaluator.EvaluateExpressionAsync("[$i]", varInfo, natvisScope, null); Assert.That(exprVarInfo.DisplayName, Is.EqualTo("[2]")); Assert.That(await exprVarInfo.ValueAsync(), Is.EqualTo("5")); }
public async Task DeclareVariableAsync() { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateSimpleChar("testVar", 'c'); RemoteValueFake createdValue = RemoteValueFakeUtil.CreateSimpleInt("$test", 22); remoteValue.AddValueFromExpression("auto $test=var1+var2; $test", createdValue); remoteValue.AddValueFromExpression("$test", createdValue); var natvisScope = new NatvisScope(); natvisScope.AddScopedName("test", "$test"); IVariableInformation varInfo = _varInfoFactory.Create(remoteValue); await _evaluator.DeclareVariableAsync(varInfo, "test", "var1+var2", natvisScope); Assert.That(natvisScope.ContextVariables, Does.ContainKey("$test")); Assert.That(natvisScope.ContextVariables["$test"], Is.EqualTo(createdValue)); }