package com.reason.lang.reason;

import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.reason.lang.BaseParsingTestCase;
import com.reason.lang.core.psi.PsiLocalOpen;

public class LocalOpenTest extends BaseParsingTestCase {
    public LocalOpenTest() {
        super("", "re", new RmlParserDefinition());
    }

    public void testLocalParen() {
        PsiElement expression = parseCode("ModA.ModB.(call());");
        PsiLocalOpen o = PsiTreeUtil.findChildOfType(expression, PsiLocalOpen.class);
        assertEquals("(call())", o.getText());
    }

    public void testLocalParen_2() {
        PsiElement expression = parseCode("let x = Js.Promise.(Api.call());");
        PsiLocalOpen o = PsiTreeUtil.findChildOfType(expression, PsiLocalOpen.class);
        assertEquals("(Api.call())", o.getText());
    }

    public void testLocalList() {
        PsiElement expression = parseCode("ModA.ModB.[call()];");
        PsiLocalOpen o = PsiTreeUtil.findChildOfType(expression, PsiLocalOpen.class);
        assertEquals("[call()]", o.getText());
    }

    public void testLocalList_2() {
        PsiElement expression = parseCode("let x = ModA.ModB.[call()];");
        PsiLocalOpen o = PsiTreeUtil.findChildOfType(expression, PsiLocalOpen.class);
        assertEquals("[call()]", o.getText());
    }

    public void testNotLocal() {
        PsiElement expression = firstElement(parseCode("Js.log(\"nok\");"));
        assertFalse(expression instanceof PsiLocalOpen);
    }

}