Beispiel #1
0
        public void TestNumericLiteralEquals()
        {
            NumericLiteral first = new NumericLiteral()
            {
                Value = 3
            };

            NumericLiteral firstClone = new NumericLiteral()
            {
                Value = 3
            };

            NumericLiteral second = new NumericLiteral()
            {
                Value = 17
            };

            //Equals
            Assert.IsTrue(Equals(first, firstClone));
            Assert.IsFalse(Equals(first, null));
            Assert.IsFalse(Equals(first, "test"));
            Assert.IsFalse(Equals(first, second));

            //Hash code
            Assert.AreEqual(first.GetHashCode(), firstClone.GetHashCode());
            Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode());
        }
        /// <summary>
        /// Returns the object value of the literal.
        /// </summary>
        /// <param name="lit"></param>
        /// <returns></returns>
        public object GitLiteralValue(Literal lit)
        {
            // Support string literals.
            StringLiteral  stringLit     = null;
            NumericLiteral numberLiteral = null;

            stringLit = lit as StringLiteral;
            if (stringLit != null)
            {
                return(ParseStringLiteralValue(stringLit));
            }

            numberLiteral = lit as NumericLiteral;
            if (numberLiteral != null)
            {
                return(ParseNumericLiteralValue(numberLiteral));
            }

            var nullLiteral = lit as NullLiteral;

            if (nullLiteral != null)
            {
                return(null);
            }

            throw new NotSupportedException("Unknown Literal");
        }
        protected override void VisitNumericLiteral(NumericLiteral item)
        {
            var sqlValue = ParseNumericLiteralValue(item);
            var attName  = GetColumnLogicalAttributeName(this.CurrentColumn);

            this.EntityBuilder.WithAttribute(attName).SetValueWithTypeCoersion(sqlValue);
        }
        /// <summary>
        /// Returns the object value of the numeric literal.
        /// </summary>
        /// <param name="literal"></param>
        /// <returns></returns>
        public object ParseNumericLiteralValue(NumericLiteral literal)
        {
            // cast down from double to int if possible..
            checked
            {
                try
                {
                    if ((literal.Value % 1) == 0)
                    {
                        int intValue = (int)literal.Value;
                        if (intValue == literal.Value)
                        {
                            return(intValue);
                        }
                    }

                    // can we return a decimal instead?
                    var decVal = Convert.ToDecimal(literal.Value);
                    return(decVal);
                }
                catch (OverflowException)
                {
                    //   can't down cast to int so remain as double.
                    return(literal.Value);
                }
            }
        }
Beispiel #5
0
 private Field Numeric(NumericLiteral number)
 {
     return(new Field()
     {
         Value = number.Number
     });
 }
Beispiel #6
0
        public void TestNumericLiteralAccept()
        {
            Mock <KoraliumSqlVisitor> mock           = new Mock <KoraliumSqlVisitor>();
            NumericLiteral            numericLiteral = new NumericLiteral();

            numericLiteral.Accept(mock.Object);
            mock.Verify(x => x.VisitNumericLiteral(numericLiteral));
        }
Beispiel #7
0
 /// <summary>
 /// Gets the numeric properties.
 /// </summary>
 /// <param name="numericValue">The numeric value.</param>
 /// <returns></returns>
 protected static NumericProperties GetNumericProperties(NumericLiteral numericValue)
 {
     return(new NumericProperties
     {
         Precision = numericValue.Value.Length,
         Scale = numericValue.Value.Length - numericValue.Value.IndexOf('.')
     });
 }
Beispiel #8
0
        public void TestNumericLiteralGetValue()
        {
            NumericLiteral numericLiteral = new NumericLiteral()
            {
                Value = 17
            };

            Assert.AreEqual(17m, numericLiteral.GetValue());
        }
Beispiel #9
0
        public void TestNumericLiteralWithDecimal()
        {
            var actual = new NumericLiteral()
            {
                Value = 12.3M
            }.Print();
            var expected = "12.3";

            actual.Should().Be(expected);
        }
        public void TestVisitNumericLiteral()
        {
            NumericLiteral     numericLiteral     = new NumericLiteral();
            KoraliumSqlVisitor koraliumSqlVisitor = new KoraliumSqlVisitor();

            koraliumSqlVisitor.Visit(numericLiteral);

            //Nothing to verify yet, only that no exceptions are thrown
            Assert.Pass();
        }
