public static Maybe <IReadOnlyList <MethodDeclarationSyntax> > FindMethodsOfClass <TClass>(Expression <Func <TClass, string> > exMethodName, CSharpSyntaxTree syntaxTree) where TClass : class { var methodName = ValueOf.Property(exMethodName, null); var className = typeof(TClass).Name; return(FindMethodsOfClass(syntaxTree, className, methodName)); }
private ValueOf ParseValueOf() { ExpectTokenType(TokenType.Identifier); var result = new ValueOf { VariableName = _scanner.Token.Value }; _scanner.ReadNextToken(); if (_scanner.Token.Type == TokenType.SquareBracketOpen) { _scanner.ReadNextToken(); ExpectTokenType(TokenType.Number); result.Index = Int32.Parse(_scanner.Token.Value); _scanner.ReadNextToken(); ExpectTokenType(TokenType.SquareBracketClose); _scanner.ReadNextToken(); } if (_scanner.Token.Type == TokenType.Dot) { _scanner.ReadNextToken(); ExpectTokenType(TokenType.Identifier); result.NestedValue = ParseValueOf(); } return(result); }
public void NullStringValue() { ValueOf <String> some = ValueOfFactory.valueOfString(null); Assert.IsNotNull(some); Assert.IsNull(some.value()); }
public void ScopeWithObjectWithArray_VariableIsCalled_CorrectValueIsReturned() { // prepare var scope_prototype = new ScopePrototype { Variables = new HashSet <string> { "array" }, }; var scope = new Scope(scope_prototype) { VariableValues = new Dictionary <string, AssignedValue> { { "array", new AssignedValue(JToken.Parse("{'object': [1,3,6]}")) } } }; var valueOf = new ValueOf { VariableName = "array", NestedValue = new ValueOf { VariableName = "object", Index = 2 } }; // act var value = scope.FindValueOfValueOf(valueOf); // validate Assert.Equal("6", value); }
public void ScopeWithVariable_VariableIsCalled_CorrectValueIsReturned() { // prepare var scope_prototype = new ScopePrototype { Variables = new HashSet <string> { "arg" }, }; var scope = new Scope(scope_prototype) { VariableValues = new Dictionary <string, AssignedValue> { { "arg", new AssignedValue(JToken.Parse("'value'")) } } }; var valueOf = new ValueOf { VariableName = "arg" }; // act var value = scope.FindValueOfValueOf(valueOf); // validate Assert.Equal("value", value); }
public static int mean(int[] values, ValueOf valueOf = null) { int n = values.Length, m = n, i = -1; int value, sum = 0; if (valueOf == null) { while (++i < n) { value = values[i]; sum += value; } } else { while (++i < n) { value = valueOf(values[i], i, values); sum += value; } } return(sum / m); }
public void StringValue() { ValueOf <String> some = ValueOfFactory.valueOfString("value"); Assert.IsNotNull(some); Assert.IsNotNull(some.value()); Assert.AreEqual("value", some.value()); }
public void RawAxisTest() { ValueSpy <float> spy = new ValueSpy <float>(ValueOf.RawAxis("Horizontal")); spy.SimulateInput(i => i.GetAxisRaw("Horizontal").Returns(2.0f)); spy.AssertWasUpdatedTo(2.0f); spy.WaitFrame(); spy.AssertNothingHappened(); }
public void testUpdateNestedProperty() { var inst = new ValueOf { Value = new Value() { ValueField = 10 } }; var newInst = inst.update(i => i.Value.ValueProperty, v => v + 1); Assert.That(newInst, Is.Not.SameAs(inst)); Assert.That(newInst.Value, Is.Not.SameAs(inst.Value)); Assert.That(newInst.Value.ValueProperty, Is.EqualTo(inst.Value.ValueProperty + 1)); }
private ICondition ParseConditionWithAnyValue(ValueOf lhs, ConditionType conditionType) { var result = new ConditionWithValue { LeftHandSideVariable = lhs, ConditionType = conditionType, RightHandSideVariable = ParseValue() }; return(result); }
private ConditionWithValue ParseConditionWithVariableOrNumericValue(ValueOf lhs, ConditionType conditionType) { var result = new ConditionWithValue { LeftHandSideVariable = lhs, ConditionType = conditionType, }; result.RightHandSideVariable = ParseVariableOrNumericValue(); return(result); }
private StringComponentInstruction PopulateValueOf(ScopePrototype scope, ValueOf valueOf) { // check if value has been declared in the scope if (!scope.Variables.Contains(valueOf.VariableName)) { throw new SemanticsException($"Variable {valueOf.VariableName} has not been declared in the scope of function {scope.FunctionName}."); } var valueOfInstruction = new StringComponentInstruction(scope, valueOf); return(valueOfInstruction); }
public void ScopeWithoutVariable_VariableIsCalled_RuntimeExceptionIsThrown() { // prepare var outer_scope_prototype = new ScopePrototype { Variables = new HashSet <string> { "arg" }, }; var scope_prototype = new ScopePrototype { Variables = new HashSet <string> { "arg2" }, UpperScopePrototype = outer_scope_prototype }; var scope = new Scope(scope_prototype) { UpperScope = new Scope(outer_scope_prototype) { VariableValues = new Dictionary <string, AssignedValue> { { "arg", new AssignedValue(JToken.Parse("'value'")) } } }, VariableValues = new Dictionary <string, AssignedValue> { { "arg2", new AssignedValue(JToken.Parse("'value2'")) } } }; var valueOf = new ValueOf { VariableName = "arg3" }; // act var exceptionWasThrown = false; try { scope.FindValueOfValueOf(valueOf); } catch (RuntimeException) { exceptionWasThrown = true; } // validate Assert.True(exceptionWasThrown); }
public JToken FindValueOfValueOf(ValueOf valueOf) { var rootValue = FindValueOfVariable(valueOf.VariableName); var rootName = valueOf.VariableName; if (rootValue.IsNumericValue) { if (valueOf.Index != null || valueOf.NestedValue != null) { throw new RuntimeException("Tried to access members of a numeric value."); } return(rootValue.NumericValue.ToString()); } var currentValueOf = valueOf; var alreadyParsedBuilder = new StringBuilder(rootName); JToken jToken = rootValue.StringValue; do { if (currentValueOf.Index != null) { var list = jToken.ToList(); if (list.Count() <= currentValueOf.Index) { throw new RuntimeException($"The object {alreadyParsedBuilder.ToString()} does not have a member of index {currentValueOf.Index}."); } jToken = list[currentValueOf.Index.Value]; alreadyParsedBuilder.Append($"[{currentValueOf.Index}]"); } currentValueOf = currentValueOf.NestedValue; if (currentValueOf != null) { try { jToken = jToken[currentValueOf.VariableName]; } catch (InvalidOperationException) { throw new RuntimeException($"The object {alreadyParsedBuilder.ToString()} does not have a member called {currentValueOf.VariableName}."); } alreadyParsedBuilder.Append($".{currentValueOf.VariableName}"); } }while (currentValueOf != null); return(jToken); }
protected override bool Equals(ValueOf <string, CaseInsensitiveClientRef> other) { return(EqualityComparer <string> .Default.Equals(Value.ToLower(), other.Value.ToLower())); }