Exemplo n.º 1
0
        public void CreatingNewObject_ShouldHaveCorrectValueCorectDataGiven()
        {
            var expected = new BooleanValue(true);
            var actual   = new BooleanLiteral("true");

            Assert.Equal(expected, actual.Value);
        }
Exemplo n.º 2
0
        public void TestBooleanLiteralEquals()
        {
            BooleanLiteral first = new BooleanLiteral()
            {
                Value = true
            };

            BooleanLiteral firstClone = new BooleanLiteral()
            {
                Value = true
            };

            BooleanLiteral second = new BooleanLiteral()
            {
                Value = false
            };

            //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());
        }
 public override void VisitBooleanLiteral(BooleanLiteral node, CloningAstVisitorContext context)
 {
     context.Result = new BooleanLiteral()
     {
         LiteralValue = node.LiteralValue
     };
 }
Exemplo n.º 4
0
 public override INode VisitBooleanLiteral(BooleanLiteral booleanLiteral)
 {
     return(new BooleanLiteral(booleanLiteral.Context, booleanLiteral.overrideText)
     {
         Type = booleanLiteral.Type
     });
 }
Exemplo n.º 5
0
 public override void Visit(BooleanLiteral node)
 {
     PushLocation(node);
     _ilGen.Ldc_I4(node.Value);
     _result.ValueType = mdr.ValueTypes.Boolean;
     PopLocation();
 }
        public static void SerializeBooleanLiteral()
        {
            var a = new BooleanLiteral(true);
            var b = SerializationUtil.Reserialize(a);

            Assert.AreEqual(a, b);
        }
Exemplo n.º 7
0
        public void BooleanLiteral_ShouldPrint()
        {
            var ast = new BooleanLiteral(0, true);

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"Boolean(True)
"));
        }
Exemplo n.º 8
0
        public void SerializeFalse()
        {
            var falseNode = new BooleanLiteral (false);

            var falseSql = falseNode.Walk (new Sqlizer (foobarTable()));

            Assert.AreEqual ("FALSE", falseSql);
        }
        public static void SerializeXorExpression()
        {
            var v = new BooleanLiteral(true);
            var a = new XorExpression(v, v);
            var b = SerializationUtil.Reserialize(a);

            Assert.AreEqual(a, b);
        }
Exemplo n.º 10
0
        public void TestBooleanLiteralAccept()
        {
            Mock <KoraliumSqlVisitor> mock           = new Mock <KoraliumSqlVisitor>();
            BooleanLiteral            booleanLiteral = new BooleanLiteral();

            booleanLiteral.Accept(mock.Object);
            mock.Verify(x => x.VisitBooleanLiteral(booleanLiteral));
        }
Exemplo n.º 11
0
        public void CheckBooleanDoesNothing()
        {
            var boolean = new BooleanLiteral (true);

            var result = boolean.Walk (new RefChecker (), new [] { "Foobar" });

            Assert.AreEqual (1, result.Length);
            Assert.Contains ("Foobar", result);
        }
Exemplo n.º 12
0
        public void TestBooleanLiteralFalse()
        {
            var actual = new BooleanLiteral()
            {
                Value = false
            }.Print();
            var expected = "false";

            actual.Should().Be(expected);
        }
Exemplo n.º 13
0
        public void TestVisitBooleanLiteral()
        {
            BooleanLiteral     booleanLiteral     = new BooleanLiteral();
            KoraliumSqlVisitor koraliumSqlVisitor = new KoraliumSqlVisitor();

            koraliumSqlVisitor.Visit(booleanLiteral);

            //Nothing to verify yet, only that no exceptions are thrown
            Assert.Pass();
        }
Exemplo n.º 14
0
        public void AllowBooleanEqualityComparison(string op)
        {
            var left = new BooleanLiteral (true);
            var right = new BooleanLiteral (false);
            var compared = new BinaryOperation (op, left, right);

            var type = compared.Walk (new TypeChecker ());

            Assert.AreEqual (SpecType.Boolean, type.Type);
        }
