Package ro.redeul.google.go.psi

Source Code of ro.redeul.google.go.psi.GoPsiFunctionTest

package ro.redeul.google.go.psi;

import ro.redeul.google.go.GoPsiTestCase;
import ro.redeul.google.go.lang.psi.GoFile;
import ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration;
import ro.redeul.google.go.lang.psi.toplevel.GoFunctionParameter;
import static ro.redeul.google.go.util.GoPsiTestUtils.childAt;
import static ro.redeul.google.go.util.GoPsiTestUtils.get;

public class GoPsiFunctionTest extends GoPsiTestCase {

    public void testNoParams() throws Exception {
        GoFile file = get(parse("package main; func a() { }"));

        GoFunctionDeclaration func =
            childAt(0,
                    file.getFunctions()
            );

        assertEquals(func.getParameters().length, 0);
    }

    public void testOneParam() throws Exception {
        GoFile file = get(parse("package main; func a(a int) { }"));

        GoFunctionDeclaration func =
            childAt(0,
                    file.getFunctions()
            );

        assertEquals(func.getParameters().length, 1);
    }

    public void testOneParamVariadic() throws Exception {
        GoFile file = get(parse("package main; func a(a ...int) { }"));

        GoFunctionDeclaration func =
            childAt(0,
                    file.getFunctions()
            );

        assertEquals(func.getParameters().length, 1);
    }

    public void testUnnamedParamVariadic() throws Exception {
        GoFile file = get(parse("package main; func a(...int) { }"));
        GoFunctionParameter param =
            childAt(0,
                    childAt(0,
                            file.getFunctions()
                    ).getParameters()
            );

        assertEquals(param.isVariadic(), true);
    }
}
TOP

Related Classes of ro.redeul.google.go.psi.GoPsiFunctionTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.