Skip to content

Commit

Permalink
Make DocumentTest windows safe
Browse files Browse the repository at this point in the history
  • Loading branch information
milesziemer committed Jun 13, 2024
1 parent cfe22db commit 41c90cc
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ private static int[] computeLineIndicies(StringBuilder buffer) {
List<Integer> indicies = new ArrayList<>();
indicies.add(0);
while ((next = buffer.indexOf(System.lineSeparator(), off)) != -1) {
indicies.add(next + 1);
off = next + 1;
indicies.add(next + System.lineSeparator().length());
off = next + System.lineSeparator().length();
++matchCount;
}
return indicies.stream().mapToInt(Integer::intValue).toArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private ProjectLoader() {
* @return The loaded project
*/
public static Project loadDetached(String uri, String text) {
LOGGER.info("Loading detached project at " + uri);
String asPath = UriAdapter.toPath(uri);
ValidatedResult<Model> modelResult = Model.assembler()
.addUnparsedModel(asPath, text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.logging.Logger;

/**
Expand All @@ -28,7 +29,7 @@ private UriAdapter() {
*/
public static String toPath(String uri) {
if (uri.startsWith("file://")) {
return uri.replaceFirst("file://", "");
return Paths.get(URI.create(uri)).toString();
} else if (isSmithyJarFile(uri)) {
String decoded = decode(uri);
return fixJarScheme(decoded);
Expand All @@ -42,12 +43,12 @@ public static String toPath(String uri) {
* correct scheme for jars
*/
public static String toUri(String path) {
if (path.startsWith("/")) {
return "file://" + path;
} else if (path.startsWith("jar:file")) {
if (path.startsWith("jar:file")) {
return path.replaceFirst("jar:file", "smithyjar");
} else {
} else if (path.startsWith("smithyjar:")) {
return path;
} else {
return Paths.get(path).toUri().toString();
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/test/java/software/amazon/smithy/lsp/TestWorkspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public String getUri(String filename) {
*/
public void addModel(String relativePath, String model) {
try {
Files.write(root.resolve(relativePath), model.getBytes(StandardCharsets.UTF_8));
Files.write(root.resolve(relativePath), model.replace("\n", System.lineSeparator())
.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -172,7 +173,8 @@ protected void writeModels(Path toDir) {

private static void writeModels(Path toDir, Map<String, String> models) throws Exception {
for (Map.Entry<String, String> entry : models.entrySet()) {
Files.write(toDir.resolve(entry.getKey()), entry.getValue().getBytes(StandardCharsets.UTF_8));
Files.write(toDir.resolve(entry.getKey()),
entry.getValue().replace("\n", System.lineSeparator()).getBytes(StandardCharsets.UTF_8));
}
}
}
Expand Down
Loading

0 comments on commit 41c90cc

Please sign in to comment.