Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Commit

Permalink
Add last line ending symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaiR committed Oct 28, 2018
1 parent 2ddf47d commit 9ab8af8
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/github/spair/dmm/io/DmmData.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class DmmData {
private int keyLength;

private Map<String, TileContent> tileContentsByKey = new TreeMap<>(new TileKeyComparator());
private Map<TileLocation, TileContent> tileContentsByLocation = new HashMap<>();
private Map<TileContent, String> keysByTileContent = new HashMap<>();
private Map<TileLocation, TileContent> tileContentsByLocation = new HashMap<>();

public void addKeyAndTileContent(final String key, final TileContent tileContent) {
tileContentsByKey.put(key, tileContent);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/github/spair/dmm/io/writer/DmmWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static File saveAsByond(final File fileToSave, final DmmData map) {
writer.write(NEW_LINE);
}

writer.write("\"}");
writer.write("\"}" + NEW_LINE);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -67,6 +67,7 @@ public static File saveAsTGM(final File fileToSave, final DmmData map) {

writer.write("\"}");
}
writer.write(NEW_LINE);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/io/github/spair/dmm/io/ResourceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.io.File;
import java.util.Objects;

public class ResourceUtil {
public final class ResourceUtil {

public static File readResourceFile(final String path) {
return new File(Objects.requireNonNull(ResourceUtil.class.getClassLoader().getResource(path)).getFile());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

public class TileKeyComparatorTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

public class TileObjectComparatorTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.spair.dmm.io.reader;

import io.github.spair.dmm.io.*;
import org.junit.Before;
import io.github.spair.dmm.io.DmmDataUtil;
import io.github.spair.dmm.io.ResourceUtil;
import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

public class DmmReaderTest {

Expand Down
26 changes: 23 additions & 3 deletions src/test/java/io/github/spair/dmm/io/writer/DmmWriterTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.spair.dmm.io.writer;

import io.github.spair.dmm.io.*;
import io.github.spair.dmm.io.DmmData;
import io.github.spair.dmm.io.DmmDataUtil;
import io.github.spair.dmm.io.ResourceUtil;
import io.github.spair.dmm.io.reader.DmmReader;
import org.junit.After;
import org.junit.Before;
Expand All @@ -9,6 +11,7 @@
import java.io.File;
import java.nio.file.Files;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

public class DmmWriterTest {
Expand All @@ -27,16 +30,33 @@ public void tearDown() {
}

@Test
public void testSaveAsByond() {
public void testSaveAsByond() throws Exception {
DmmData dmmData = DmmDataUtil.getDmmData(false);
DmmWriter.saveAsByond(tmpFile, dmmData);
assertEquals(dmmData, DmmReader.readMap(tmpFile));

File basicFile = ResourceUtil.readResourceFile("basic.dmm");
dmmData = DmmReader.readMap(basicFile);
DmmWriter.saveAsByond(tmpFile, dmmData);

assertFilesAreIdentical(basicFile, tmpFile);
}

@Test
public void testSaveAsTGM() {
public void testSaveAsTGM() throws Exception {
DmmData dmmData = DmmDataUtil.getDmmData(true);
DmmWriter.saveAsTGM(tmpFile, dmmData);
assertEquals(dmmData, DmmReader.readMap(tmpFile));

File tgmFile = ResourceUtil.readResourceFile("tgm.dmm");
dmmData = DmmReader.readMap(tgmFile);
DmmWriter.saveAsTGM(tmpFile, dmmData);

assertFilesAreIdentical(tgmFile, tmpFile);
}

private void assertFilesAreIdentical(final File f1, final File f2) throws Exception {
// Fast and easy way to check if last line contains line ending symbol.
assertArrayEquals("files should be absolutely identical", Files.readAllBytes(f1.toPath()), Files.readAllBytes(f2.toPath()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

public class TileContentStringifierTest {

Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/basic.dmm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"a" = (/obj/structure/inflatable/survival,/turf/simulated/floor/pod)
"b" = (/obj/structure/sign/mining/survival{icon_state = "survival"; dir = 1},/obj/structure/inflatable/survival)
"b" = (/obj/structure/sign/mining/survival{dir = 1; icon_state = "survival"},/obj/structure/inflatable/survival)
"c" = (/obj/structure/fans,/turf/simulated/floor/pod,/area/survivalpod{icon_state = "survival"})

(1,1,1) = {"
aaa
bcb
aaa
"}
"}
6 changes: 3 additions & 3 deletions src/test/resources/tgm.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
/turf/simulated/floor/pod)
"b" = (
/obj/structure/sign/mining/survival{
icon_state = "survival";
dir = 1
dir = 1;
icon_state = "survival"
},
/obj/structure/inflatable/survival)
"c" = (
Expand All @@ -29,4 +29,4 @@ a
a
b
a
"}
"}

0 comments on commit 9ab8af8

Please sign in to comment.