Skip to content

Commit

Permalink
[feature] Improve naming of XQuery based XQuery tests. Convert namesp…
Browse files Browse the repository at this point in the history
…ace to Java Package name
  • Loading branch information
adamretter committed Apr 14, 2020
1 parent 50e6433 commit 897c036
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -142,9 +143,43 @@ private static XQueryTestInfo extractTestInfo(final Path path) throws Initializa
}

private String getSuiteName() {
return info.getNamespace();
// final String filename = path.getFileName().toString();
// return filename.substring(0, filename.indexOf('.') - 1);
return namespaceToPackageName(info.getNamespace());
}

private String namespaceToPackageName(final String namespace) {
try {
final URI uri = new URI(namespace);
final StringBuilder packageName = new StringBuilder();
hostNameToPackageName(uri.getHost(), packageName);
pathToPackageName(uri.getPath(), packageName);
packageName.insert(0, "xqts."); // add "xqts." prefix
return packageName.toString();
} catch (final URISyntaxException e) {
throw new RuntimeException(e);
}
}

private void hostNameToPackageName(String host, final StringBuilder buffer) {
while (host != null && !host.isEmpty()) {
if (buffer.length() > 0) {
buffer.append('.');
}

final int idx = host.lastIndexOf('.');
if (idx > -1) {
buffer.append(host.substring(idx + 1));
host = host.substring(0, idx);
} else {
buffer.append(host);
host = null;
}
}
}

private void pathToPackageName(String path, final StringBuilder buffer) {
path = path.replace('.', '_');
path = path.replace('/', '.');
buffer.append(path);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
xquery version "3.1";

module namespace rt="combined-range-function-signature-test";
module namespace rt="http://exist-db.org/xquery/range/combined-range-function-signature/test";

declare namespace test="http://exist-db.org/xquery/xqsuite";

Expand Down

0 comments on commit 897c036

Please sign in to comment.