Exemplo n.º 15
0
        public void TestBooleanLiteralTrue()
        {
            var actual = new BooleanLiteral()
            {
                Value = true
            }.Print();
            var expected = "true";

            actual.Should().Be(expected);
        }
Exemplo n.º 16
0
        public void ProcessAction(Stack <Ast> semanticStack, Symbol symbol, Token lastToken)
        {
            switch (symbol)
            {
            case Symbol.MakePlus:
            {
                var right = semanticStack.Pop();
                var left  = semanticStack.Pop();
                var node  = new PlusOperator(position: 0, left: (Expr)left, right: (Expr)right);
                semanticStack.Push(node);
                return;
            }

            case Symbol.MakeTimes:
            {
                var right = semanticStack.Pop();
                var left  = semanticStack.Pop();
                var node  = new TimesOperator(position: 0, left: (Expr)left, right: (Expr)right);
                semanticStack.Push(node);
                return;
            }

            case Symbol.MakeIdentifier:
            {
                var value = lastToken.Value;
                var node  = new Identifier(position: 0, value: value);
                semanticStack.Push(node);
                return;
            }

            case Symbol.MakeIntegerLiteral:
            {
                var node = new IntegerLiteral(position: 0, value: lastToken.Value);
                semanticStack.Push(node);
                return;
            }

            case Symbol.MakeMakeBooleanTrueLiteral:
            {
                var node = new BooleanLiteral(position: 0, value: true);
                semanticStack.Push(node);
                return;
            }

            case Symbol.MakeMakeBooleanFalseLiteral:
            {
                var node = new BooleanLiteral(position: 0, value: false);
                semanticStack.Push(node);
                return;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(symbol), symbol, null);
            }
        }
Exemplo n.º 17
0
        public void CheckDisjunctionDoesNothing()
        {
            var yes = new BooleanLiteral (true);
            var no = new BooleanLiteral (false);
            var disjunction = new LogicalDisjunction (yes, no);

            var result = disjunction.Walk (new RefChecker (), new [] { "Foobar" });

            Assert.AreEqual (1, result.Length);
            Assert.Contains ("Foobar", result);
        }
Exemplo n.º 18
0
 public override AstNode VisitBooleanLiteral(BooleanLiteral ast)
 {
     if (ast.Value)
     {
         m_ilgen.Emit(OpCodes.Ldc_I4_1);
     }
     else
     {
         m_ilgen.Emit(OpCodes.Ldc_I4_0);
     }
     return(ast);
 }
Exemplo n.º 19
0
        public void TestCloneBooleanLiteral()
        {
            BooleanLiteral booleanLiteral = new BooleanLiteral()
            {
                Value = true
            };

            var clone = booleanLiteral.Clone() as BooleanLiteral;

            Assert.AreEqual(booleanLiteral, clone);
            Assert.IsFalse(ReferenceEquals(booleanLiteral, clone));
        }
Exemplo n.º 20
0
        public void TestBooleanLiteralGetValue()
        {
            BooleanLiteral booleanLiteral = new BooleanLiteral()
            {
                Value = true
            };

            Assert.AreEqual(true, booleanLiteral.GetValue());

            booleanLiteral.Value = false;

            Assert.AreEqual(false, booleanLiteral.GetValue());
        }
Exemplo n.º 21
0
        private string Execute(Expression expression)
        {
            var result = expression switch
            {
                FunctionCall functionCall => ExecuteFunction(functionCall),
                VariableReference variableRef => ResolveVariable(variableRef.VariableName),
                StringLiteral stringLiteral => stringLiteral.Value,
                IntegerLiteral integerLiteral => integerLiteral.Value.ToString(CultureInfo.InvariantCulture),
                BooleanLiteral booleanLiteral => booleanLiteral.Value.ToString(),
                // TODO: BooleanExpression and ArithmeticExpression
                _ => throw new NotSupportedException()
            };

            return(result);
        }
