Skip to content

Commit

Permalink
Issue #171 - Fix additional case when the module directory contains h…
Browse files Browse the repository at this point in the history
…yphen.
  • Loading branch information
ligasgr committed Jan 9, 2017
1 parent 23a48d6 commit c0c99dc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/intellij/xquery/psi/XQueryUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 Grzegorz Ligas <[email protected]> and other contributors
* Copyright 2013-2016 Grzegorz Ligas <[email protected]> and other contributors
* (see the CONTRIBUTORS file).
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -97,7 +97,7 @@ public boolean value(PsiFile psiFile) {
if (virtualFile == null) return false;
String canonicalPath = virtualFile.getCanonicalPath();
if (canonicalPath == null) return false;
return canonicalPath.replaceAll("-[\\d\\.\\w-]+/", "/").endsWith(name);
return canonicalPath.endsWith(name);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 Grzegorz Ligas <[email protected]> and other contributors
* Copyright 2013-2016 Grzegorz Ligas <[email protected]> and other contributors
* (see the CONTRIBUTORS file).
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -86,6 +86,26 @@ public void testModuleReferenceToFileWhenTwoFilesWithTheSameNameAndDifferentDire
assertFalse("sub".equals(((XQueryFile) resolvedReference).getContainingDirectory().getName()));
}

public void testModuleReferenceToFileInDirectoryWithHyphen() {
myFixture.configureByFiles("ModuleReferenceWithHyphen.xq", "sub-dir/ModuleReferenceWithHyphen_ReferencedModule.xq");

PsiElement resolvedReference = getTargetOfReferenceAtCaret(myFixture, XQueryModuleImportPath.class);

assertChildOf(resolvedReference, XQueryFile.class);
assertEquals("ModuleReferenceWithHyphen_ReferencedModule.xq", ((XQueryFile) resolvedReference).getName());
assertTrue("sub-dir".equals(((XQueryFile) resolvedReference).getContainingDirectory().getName()));
}

public void testModuleReferenceToFileInDirectoryWithHyphenInSameDirectory() {
myFixture.configureByFiles("sub-dir/ModuleReferenceWithHyphenInSameDirectory.xq", "sub-dir/ModuleReferenceWithHyphen_ReferencedModule.xq");

PsiElement resolvedReference = getTargetOfReferenceAtCaret(myFixture, XQueryModuleImportPath.class);

assertChildOf(resolvedReference, XQueryFile.class);
assertEquals("ModuleReferenceWithHyphen_ReferencedModule.xq", ((XQueryFile) resolvedReference).getName());
assertTrue("sub-dir".equals(((XQueryFile) resolvedReference).getContainingDirectory().getName()));
}

public void testModuleReferenceWithRelativePath() {
myFixture.configureByFiles("sub/ModuleReference_InSubDir.xq", "ModuleReference.xq");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import module namespace library = "http://module2.namespace" at "<caret>sub-dir/ModuleReferenceWithHyphen_ReferencedModule.xq";

$library:accessible
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import module namespace library = "http://module2.namespace" at "<caret>sub-dir/ModuleReferenceWithHyphen_ReferencedModule.xq";

$library:accessible

0 comments on commit c0c99dc

Please sign in to comment.