Files
openide/json/tests/test/com/intellij/json/JsonHighlightingTest.java
Sergey Simonchik ec5f02f021 json: allow empty .jsonl files (WEB-49403)
Also, allow empty .json files to make creating a new JSON file more pleasant.

GitOrigin-RevId: 707361a11b025917c06758f5c058c144f18eee4f
2021-02-08 20:30:56 +00:00

117 lines
5.2 KiB
Java

package com.intellij.json;
import com.intellij.json.codeinsight.JsonDuplicatePropertyKeysInspection;
import com.intellij.json.codeinsight.JsonStandardComplianceInspection;
/**
* @author Mikhail Golubev
*/
public class JsonHighlightingTest extends JsonHighlightingTestBase {
@Override
protected String getExtension() {
return "json";
}
private void enableStandardComplianceInspection(boolean checkComments, boolean checkTopLevelValues) {
final JsonStandardComplianceInspection inspection = new JsonStandardComplianceInspection();
inspection.myWarnAboutComments = checkComments;
inspection.myWarnAboutMultipleTopLevelValues = checkTopLevelValues;
myFixture.enableInspections(inspection);
}
public void testStringLiterals() {
doTest();
}
// IDEA-134372
public void testComplianceProblemsLiteralTopLevelValueIsAllowed() {
enableStandardComplianceInspection(true, true);
doTest();
}
// WEB-16009
public void testComplianceProblemsMultipleTopLevelValuesAllowed() {
enableStandardComplianceInspection(true, false);
}
public void testComplianceProblems() {
enableStandardComplianceInspection(true, true);
doTestHighlighting(false, true, true);
}
public void testJsonLinesComplianceProblems() {
enableStandardComplianceInspection(true, true);
doTestHighlightingForJsonLines(false, true, true);
}
public void testJsonLinesEmptyFile() {
enableStandardComplianceInspection(true, true);
doTestHighlightingForJsonLines(false, true, true);
}
public void testEmptyFile() {
enableStandardComplianceInspection(true, true);
doTestHighlighting(false, true, true);
}
public void testDuplicatePropertyKeys() {
myFixture.enableInspections(JsonDuplicatePropertyKeysInspection.class);
doTestHighlighting(false, true, true);
}
// WEB-13600
public void testIncompleteFloatingPointLiteralsWithExponent() {
doTestHighlighting(false, false, false);
}
// Moved from JavaScript
public void testJSON_with_comment() {
enableStandardComplianceInspection(false, true);
doTestHighlighting(false, true, true);
}
public void testJSON() {
enableStandardComplianceInspection(true, true);
doTestHighlighting(false, true, true);
}
public void testTabInString() {
enableStandardComplianceInspection(true, true);
doTestHighlighting(false, true, true);
}
public void testSemanticHighlighting() {
// WEB-11239
doTest();
}
public void testRainbow() {
myFixture.testRainbow("test.json",
"{\n" +
" <rainbow color='ff000002'>\"type\"</rainbow>: <rainbow color='ff000002'>\"object\"</rainbow>,\n" +
" <rainbow color='ff000002'>\"properties\"</rainbow>: <rainbow color='ff000002'>{</rainbow>\n" +
" <rainbow color='ff000004'>\"versionAsStringArray\"</rainbow>: <rainbow color='ff000004'>{</rainbow>\n" +
" <rainbow color='ff000002'>\"type\"</rainbow>: <rainbow color='ff000002'>\"object\"</rainbow>,\n" +
" <rainbow color='ff000002'>\"properties\"</rainbow>: <rainbow color='ff000002'>{</rainbow>\n" +
" <rainbow color='ff000003'>\"xxx\"</rainbow>: <rainbow color='ff000003'>{</rainbow>\n" +
" <rainbow color='ff000002'>\"type\"</rainbow>: <rainbow color='ff000002'>\"number\"</rainbow>\n" +
" <rainbow color='ff000003'>}</rainbow>,\n" +
" <rainbow color='ff000004'>\"yyy\"</rainbow>: <rainbow color='ff000004'>{</rainbow>\n" +
" <rainbow color='ff000001'>\"description\"</rainbow>: <rainbow color='ff000001'>\"qqq\"</rainbow>,\n" +
" <rainbow color='ff000002'>\"type\"</rainbow>: <rainbow color='ff000002'>\"string\"</rainbow>\n" +
" <rainbow color='ff000004'>}</rainbow>,\n" +
" <rainbow color='ff000001'>\"zzz\"</rainbow>: <rainbow color='ff000001'>{</rainbow>\n" +
" <rainbow color='ff000002'>\"type\"</rainbow>: <rainbow color='ff000002'>\"number\"</rainbow>\n" +
" <rainbow color='ff000001'>}</rainbow>\n" +
" <rainbow color='ff000002'>}</rainbow>,\n" +
" <rainbow color='ff000001'>\"description\"</rainbow>: <rainbow color='ff000001'>\"aaa\"</rainbow>,\n" +
" <rainbow color='ff000003'>\"required\"</rainbow>: <rainbow color='ff000003'>[</rainbow><rainbow color='ff000003'>\"xxx\"</rainbow>, <rainbow color='ff000003'>\"yyy\"</rainbow>, <rainbow color='ff000003'>\"zzz\"</rainbow><rainbow color='ff000003'>]</rainbow>\n" +
" <rainbow color='ff000004'>}</rainbow>\n" +
" <rainbow color='ff000002'>}</rainbow>,\n" +
" <rainbow color='ff000003'>\"required\"</rainbow>: <rainbow color='ff000003'>[</rainbow><rainbow color='ff000003'>\"versionAsStringArray\"</rainbow><rainbow color='ff000003'>]</rainbow>\n" +
"}", true, true);
}
}