public void TestCanBuildBinaryExpression(string fragment, Type leftOperandType, Type rightOperandType, Operator op) { if (FifthParserManager.TryParse <Expression>(fragment, out var ast, out var errors)) { errors.Should().NotBeNull().And.BeEmpty(); ast.Should().NotBeNull(); _ = ast.Should().BeOfType(typeof(BinaryExpression)); var binexp = ast as BinaryExpression; _ = binexp.Should().NotBeNull(); _ = binexp.Left.Should().NotBeNull().And.BeOfType(leftOperandType); _ = binexp.Right.Should().NotBeNull().And.BeOfType(rightOperandType); _ = binexp.Op.Should().Be(op); }
public void TestCanGatherMultipleDefinitions() { var TestProgram = @"main():void {myprint(""hello world"");} myprint(x: string):void { print(x);} blah():void{ result: int = 5; return result;}"; if (!FifthParserManager.TryParse <FifthProgram>(TestProgram, out var ast, out var errors)) { Assert.Fail(); } var globalScope = ast.NearestScope(); var visitor = new SymbolTableBuilderVisitor(); ast.Accept(visitor); var symtab = globalScope.SymbolTable; Assert.That(symtab.Count, Is.EqualTo(5)); // the three above plus two builtins foreach (var v in symtab.Values.ToArray()[0..2])