Exemplo n.º 22
0
        public UstNode VisitLiteral(DslParser.LiteralContext context)
        {
            Token result;
            var   textSpan = context.GetTextSpan();

            if (context.Id() != null)
            {
                result = ProcessId(context.Id());
            }
            else if (context.String() != null)
            {
                result = new StringLiteral(RemoveQuotes(context.GetText()), textSpan, null);
            }
            else if (context.Oct() != null)
            {
                result = new IntLiteral(
                    System.Convert.ToInt64(context.Oct().GetText(), 8), textSpan, null);
            }
            else if (context.Int() != null)
            {
                result = new IntLiteral(long.Parse(context.Int().GetText()), textSpan, null);
            }
            else if (context.Hex() != null)
            {
                result = new IntLiteral(
                    System.Convert.ToInt64(context.Hex().GetText(), 16), textSpan, null);
            }
            else if (context.Bool() != null)
            {
                result = new BooleanLiteral(bool.Parse(context.Bool().GetText()), textSpan, null);
            }
            else if (context.Null() != null)
            {
                result = new NullLiteral(textSpan, null);
            }
            else
            {
                throw new NotImplementedException();
            }
            return(result);
        }
Exemplo n.º 23
0
        internal List <Statement> GetStatements()
        {
            return(_variables.Select(variable =>
            {
                Expression literal;
                if (variable.Value is int i)
                {
                    literal = new IntegerLiteral("IntegerLiteral", Convert.ToString(i));
                }
                else if (variable.Value is bool b)
                {
                    literal = new BooleanLiteral("BooleanLiteral", b);
                }
                else if (variable.Value is float f)
                {
                    literal = new FloatLiteral("FloatLiteral", Convert.ToDecimal(f));
                }
                else if (variable.Value is DateTime d)
                {
                    literal = new DateTimeLiteral("DateTimeLiteral", d);
                }
                else if (variable.Value is DateTimeOffset o)
                {
                    literal = new DateTimeLiteral("DateTimeLiteral", o.UtcDateTime);
                }
                else
                {
                    literal = new StringLiteral("StringLiteral", Convert.ToString(variable.Value));
                }

                var assignment = new VariableAssignment("VariableAssignment",
                                                        new Identifier("Identifier", variable.Name), literal);

                return new OptionStatement("OptionStatement", assignment) as Statement;
            }).ToList());
        }
Exemplo n.º 24
0
        public void DisjunctionErrorsOnNumbers()
        {
            var numberVal = new NumberLiteral (42);
            var boolVal = new BooleanLiteral (true);
            var left = new LogicalDisjunction (numberVal, boolVal);
            var right = new LogicalDisjunction (boolVal, numberVal);

            var leftEx = Assert.Throws<TypeCheckException>(() => left.Walk (new TypeChecker ()));
            var rightEx = Assert.Throws<TypeCheckException>(() => right.Walk (new TypeChecker ()));

            Assert.That (INCOMPATIBLE_RE.IsMatch (leftEx.Message));
            Assert.That (INCOMPATIBLE_RE.IsMatch (rightEx.Message));
        }
