コード例 #1
0
ファイル: ParserTests.cs プロジェクト: gsuberland/ChavLang
        public void ProgramParsesReturnStatementWithUnsignedInteger()
        {
            string code            = @"
int main()
{
    return 420u;
}
";
            var    program         = new ProgramNode();
            var    function        = new FunctionNode(program, "main", new List <FunctionParameter>());
            var    returnStatement = new ReturnNode(function);
            var    returnValue     = new UIntNode(returnStatement, 420u);

            returnStatement.AddChild(returnValue);
            function.AddChild(returnStatement);
            program.AddChild(function);

            AssertResultMatchesExpectedProgram(code, program);
        }
コード例 #2
0
ファイル: ParserTests.cs プロジェクト: gsuberland/ChavLang
        public void ProgramParsesReturnStatementWithIdentifier()
        {
            string code    = @"int foo = 420;
int main()
{
    return foo;
}
";
            var    program = new ProgramNode();

            program.AddChild(new VariableDeclarationNode(program, "int", "foo", "420"));
            var function        = new FunctionNode(program, "main", new List <FunctionParameter>());
            var returnStatement = new ReturnNode(function);
            var returnValue     = new IdentifierNode(returnStatement, "foo");

            returnStatement.AddChild(returnValue);
            function.AddChild(returnStatement);
            program.AddChild(function);

            AssertResultMatchesExpectedProgram(code, program);
        }