/*
 * Copyright (c) 2017. tangzx(love.tangzx@qq.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package completion;

import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;

import java.util.Arrays;
import java.util.List;

/**
 *
 * Created by tangzx on 2017/4/23.
 */
public class TestCompletion extends LightCodeInsightFixtureTestCase {
    @Override
    protected String getTestDataPath() {
        return "src/main/testData/completion";
    }

    public void testLocalCompletion() {
        myFixture.configureByFiles("testCompletion.lua");
        myFixture.complete(CompletionType.BASIC, 1);
        List<String> strings = myFixture.getLookupElementStrings();

        assertNotNull(strings);
        assertTrue(strings.containsAll(Arrays.asList("a", "b", "func1")));
    }

    public void testGlobalCompletion() {
        //test 1
        myFixture.configureByFiles("globals.lua");
        myFixture.configureByText("test.lua", "<caret>");
        myFixture.complete(CompletionType.BASIC, 1);
        List<String> strings = myFixture.getLookupElementStrings();

        assertNotNull(strings);
        assertTrue(strings.containsAll(Arrays.asList("gVar1", "gVar2")));

        //test 2
        myFixture.configureByFiles("globals.lua");
        myFixture.configureByText("test.lua", "gVar2.<caret>");
        myFixture.complete(CompletionType.BASIC, 1);
        strings = myFixture.getLookupElementStrings();

        assertNotNull(strings);
        assertTrue(strings.containsAll(Arrays.asList("aaa", "bbb", "ccc")));
    }

    public void testSelfCompletion() {
        myFixture.configureByFiles("testSelf.lua");
        myFixture.complete(CompletionType.BASIC, 1);
        List<String> strings = myFixture.getLookupElementStrings();

        assertNotNull(strings);
        assertTrue(strings.containsAll(Arrays.asList("self:aaa", "self:abb")));
    }

    public void testParamCompletion() {
        myFixture.configureByFiles("testParam.lua");
        myFixture.complete(CompletionType.BASIC, 1);
        List<String> strings = myFixture.getLookupElementStrings();

        assertNotNull(strings);
        assertTrue(strings.containsAll(Arrays.asList("param1", "param2")));
    }
}

@@ -2783,11 +2783,951 @@
 );%0A    %7D
+%0A%0A    public void testAnnotation() %7B%0A        String code = %22---@class MyClass%5Cn%22 +%0A                %22---@field public name string%5Cn%22 +%0A                %22local s = %7B%7D%5Cn%22 +%0A                %22function s:method()end%5Cn%22 +%0A                %22function s.staticMethod()end%5Cn%22 +%0A                %22---@type MyClass%5Cn%22 +%0A                %22local instance%5Cn%22;%0A%0A        // fields and methods%0A        myFixture.configureByText(%22test.lua%22, code + %22instance.%3Ccaret%3E%22);%0A        myFixture.completeBasic();%0A        List%3CString%3E strings = myFixture.getLookupElementStrings();%0A        assertNotNull(strings);%0A        assertTrue(strings.containsAll(Arrays.asList(%22name%22, %22method%22, %22staticMethod%22)));%0A%0A%0A        // methods%0A        myFixture.configureByText(%22test.lua%22, code + %22instance:%3Ccaret%3E%22);%0A        myFixture.completeBasic();%0A        strings = myFixture.getLookupElementStrings();%0A        assertNotNull(strings);%0A        assertTrue(strings.contains(%22method%22));%0A    %7D
 %0A%7D%0A

test case