private void SetNumericalExpression(IdentifierValueNode identifierValueNode, ExpressionNode expressionNode, SymbolType expressionType) { switch (expressionType) { case SymbolType.Float: { FloatValueNode floatValueNode = new FloatValueNode(); ExpressionEvaluator <float> expressionEvaluator = new ExpressionEvaluator <float>(new FloatCalculator(expressionNode.Token)); expressionNode.Accept(expressionEvaluator); floatValueNode.Value = expressionEvaluator.Result; identifierValueNode.ValueNode = floatValueNode; break; } case SymbolType.Integer: { IntValueNode intValueNode = new IntValueNode(); ExpressionEvaluator <int> expressionEvaluator = new ExpressionEvaluator <int>(new IntCalculator(expressionNode.Token)); expressionNode.Accept(expressionEvaluator); intValueNode.Value = expressionEvaluator.Result; identifierValueNode.ValueNode = intValueNode; break; } } }
/// <inheritdoc /> protected override int ParseLiteral(IntValueNode valueSyntax) { if (valueSyntax.ToInt32() > MaxValue) { throw ThrowHelper.NegativeIntType_ParseLiteral_IsNotNegative(this); } return(base.ParseLiteral(valueSyntax)); }
/// <inheritdoc /> protected override uint ParseLiteral(IntValueNode valueSyntax) { if (valueSyntax.ToUInt32() < MinValue) { throw ThrowHelper.UnsignedIntType_ParseLiteral_IsNotUnsigned(this); } return(valueSyntax.ToUInt32()); }
public void ParseLiteral_Wrong_ValueNode_Throws() { // arrange StringType type = new StringType(); IntValueNode input = new IntValueNode(123456); // act // assert Assert.Throws <ArgumentException>(() => type.ParseLiteral(input)); }
public void ParseLiteral_Wrong_ValueNode_Throws() { // arrange var type = new MultiplierPathType(); var input = new IntValueNode(123456); // act // assert Assert.Throws <ScalarSerializationException>( () => type.ParseLiteral(input)); }
/// <inheritdoc /> protected override int ParseLiteral(IntValueNode valueSyntax) { var result = base.ParseLiteral(valueSyntax); if (result < MinValue) { throw ThrowHelper.PositiveIntType_ParseLiteral_ZeroOrLess(this); } return(result); }
/// <inheritdoc /> protected override TRuntimeType ParseLiteral(IntValueNode literal) { if (TryDeserialize(literal.ToInt32(), out TRuntimeType? value)) { return(value.Value); } throw new SerializationException( string.Format(IntToStructBaseType_ParseLiteral_UnableToDeserializeInt, Name), this); }
protected override TRuntimeType ParseLiteral(IntValueNode literal) { if (TryDeserialize(literal.ToInt32(), out TRuntimeType? value)) { return(value.Value); } throw new SerializationException( $"Unable to deserialize integer to {this.Name}", this); }
internal static StreamDirective?GetStreamDirective( this IReadOnlyList <DirectiveNode> directives, IVariableValueCollection variables) { DirectiveNode?directiveNode = GetDirective(directives, WellKnownDirectives.Stream); if (directiveNode is not null) { var @if = true; string?label = null; var initialCount = 0; foreach (ArgumentNode argument in directiveNode.Arguments) { switch (argument.Name.Value) { case WellKnownDirectives.IfArgument: @if = argument.Value switch { VariableNode variable => variables.GetVariable <bool>(variable.Name.Value), BooleanValueNode b => b.Value, _ => @if }; break; case WellKnownDirectives.LabelArgument: label = argument.Value switch { VariableNode variable => variables.GetVariable <string?>(variable.Name.Value), StringValueNode b => b.Value, _ => label }; break; case WellKnownDirectives.InitialCount: initialCount = argument.Value switch { VariableNode variable => variables.GetVariable <int>(variable.Name.Value), IntValueNode b => b.ToInt32(), _ => initialCount }; break; } } return(new StreamDirective(@if, initialCount, label)); } return(null); }
public void IsInstanceOfType_IntLiteral() { // arrange var uuidType = new UuidType(); var literal = new IntValueNode(123); // act var isOfType = uuidType.IsInstanceOfType(literal); // assert Assert.False(isOfType); }
public void IsInstanceOfType_Wrong_ValueNode() { // arrange var type = new MultiplierPathType(); var input = new IntValueNode(123456); // act bool result = type.IsInstanceOfType(input); // assert Assert.False(result); }
public void IsInstanceOfType_Wrong_ValueNode() { // arrange StringType type = new StringType(); IntValueNode input = new IntValueNode(123456); // act bool result = type.IsInstanceOfType(input); // assert Assert.False(result); }
public void ParseLiteral_IntValueNode_decimal() { // arrange var type = new DecimalType(); var input = new IntValueNode("123"); // act var output = type.ParseLiteral(input); // assert Assert.Equal(123, Assert.IsType <decimal>(output)); }
public void IsInstanceOfType_IntLiteral_True() { // arrange var type = new DecimalType(); var input = new IntValueNode("123"); // act var result = type.IsInstanceOfType(input); // assert Assert.True(result); }
public void ParseLiteral_IntValueNode() { // arrange var byteArrayType = new ByteArrayType(); var literal = new IntValueNode(123); // act Action action = () => byteArrayType.ParseLiteral(literal); // assert Assert.Throws <SerializationException>(action); }
public void ParseLiteral_IntValueNode() { // arrange var uuidType = new UuidType(); var literal = new IntValueNode(123); // act Action action = () => uuidType.ParseLiteral(literal); // assert Assert.Throws <ScalarSerializationException>(action); }
public void IsInstanceOfType_GivenNonUrlValueNode_ReturnsFalse() { // arrange var urlType = new UrlType(); var intValue = new IntValueNode(1); // act var isUrlType = urlType.IsInstanceOfType(intValue); // assert Assert.False(isUrlType); }
public void ParseValue_Nullable() { // arrange var type = new ShortType(); short?input = 123; // act IntValueNode output = (IntValueNode)type.ParseValue(input); // assert Assert.Equal(123, output.ToDouble()); }
public void IsInstanceOfType_FloatLiteral_True() { // arrange var type = new ShortType(); var literal = new IntValueNode(1); // act var result = type.IsInstanceOfType(literal); // assert Assert.True(result); }
protected void LocalTime_ExpectDeserializeToThrowSerializationException() { // arrange ScalarType scalar = CreateType <LocalTimeType>(); object runtimeValue = new IntValueNode(1); // act Exception?result = Record.Exception(() => scalar.Deserialize(runtimeValue)); // assert Assert.IsType <SerializationException>(result); }
public void IsInstanceOfType_IntValueNode() { // arrange var type = new FloatType(); var input = new IntValueNode("123"); // act bool result = type.IsInstanceOfType(input); // assert Assert.True(result); }
protected void LocalTime_ExpectParseResultToThrowSerializationException() { // arrange ScalarType scalar = new LocalTimeType(); IValueNode runtimeValue = new IntValueNode(1); // act Exception?result = Record.Exception(() => scalar.ParseResult(runtimeValue)); // assert Assert.IsType <SerializationException>(result); }
public void ParseLiteral_IntLiteral() { // arrange var type = new ShortType(); var literal = new IntValueNode(1); // act var value = type.ParseLiteral(literal); // assert Assert.IsType <short>(value); Assert.Equal(literal.ToInt16(), value); }
public void ParseLiteral_IntValueNode() { // arrange var type = new FloatType(); var input = new IntValueNode("123"); // act object result = type.ParseLiteral(input); // assert Assert.IsType <double>(result); Assert.Equal(123d, result); }
public void ParseLiteral_IntLiteral() { // arrange var type = new FloatType(); var literal = new IntValueNode(123); // act var value = type.ParseLiteral(literal); // assert Assert.IsType <double>(value); Assert.Equal(literal.ToDouble(), value); }
public void IsInstanceOfType_IntLiteral() { // arrange var byteArrayType = new ByteArrayType(); var literal = new IntValueNode(123); // act bool isOfType = byteArrayType.IsInstanceOfType(literal); // assert Assert.False(isOfType); }
public void ParseLiteral() { // arrange IntValueNode literal = new IntValueNode(null, "12345"); // act IntType integerType = new IntType(); object result = integerType.ParseLiteral(literal); // assert Assert.IsType <int>(result); Assert.Equal(12345, result); }
public void ParseLiteral_IntLiteral() { // arrange var type = new ByteType(); var literal = new IntValueNode(1); // act var value = type.ParseLiteral(literal); // assert Assert.IsType <byte>(value); Assert.Equal(literal.ToByte(), value); }
public void ParseLiteral_IntValueNode() { // arrange var type = new IdType(); var input = new IntValueNode("123456"); // act object output = type.ParseLiteral(input); // assert Assert.IsType <string>(output); Assert.Equal("123456", output); }
protected override void VisitIntValue( IntValueNode node, Action <object> setValue) { if (int.TryParse(node.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int i)) { setValue(i); } else { setValue(node.Value); } }