summaryrefslogtreecommitdiff
path: root/xml/relaxng/test/org/intellij/plugins/relaxNG/RngHighlightingTest.java
blob: aa44eca4f67442f48bf2b599154a7ae8d5c44d16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * Copyright 2007 Sascha Weinreuter
 *
 * 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 org.intellij.plugins.relaxNG;

import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiPolyVariantReference;
import com.intellij.psi.PsiReference;
import com.intellij.psi.ResolveResult;
import com.intellij.psi.xml.XmlTag;

/**
 * Created by IntelliJ IDEA.
 * User: sweinreuter
 * Date: 25.07.2007
 */
public class RngHighlightingTest extends HighlightingTestBase {

  public String getTestDataPath() {
    return "highlighting/rng";
  }

  public void testSimpleSchema() throws Throwable {
    doHighlightingTest("simple.rng");
  }

  public void testRef1() throws Throwable {
    doHighlightingTest("ref-1.rng");
  }

  public void testRef2() throws Throwable {
    doHighlightingTest("ref-2.rng");
  }

  public void testRef3() throws Throwable {
    doHighlightingTest("ref-3.rng");
  }

  public void testBadRef() throws Throwable {
    doHighlightingTest("bad-ref.rng");
  }

  public void testBadRef2() throws Throwable {
    doHighlightingTest("bad-ref-2.rng");
  }

  public void testBadRef3() throws Throwable {
    doHighlightingTest("bad-ref-3.rng");
  }

  public void testBadRef4() throws Throwable {
    doHighlightingTest("bad-ref-4.rng");
  }

  public void testCreateDefinition1() throws Throwable {
    doTestQuickFix("create-definition-1", "rng");
  }

  public void testParentRef1() throws Throwable {
    doHighlightingTest("parent-ref-1.rng");
  }

  public void testParentRef2() throws Throwable {
    myTestFixture.copyFileToProject("include.rng");
    doHighlightingTest("parent-ref-2.rng");
  }

  public void testBadParentRef1() throws Throwable {
    doHighlightingTest("bad-parent-ref-1.rng");
  }

  public void testBadParentRef2() throws Throwable {
    myTestFixture.copyFileToProject("bad-parent-ref-1.rng");
    doHighlightingTest("bad-parent-ref-2.rng");
  }

  public void testCreateDefinition2() throws Throwable {
    doTestQuickFix("create-definition-2", "rng");
  }

  public void testMissingStartElement() throws Throwable {
    doCustomHighlighting("missing-start-element.rng", false, true);
  }

  public void testMissingStartElementAndInclude() throws Throwable {
    myTestFixture.copyFileToProject("included-grammar.rng");
    doCustomHighlighting("missing-start-element-and-include.rng", false, true);
  }

  public void testBadNsPrefix() throws Throwable {
    doHighlightingTest("bad-ns-prefix.rng");
  }

  public void testBadElement() throws Throwable {
    doExternalToolHighlighting("bad-element.rng");
  }

  public void testInclude() throws Throwable {
    myTestFixture.copyFileToProject("include.rng");
    doHighlightingTest("good-include.rng");
  }

  public void testIncludedRef1() throws Throwable {
    myTestFixture.copyFileToProject("include.rng");
    doHighlightingTest("good-include-ref-1.rng");
  }

  public void testResolveIncludedRef1() throws Throwable {
    myTestFixture.copyFileToProject("include.rng");

    final PsiReference ref = myTestFixture.getReferenceAtCaretPositionWithAssertion("resolve-include-ref-1.rng");
    final PsiElement element = ref.resolve();
    assertTrue(element instanceof XmlTag);
    assertNotSame(element.getContainingFile(), ref.getElement().getContainingFile());
    assertEquals(0, ((XmlTag)element).getSubTags().length);
  }

  public void testResolveIncludedRef2() throws Throwable {
    myTestFixture.copyFileToProject("include.rng");

    final PsiReference ref = myTestFixture.getReferenceAtCaretPositionWithAssertion("resolve-include-ref-2.rng");
    assertTrue("PolyVariantRef", ref instanceof PsiPolyVariantReference);

    final PsiElement element = ref.resolve();
    assertNull(element);

    final ResolveResult[] results = ((PsiPolyVariantReference)ref).multiResolve(false);
    assertEquals(2, results.length);

    for (ResolveResult result : results) {
      PsiElement e = result.getElement();
      assertTrue(e instanceof XmlTag);

      final int contentLength = ((XmlTag)e).getSubTags().length;
      if (e.getContainingFile() == ref.getElement().getContainingFile()) {
        assertEquals(1, contentLength);
      } else {
        assertEquals(0, contentLength);
      }
    }
  }

  public void testBadInclude() throws Throwable {
    doHighlightingTest("bad-include.rng");
  }
}