/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* 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 com.intellij.codeInsight.daemon;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
public class LightRainbowHighlightingTest extends LightCodeInsightFixtureTestCase {
public void testRainbowOff() throws Exception {
checkRainbow(
"class TestClass {\n" +
" private static int field = 1;\n" +
" public static void main(String[] args) {\n" +
" ++field;\n" +
" String local1 = null;\n" +
" System.out.println(field + local1 + args[0]);\n" +
" }\n" +
"}", false, false);
}
public void testRainbowSameColorsForSameIds() throws Exception {
checkRainbow(
"class TestClass {\n" +
" public static void main(String[] args) {\n" +
" String local1 = null;\n" +
" System.out.println(local1\n" +
" + args[0]);\n" +
" }\n" +
"}", true, true);
}
public void testRainbowHighlightingIds() throws Exception {
// check no coloring for [this] and etc.
checkRainbow(
"class TestClass {\n" +
" private static int SFIELD = 1;\n" +
" private static int myField = 1;\n" +
" private static Runnable myRunnable = () -> {int a = 0;\n" +
" a++;};\n" +
" public void f(int param1,\n" +
" int param2,\n" +
" int param3) {\n" +
" SFIELD = param1 + param2 + param3 + myField;\n" +
" param1 = this.hashCode() + this.myField;\n" +
" }\n" +
"}", true, false);
}
public void testRainbowParamsInJavadocHaveTheSameColorsAsInCode() throws Exception {
checkRainbow(
"class TestClass {\n" +
" /**\n" +
" * \n" +
" * @param param1\n" +
" * @param param2\n" +
" * @param param3\n" +
" */\n" +
" public void f(int param1,\n" +
" int param2,\n" +
" int param3) {\n" +
" }\n" +
"}", true, true);
}
public void testBadStringHashValue() {
int color = UsedColors.getOrAddColorIndex(new UserDataHolderBase(), "JHZaWC", 5);
assertEquals(3, color);
}
void checkRainbow(@NotNull String code, boolean isRainbowOn, boolean withColor) throws Exception {
myFixture.testRainbow(
"rainbow.java",
code,
isRainbowOn, withColor);
}
}