Beispiel #11
0
        public CSharpSyntaxNode Convert(NumericLiteral node)
        {
            string text = node.Text;

            if (Zeroize(node))
            {
                text += ".0";
            }
            return(SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(text, double.Parse(text))));
        }
Beispiel #12
0
 /// <summary>
 /// Generates the text for a NumericLiteral builder.
 /// </summary>
 /// <param name="item">The NumericLiteral builder to generate the text for.</param>
 protected internal override void VisitNumericLiteral(NumericLiteral item)
 {
     if (item.Format == null)
     {
         writer.Write(item.Value.ToString(CultureInfo.InvariantCulture));
     }
     else
     {
         writer.Write(item.Value.ToString(item.Format, CultureInfo.InvariantCulture));
     }
 }
Beispiel #13
0
        public void TestCloneNumericLiteral()
        {
            NumericLiteral numericLiteral = new NumericLiteral()
            {
                Value = 3
            };

            var clone = numericLiteral.Clone() as NumericLiteral;

            Assert.AreEqual(numericLiteral, clone);
            Assert.IsFalse(ReferenceEquals(numericLiteral, clone));
        }
        protected override void VisitNumericLiteral(NumericLiteral item)
        {
            var sqlValue = ParseNumericLiteralValue(item);

            if (IsVisitingFilterItem)
            {
                IdFilterValue = sqlValue;
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Beispiel #15
0
        public void Decimals(string input, decimal result, int length)
        {
            List <Token> tokens = Lexer.Lex(input);

            Assert.NotNull(tokens);
            NumericLiteral token = Assert.IsType <NumericLiteral>(tokens[0]);

            Assert.Equal(0, token.Start);
            Assert.Equal(length, token.End);
            Assert.Equal(result, token.Number);

            Assert.Equal(input, string.Join("", tokens));
        }
Beispiel #16
0
        private bool Zeroize(NumericLiteral node)
        {
            BinaryExpression expr = node.Parent == null ? null : node.Parent as BinaryExpression;

            if (expr != null &&
                expr.OperatorToken.Kind == NodeKind.SlashToken &&
                expr.Left.Kind == NodeKind.NumericLiteral &&
                expr.Right.Kind == NodeKind.NumericLiteral &&
                node.Text.IndexOf(".") == -1)
            {
                return(true);
            }
            return(false);
        }
Beispiel #17
0
        protected override void VisitNumericLiteral(NumericLiteral item)
        {
            var sqlValue = ParseNumericLiteralValue(item);

            if (CurrentUpdateStatementPart == UpdateStatementPart.WhereClause)
            {
                IdFilterValue = sqlValue;
            }
            else
            {
                var attName = GetColumnLogicalAttributeName(this.CurrentSetterColumn);
                EntityBuilder.WithAttribute(attName).SetValueWithTypeCoersion(sqlValue);
            }
        }
Beispiel #18
0
 public abstract T Visit(NumericLiteral node);
Beispiel #19
0
 /// <summary>
 /// Gets the data type of the value.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 protected static string GetDataType(NumericLiteral value)
 {
     return(value.LiteralType.ToString());
 }
Beispiel #20
0
        private void visitBoundFrame(BoundFrame item)
        {
            IVisitableBuilder literal = new NumericLiteral(item.RowCount);

            literal.Accept(forSubCommand());
        }
Beispiel #21
0
        private LinkedList <Token> GenerateTokens()
        {
            string[]      lines = sourceString.SplitAndKeep(new[] { '\r', '\n' }).ToArray();
            string[]      temp;
            List <string> list = new List <string>();

            foreach (string line in lines)
            {
                list.AddRange(line.Split('\t', ' '));
            }
            temp                = list.ToArray();
            temp                = temp.Where(x => !String.IsNullOrEmpty(x)).ToArray();
            tokenStrings        = new LinkedList <string>(temp);
            currentTokenString  = tokenStrings.First;
            nextTokenString     = currentTokenString.Next;
            previousTokenString = currentTokenString.Previous;
            while (currentTokenString != null)
            {
                Token token = new GenericToken(currentTokenString.Value);
                if (token.isOperator())
                {
                    Operator op = new Operator(currentTokenString.Value);
                    op.Type = op.DetectType();
                    tokens.AddLast(new LinkedListNode <Token>(op));
                }
                else if (token.isKeyword())
                {
                    Keyword keyword = new Keyword(currentTokenString.Value);
                    keyword.Type = keyword.DetectType();
                    tokens.AddLast(new LinkedListNode <Token>(keyword));
                }
                else if (token.isType())
                {
                    Typename typename = new Typename(currentTokenString.Value);
                    typename.Type = typename.DetectType();
                    tokens.AddLast(new LinkedListNode <Token>(typename));
                }
                else
                {
                    token.Type = token.DetectType();
                    if ((EnumTokenType)token.Type == EnumTokenType.STRING)
                    {
                        StringLiteral literal = new StringLiteral(currentTokenString.Value);
                        literal.Type = EnumTokenType.STRING_LITERAL;
                        while (!literal.Value.EndsWith("\""))
                        {
                            currentTokenString = nextTokenString;
                            nextTokenString    = currentTokenString.Next;
                            if (currentTokenString.Value == null)
                            {
                                ThrowError(EnumErrorCodes.STRING_NOT_TETMINATED, "\"");
                                return(null);
                            }
                            literal.Value += " " + currentTokenString.Value;
                        }
                        tokens.AddLast(new LinkedListNode <Token>(literal));
                    }
                    else if ((EnumTokenType)token.Type == EnumTokenType.NUMBER)
                    {
                        NumericLiteral literal = new NumericLiteral(currentTokenString.Value);
                        literal.Type = EnumTokenType.NUMERIC_LITERAL;
                        tokens.AddLast(new LinkedListNode <Token>(literal));
                    }
                    else
                    {
                        tokens.AddLast(new LinkedListNode <Token>(token));
                    }
                }
                currentTokenString = nextTokenString;
                if (nextTokenString != null)
                {
                    nextTokenString = currentTokenString.Next;
                }
                if (previousTokenString != null)
                {
                    previousTokenString = currentTokenString.Previous;
                }
            }
            return(tokens);
        }
Beispiel #22
0
 public Constant VisitNumericLiteral(NumericLiteral number)
 {
     return(Constant.Create(PrimitiveType.Int64, number.Value));
 }
Beispiel #23
0
 public virtual void VisitNumericLiteral(NumericLiteral numericLiteral)
 {
     //NOP
 }
 public override object?Visit(NumericLiteral node)
 {
     AddNodeInfo(node.Value.ToString(CultureInfo.InvariantCulture));
     return(null);
 }
 public override void ExplicitVisit(NumericLiteral fragment)
 {
     _fragments.Add(fragment);
 }
 public override void ExplicitVisit(NumericLiteral node)
 {
     node.Value = "0.1";
     base.ExplicitVisit(node);
 }
Beispiel #27
0
 public NumericExpression(IScope scope, Expression value, NumericLiteral fallback)
     : base(GlobalFunction.NUMB, scope, value)
 {
     _fallback = fallback;
 }
 protected override void VisitNumericLiteral(NumericLiteral item)
 {
     this.ColumnSize = System.Convert.ToInt32(item.Value);
     base.VisitNumericLiteral(item);
 }
 protected override void VisitNumericLiteral(NumericLiteral item)
 {
     this.CurrentNumericLiteralValue = item.Value;
     //   base.VisitNumericLiteral(item);
 }
Beispiel #30
0
 public override void Visit(NumericLiteral node) { this.action(node); }
Beispiel #31
0
 public SerializedType VisitNumericLiteral(NumericLiteral number)
 {
     throw new NotImplementedException();
 }
 public override void ExplicitVisit(NumericLiteral node)
 {
     base.ExplicitVisit(node);
 }