public void CreatingNewObject_ShouldHaveCorrectValueCorectDataGiven() { var expected = new BooleanValue(true); var actual = new BooleanLiteral("true"); Assert.Equal(expected, actual.Value); }
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 }; }
public override INode VisitBooleanLiteral(BooleanLiteral booleanLiteral) { return(new BooleanLiteral(booleanLiteral.Context, booleanLiteral.overrideText) { Type = booleanLiteral.Type }); }
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); }
public void BooleanLiteral_ShouldPrint() { var ast = new BooleanLiteral(0, true); Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo( @"Boolean(True) ")); }
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); }
public void TestBooleanLiteralAccept() { Mock <KoraliumSqlVisitor> mock = new Mock <KoraliumSqlVisitor>(); BooleanLiteral booleanLiteral = new BooleanLiteral(); booleanLiteral.Accept(mock.Object); mock.Verify(x => x.VisitBooleanLiteral(booleanLiteral)); }
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); }
public void TestBooleanLiteralFalse() { var actual = new BooleanLiteral() { Value = false }.Print(); var expected = "false"; actual.Should().Be(expected); }
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(); }
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); }
public void TestBooleanLiteralTrue() { var actual = new BooleanLiteral() { Value = true }.Print(); var expected = "true"; actual.Should().Be(expected); }
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); } }
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); }
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); }
public void TestCloneBooleanLiteral() { BooleanLiteral booleanLiteral = new BooleanLiteral() { Value = true }; var clone = booleanLiteral.Clone() as BooleanLiteral; Assert.AreEqual(booleanLiteral, clone); Assert.IsFalse(ReferenceEquals(booleanLiteral, clone)); }
public void TestBooleanLiteralGetValue() { BooleanLiteral booleanLiteral = new BooleanLiteral() { Value = true }; Assert.AreEqual(true, booleanLiteral.GetValue()); booleanLiteral.Value = false; Assert.AreEqual(false, booleanLiteral.GetValue()); }
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); }
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); }
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()); }
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)); }
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); }
public override object Visit(BooleanLiteral that, object value = null) { return null; }
public override object Visit(BooleanLiteral that, object value) { return new ImmediateStorage(that.Value ? "true" : "false"); }
public CodeExpression VisitBooleanLiteral(BooleanLiteral b) { return(m.Prim(b.Value)); }
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)); }
object Evaluate(BooleanLiteral e) { return(e.BooleanValue); }
public static BooleanLiteral CreateBooleanLiteral(string value, Token token) { BooleanLiteral lit = CreateLiteral <BooleanLiteral>(token, value); return(lit); }
// 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; }
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; }
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)); }
public virtual T Visit(BooleanLiteral expr) => Visit(expr as LiteralExpression);
public DataType VisitBooleanLiteral(BooleanLiteral b) { return(DataType.Bool); }
public ValueType Visit(BooleanLiteral literal, VisitorTypeEnvironment environment) { return(new BooleanValueType()); }
public override AstNode VisitBooleanLiteral(BooleanLiteral ast) { ast.ExpressionType = PrimaryType.Boolean; return(base.VisitBooleanLiteral(ast)); }
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); }
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; }
public Expression TypeCheck(BooleanLiteral booleanLiteral, Scope scope) { return booleanLiteral; }
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)); }
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())); }
public virtual void VisitBooleanLiteral(BooleanLiteral n) { }
public virtual TResult Visit(BooleanLiteral literal, TEnvironment environment) { return(default(TResult)); }
public override object Visit(BooleanLiteral that, object value = null) { _writer.Write(that.Value ? "true" : "false"); return null; }
public void VisitBooleanLiteral(BooleanLiteral b) { throw new NotImplementedException(); }
public override AstNode VisitBooleanLiteral(BooleanLiteral ast) { ast.ExpressionType = PrimaryType.Boolean; return base.VisitBooleanLiteral(ast); }
public SerializedType VisitBooleanLiteral(BooleanLiteral booleanLiteral) { throw new NotImplementedException(); }
public virtual object Visit(BooleanLiteral that, object value) { throw new System.NotImplementedException(); }