Skip to content

Commit

Permalink
Fix load, save tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bombbird2001 committed Jun 1, 2024
1 parent 64358fd commit ad1bafd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lwjgl3/src/test/kotlin/DataFileTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ object DataFileTest: FunSpec() {
private fun testCoordsString(coords: String, maxLimit: Float? = null): Position {
val position: Position
coords.split(",").let {
it.size shouldBe 2
withClue(it) {
it.size shouldBe 2
}
val x = it[0].toFloat()
val y = it[1].toFloat()
if (maxLimit != null) {
Expand Down
18 changes: 11 additions & 7 deletions lwjgl3/src/test/kotlin/LoadSaveTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object LoadSaveTest: FunSpec() {

val metaBufferedReader = File("..\\lwjgl3\\src\\test\\kotlin\\loadSaveTestSampleMeta.txt").bufferedReader()
val testMetaString = metaBufferedReader.use { it.readText() }
testMetaString.length shouldBe 87
testMetaString.length shouldBe 111

val saveModifiedBufferedReader = File("..\\lwjgl3\\src\\test\\kotlin\\loadSaveTestSampleSaveModified.txt").bufferedReader()
val testSaveModifiedString = saveModifiedBufferedReader.use { it.readText() }
Expand All @@ -51,7 +51,7 @@ object LoadSaveTest: FunSpec() {

val metaModifiedBufferedReader = File("..\\lwjgl3\\src\\test\\kotlin\\loadSaveTestSampleMetaModified.txt").bufferedReader()
val testMetaModifiedString = metaModifiedBufferedReader.use { it.readText() }
testMetaModifiedString.length shouldBe 88
testMetaModifiedString.length shouldBe 112

@OptIn(ExperimentalStdlibApi::class)
val gameSaveMetaMoshi = Moshi.Builder().build().adapter<GameSaveMeta>()
Expand Down Expand Up @@ -113,7 +113,7 @@ object LoadSaveTest: FunSpec() {
saveHandle.readString().length shouldBeGreaterThan 0

saveMetaHandle.exists().shouldBeTrue()
saveMetaHandle.readString() shouldBe testMetaModifiedString
saveMetaHandle.readString().removeLastPlayedDatetime() shouldBe testMetaModifiedString

backupHandle.exists().shouldBeTrue()
backupHandle.readString() shouldBe testSaveString
Expand All @@ -140,7 +140,7 @@ object LoadSaveTest: FunSpec() {
saveHandle.readString().length shouldBeGreaterThan 0

saveMetaHandle.exists().shouldBeTrue()
saveMetaHandle.readString() shouldBe testMetaModifiedString
saveMetaHandle.readString().removeLastPlayedDatetime() shouldBe testMetaModifiedString

backupHandle.exists().shouldBeTrue()
backupHandle.readString() shouldBe testSaveString
Expand All @@ -166,7 +166,7 @@ object LoadSaveTest: FunSpec() {
saveHandle.readString().length shouldBeGreaterThan 0

saveMetaHandle.exists().shouldBeTrue()
saveMetaHandle.readString() shouldBe testMetaString
saveMetaHandle.readString().removeLastPlayedDatetime() shouldBe testMetaString

backupHandle.exists().shouldBeTrue()
backupHandle.readString() shouldBe testSaveModifiedString
Expand All @@ -193,7 +193,7 @@ object LoadSaveTest: FunSpec() {
saveHandle.readString().length shouldBeGreaterThan 0

saveMetaHandle.exists().shouldBeTrue()
saveMetaHandle.readString() shouldBe testMetaString
saveMetaHandle.readString().removeLastPlayedDatetime() shouldBe testMetaString

backupHandle.exists().shouldBeTrue()
backupHandle.readString() shouldBe testSaveModifiedString
Expand All @@ -220,7 +220,7 @@ object LoadSaveTest: FunSpec() {
saveHandle.readString().length shouldBeGreaterThan 0

saveMetaHandle.exists().shouldBeTrue()
saveMetaHandle.readString() shouldBe testMetaModifiedString
saveMetaHandle.readString().removeLastPlayedDatetime() shouldBe testMetaModifiedString

backupHandle.exists().shouldBeTrue()
backupHandle.readString() shouldBe testSaveString
Expand Down Expand Up @@ -251,4 +251,8 @@ object LoadSaveTest: FunSpec() {
gamesFound[TEST_SAVE_ID].shouldNotBeNull() shouldBe testMetaModified
}
}

private fun String.removeLastPlayedDatetime(): String {
return replace("\"lastPlayedDatetime\":\".*?\"".toRegex(), "\"lastPlayedDatetime\":\"\"")
}
}
2 changes: 1 addition & 1 deletion lwjgl3/src/test/kotlin/loadSaveTestSampleMeta.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"mainName":"TCTP","score":9,"highScore":37,"landed":14,"departed":57,"configNames":""}
{"mainName":"TCTP","score":9,"highScore":37,"landed":14,"departed":57,"configNames":"","lastPlayedDatetime":""}
2 changes: 1 addition & 1 deletion lwjgl3/src/test/kotlin/loadSaveTestSampleMetaModified.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"mainName":"TCTP","score":11,"highScore":37,"landed":14,"departed":57,"configNames":""}
{"mainName":"TCTP","score":11,"highScore":37,"landed":14,"departed":57,"configNames":"","lastPlayedDatetime":""}

0 comments on commit ad1bafd

Please sign in to comment.