Skip to content

Commit

Permalink
Fix xml.schema.completion test/implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasblaesing committed Oct 31, 2020
1 parent 32fcad7 commit 69fbca5
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ matrix:
- ant $OPTS -f ide/xml.lexer test
- ant $OPTS -f ide/xml.multiview test
- ant $OPTS -f ide/xml.retriever test
- ant $OPTS -f ide/xml.schema.completion test -Dtest.config=stableBTD
- ant $OPTS -f ide/xml.schema.completion test
- ant $OPTS -f ide/xml.schema.model test
- ant $OPTS -f ide/xml.text test
- ant $OPTS -f ide/xml.text.obsolete90 test
Expand Down
34 changes: 0 additions & 34 deletions ide/xml.schema.completion/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,3 @@

javac.source=1.8
javadoc.arch=${basedir}/arch.xml
# XXX should be deleted in simpletests branch (see project.xml entry):
test.qa-functional.cp.extra=\
../xml.schema/build/test/qa-functional/classes

test.config.all.includes=\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0001.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0002.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0003.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0004.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0005.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0006.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0007.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0008.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0009.class

test.config.stable.includes=\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0001.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0002.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0003.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0004.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0005.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0008.class

test.config.unstable.includes=\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0006.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0007.class,\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0009.class

test.config.working.includes=\
org/netbeans/test/xml/schema/codecompletion/XMLCodeCompletion_0009.class

test.config.stableBTD.includes=**/*Test.class
test.config.stableBTD.excludes=\
**/BasicCompletionTest.class
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,8 @@ private void createPathFromRoot(SyntaxElement se) {
if(se == null)
return;
Stack<SyntaxElement> stack = new Stack<>();
boolean insideEmpty = false;
if(support.isEmptyTag(se)) {
stack.push(se);
insideEmpty = true;
}

while( se != null) {
Expand All @@ -735,11 +733,7 @@ private void createPathFromRoot(SyntaxElement se) {
se = se.getPrevious();
continue;
}
if (support.isEmptyTag(se)) {
if (insideEmpty) {
stack.pop();
}
} else if (support.isStartTag(se)) {
if (support.isStartTag(se)) {
SyntaxElement end = stack.isEmpty() ? null : stack.peek();
if (support.isEndTag(end)) {
if(end.getNode().getNodeName().equals(se.getNode().getNodeName())) {
Expand All @@ -749,7 +743,6 @@ private void createPathFromRoot(SyntaxElement se) {
stack.push(se);
}
}
insideEmpty = false;
se = se.getPrevious();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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
https://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.
-->
<A:rootA2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:A="http://xml.netbeans.org/schema/TNSA"
xsi:schemaLocation="http://xml.netbeans.org/schema/TNSA A.xsd">
<A:rootA3>
<A:A31 />
</A:rootA3>

</A:rootA2>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.netbeans.modules.xml.schema.completion.util;

import java.util.Arrays;
import java.util.List;
import javax.swing.text.Document;
import javax.xml.namespace.QName;
import static junit.framework.Assert.assertEquals;
import org.junit.Test;
import org.netbeans.api.lexer.Language;
import org.netbeans.api.xml.lexer.XMLTokenId;
import org.netbeans.modules.xml.schema.completion.Util;
import org.netbeans.modules.xml.text.api.dom.XMLSyntaxSupport;
import org.openide.filesystems.FileObject;

public class CompletionContextImplTest {
@Test
public void testDetectedPaths() throws Exception {
String TNSA = "http://xml.netbeans.org/schema/TNSA";
String path = "/org/netbeans/modules/xml/schema/completion/resources/CompletionContext.xml";
FileObject fo = Util.getResourceAsFileObject(path);
Document doc = Util.getResourceAsDocument(path);
XMLSyntaxSupport support = XMLSyntaxSupport.getSyntaxSupport(doc);
doc.putProperty(Language.class, XMLTokenId.language());

assertEquals(Arrays.asList(), pathFromRoot(fo, support, 862));
assertEquals(Arrays.asList(new QName(TNSA, "rootA2")), pathFromRoot(fo, support, 872));
assertEquals(Arrays.asList(new QName(TNSA, "rootA2"), new QName(TNSA, "rootA3")), pathFromRoot(fo, support, 1052));
assertEquals(Arrays.asList(new QName(TNSA, "rootA2"), new QName(TNSA, "rootA3"), new QName(TNSA, "A31")), pathFromRoot(fo, support, 1064));
assertEquals(Arrays.asList(new QName(TNSA, "rootA2"), new QName(TNSA, "rootA3")), pathFromRoot(fo, support, 1066));
assertEquals(Arrays.asList(new QName(TNSA, "rootA2")), pathFromRoot(fo, support, 1081));
}

private static List<QName> pathFromRoot(FileObject fo, XMLSyntaxSupport support, int pos) {
CompletionContextImpl cci = new CompletionContextImpl(fo, support, pos);
cci.initContext();
return cci.getPathFromRoot();
}
}

0 comments on commit 69fbca5

Please sign in to comment.