diff options
Diffstat (limited to 'enigma/src/test/java/cuchaz')
| -rw-r--r-- | enigma/src/test/java/cuchaz/enigma/translation/mapping/serde/recaf/TestRecaf.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/enigma/src/test/java/cuchaz/enigma/translation/mapping/serde/recaf/TestRecaf.java b/enigma/src/test/java/cuchaz/enigma/translation/mapping/serde/recaf/TestRecaf.java new file mode 100644 index 0000000..1026f57 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/translation/mapping/serde/recaf/TestRecaf.java | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | package cuchaz.enigma.translation.mapping.serde.recaf; | ||
| 2 | |||
| 3 | import com.google.common.collect.Sets; | ||
| 4 | import com.google.common.jimfs.Jimfs; | ||
| 5 | import cuchaz.enigma.ProgressListener; | ||
| 6 | import cuchaz.enigma.translation.mapping.EntryMapping; | ||
| 7 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | ||
| 8 | import org.junit.Test; | ||
| 9 | |||
| 10 | import java.io.InputStream; | ||
| 11 | import java.nio.charset.StandardCharsets; | ||
| 12 | import java.nio.file.FileSystem; | ||
| 13 | import java.nio.file.Files; | ||
| 14 | import java.nio.file.Path; | ||
| 15 | import java.util.HashSet; | ||
| 16 | import java.util.Set; | ||
| 17 | |||
| 18 | import static org.junit.Assert.assertEquals; | ||
| 19 | |||
| 20 | public class TestRecaf { | ||
| 21 | |||
| 22 | @Test | ||
| 23 | public void testIntegrity() throws Exception { | ||
| 24 | Set<String> contents; | ||
| 25 | try (InputStream in = getClass().getResourceAsStream("/recaf.mappings")) { | ||
| 26 | contents = Sets.newHashSet(new String(in.readAllBytes(), StandardCharsets.UTF_8).split("\\R")); | ||
| 27 | } | ||
| 28 | |||
| 29 | try (FileSystem fs = Jimfs.newFileSystem()) { | ||
| 30 | |||
| 31 | Path path = fs.getPath("recaf.mappings"); | ||
| 32 | Files.writeString(path, String.join("\n", contents)); | ||
| 33 | |||
| 34 | RecafMappingsWriter writer = RecafMappingsWriter.INSTANCE; | ||
| 35 | RecafMappingsReader reader = RecafMappingsReader.INSTANCE; | ||
| 36 | |||
| 37 | EntryTree<EntryMapping> mappings = reader.read(path, ProgressListener.none(), null); | ||
| 38 | writer.write(mappings, path, ProgressListener.none(), null); | ||
| 39 | |||
| 40 | reader.read(path, ProgressListener.none(), null); | ||
| 41 | Set<String> newContents = new HashSet<>(Files.readAllLines(path)); | ||
| 42 | |||
| 43 | assertEquals(contents, newContents); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||