Exemplo n.º 25
0
 public override void VisitBooleanLiteral(BooleanLiteral n)
 {
     //true == 1 / false == 0
     _gen.Emit(n.Val ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
     _lastWalkedType = typeof(int);
 }
Exemplo n.º 26
0
 public override object Visit(BooleanLiteral that, object value = null)
 {
     return null;
 }
Exemplo n.º 27
0
 public override object Visit(BooleanLiteral that, object value)
 {
     return new ImmediateStorage(that.Value ? "true" : "false");
 }
Exemplo n.º 28
0
 public CodeExpression VisitBooleanLiteral(BooleanLiteral b)
 {
     return(m.Prim(b.Value));
 }
Exemplo n.º 29
0
        public void ErrorOnBooleanInequalityComparison(string op)
        {
            var left = new BooleanLiteral (true);
            var right = new BooleanLiteral (false);
            var compared = new BinaryOperation (op, left, right);

            var ex = Assert.Throws<TypeCheckException> (() => compared.Walk (new TypeChecker ()));

            Assert.That (INVALID_RE.IsMatch (ex.Message));
        }
Exemplo n.º 30
0
 object Evaluate(BooleanLiteral e)
 {
     return(e.BooleanValue);
 }
Exemplo n.º 31
0
        public static BooleanLiteral CreateBooleanLiteral(string value, Token token)
        {
            BooleanLiteral lit = CreateLiteral <BooleanLiteral>(token, value);

            return(lit);
        }
Exemplo n.º 32
0
        // Literal := 'true' | 'false' | 'null' | 'self' | SequenceLiteral | StringLiteral
        private Expression DoParseLiteral(List<string> locals)
        {
            Expression result = null;

            int line = m_scanner.Token.Line;
            if (m_scanner.Token.IsKeyword("true"))
            {
                result = new BooleanLiteral(line, true);
                m_scanner.Advance();
            }
            else if (m_scanner.Token.IsKeyword("false"))
            {
                result = new BooleanLiteral(line, false);
                m_scanner.Advance();
            }
            else if (m_scanner.Token.IsKeyword("null"))
            {
                result = new NullLiteral(line);
                m_scanner.Advance();
            }
            else if (m_scanner.Token.IsKeyword("self"))
            {
                result = new SelfLiteral(line);
                m_scanner.Advance();
            }
            else if (m_scanner.Token.IsPunct("["))
            {
                m_scanner.Advance();
                result = DoParseSequenceLiteral(line, locals);
            }
            else if (m_scanner.Token.Kind == TokenKind.String)
            {
                result = DoParseStringLiteral(locals);
            }

            return result;
        }
Exemplo n.º 33
0
        public void SerializeTrue()
        {
            var trueNode = new BooleanLiteral (true);

            var trueSql = trueNode.Walk (new Sqlizer (foobarTable()));

            Assert.AreEqual ("TRUE", trueSql);
        }
        public override object Visit(BooleanLiteral that, object value = null)
        {
            PrintPrologue(that);
            PrintNodeId("Type", that.Type);
            _writer.WriteLine("Value = {0}", that.Value.ToString());
            PrintEpilogue(that);

            that.Type.Visit(this);

            return null;
        }
Exemplo n.º 35
0
        public void ErrorOnBooleanArithmetic(string op)
        {
            var numberVal = new NumberLiteral (42);
            var boolVal = new BooleanLiteral (false);

            var left = new BinaryOperation (op, boolVal, numberVal);
            var right = new BinaryOperation (op, numberVal, boolVal);

            var leftEx = Assert.Throws<TypeCheckException> (() => left.Walk (new TypeChecker ()));
            var rightEx = Assert.Throws<TypeCheckException> (() => right.Walk (new TypeChecker ()));

            Assert.That (INVALID_RE.IsMatch (leftEx.Message));
            Assert.That (INVALID_RE.IsMatch (rightEx.Message));
        }
Exemplo n.º 36
0
 public virtual T Visit(BooleanLiteral expr) => Visit(expr as LiteralExpression);
Exemplo n.º 37
0
 public DataType VisitBooleanLiteral(BooleanLiteral b)
 {
     return(DataType.Bool);
 }
Exemplo n.º 38
0
 public ValueType Visit(BooleanLiteral literal, VisitorTypeEnvironment environment)
 {
     return(new BooleanValueType());
 }
Exemplo n.º 39
0
 public override AstNode VisitBooleanLiteral(BooleanLiteral ast)
 {
     ast.ExpressionType = PrimaryType.Boolean;
     return(base.VisitBooleanLiteral(ast));
 }
Exemplo n.º 40
0
        private void TokenPush(bool as_string)
        {
            if(current_token.Length == 0 && !as_string) {
                return;
            }

            TreeNode node = null;
            string token = current_token.ToString();

            if(Debug) {
                Console.Write("{3}[{0}] TOKEN({4},{5}): [{2}{1}{2}]", scope, token,
                    as_string ? "\"" : String.Empty, String.Empty.PadLeft(scope - 1, ' '),
                    line, column - current_token.Length);
            }

            if(as_string) {
                node = new StringLiteral(token);
            } else if(token == "#t") {
                node = new BooleanLiteral(true);
            } else if(token == "#f") {
                node = new BooleanLiteral(false);
            } else if(token.Length > 0 && token != "." && token != "-" &&
                token != "+" && number_regex.IsMatch(token)) {
                try {
                    if(token.StartsWith("0x") || token.StartsWith("-0x")) {
                        int offset = token[0] == '-' ? 3 : 2;
                        int value = Int32.Parse(token.Substring(offset),
                            NumberStyles.HexNumber, culture_info.NumberFormat);
                        node = new IntLiteral(value * (offset == 3 ? -1 : 1));
                    } else if(token.Contains(".")) {
                        node = new DoubleLiteral(Double.Parse(token,
                            NumberStyles.Float, culture_info.NumberFormat));
                    } else {
                        node = new IntLiteral(Int32.Parse(token,
                            NumberStyles.Integer, culture_info.NumberFormat));
                    }
                } catch {
                    throw new FormatException("Invalid number format: " + token);
                }
            } else {
                node = new FunctionNode(token);
            }

            if(Debug) {
                Console.WriteLine(" => [{0}]", node);
            }

            node.Line = line;
            node.Column = column;
            current_parent.AddChild(node);

            current_token.Remove(0, current_token.Length);
        }
Exemplo n.º 41
0
 public override AstNode VisitBooleanLiteral(BooleanLiteral ast)
 {
     if (ast.Value)
     {
         m_ilgen.Emit(OpCodes.Ldc_I4_1);
     }
     else
     {
         m_ilgen.Emit(OpCodes.Ldc_I4_0);
     }
     return ast;
 }
Exemplo n.º 42
0
 public Expression TypeCheck(BooleanLiteral booleanLiteral, Scope scope)
 {
     return booleanLiteral;
 }
Exemplo n.º 43
0
        public void DisjunctionErrorsOnStrings()
        {
            var stringVal = new StringLiteral ("foobar");
            var boolVal = new BooleanLiteral (true);
            var left = new LogicalDisjunction (stringVal, boolVal);
            var right = new LogicalDisjunction (boolVal, stringVal);

            var leftEx = Assert.Throws<TypeCheckException>(() => left.Walk (new TypeChecker ()));
            var rightEx = Assert.Throws<TypeCheckException>(() => right.Walk (new TypeChecker ()));

            Assert.That (INCOMPATIBLE_RE.IsMatch (leftEx.Message));
            Assert.That (INCOMPATIBLE_RE.IsMatch (rightEx.Message));
        }
Exemplo n.º 44
0
        public void CheckBooleanLiterals()
        {
            var booleanNode = new BooleanLiteral (false);

            var type = booleanNode.Walk (new TypeChecker ());

            Assert.AreEqual (SpecType.Boolean, type.Type);
        }
 public override Value Visit(BooleanLiteral literal)
 {
     return(new BooleanValue(literal.GetValue()));
 }
Exemplo n.º 46
0
 public virtual void VisitBooleanLiteral(BooleanLiteral n)
 {
 }
Exemplo n.º 47
0
 public virtual TResult Visit(BooleanLiteral literal, TEnvironment environment)
 {
     return(default(TResult));
 }
Exemplo n.º 48
0
 public override object Visit(BooleanLiteral that, object value = null)
 {
     _writer.Write(that.Value ? "true" : "false");
     return null;
 }
Exemplo n.º 49
0
 public void VisitBooleanLiteral(BooleanLiteral b)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 50
0
 public override AstNode VisitBooleanLiteral(BooleanLiteral ast)
 {
     ast.ExpressionType = PrimaryType.Boolean;
     return base.VisitBooleanLiteral(ast);
 }
Exemplo n.º 51
0
 public SerializedType VisitBooleanLiteral(BooleanLiteral booleanLiteral)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 52
0
 public virtual object Visit(BooleanLiteral that, object value)
 {
     throw new System.NotImplementedException();
 }