Ejemplo n.º 1
0
        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;
            }
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        protected override int ParseLiteral(IntValueNode valueSyntax)
        {
            if (valueSyntax.ToInt32() > MaxValue)
            {
                throw ThrowHelper.NegativeIntType_ParseLiteral_IsNotNegative(this);
            }

            return(base.ParseLiteral(valueSyntax));
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        protected override uint ParseLiteral(IntValueNode valueSyntax)
        {
            if (valueSyntax.ToUInt32() < MinValue)
            {
                throw ThrowHelper.UnsignedIntType_ParseLiteral_IsNotUnsigned(this);
            }

            return(valueSyntax.ToUInt32());
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        protected override int ParseLiteral(IntValueNode valueSyntax)
        {
            var result = base.ParseLiteral(valueSyntax);

            if (result < MinValue)
            {
                throw ThrowHelper.PositiveIntType_ParseLiteral_ZeroOrLess(this);
            }

            return(result);
        }
Ejemplo n.º 7
0
    /// <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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        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());
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        public void IsInstanceOfType_IntValueNode()
        {
            // arrange
            var type  = new FloatType();
            var input = new IntValueNode("123");

            // act
            bool result = type.IsInstanceOfType(input);

            // assert
            Assert.True(result);
        }
Ejemplo n.º 22
0
        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);
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
        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);
        }
Ejemplo n.º 27
0
        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);
        }
Ejemplo n.º 28
0
        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);
        }
Ejemplo n.º 29
0
        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);
        }
Ejemplo n.º 30
0
 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);
     }
 }