forked from kolmafia/kolmafia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the "mirror" command to completely mirror gCLI instead of prev…
…ious usage
- Loading branch information
1 parent
5dd54dc
commit 89ba30b
Showing
4 changed files
with
158 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
test/net/sourceforge/kolmafia/textui/command/MirrorCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package net.sourceforge.kolmafia.textui.command; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import net.sourceforge.kolmafia.KoLConstants; | ||
import net.sourceforge.kolmafia.RequestLogger; | ||
import net.sourceforge.kolmafia.utilities.FileUtilities; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
public class MirrorCommandTest extends AbstractCommandTestBase { | ||
|
||
public MirrorCommandTest() { | ||
this.command = "mirror"; | ||
} | ||
|
||
@BeforeEach | ||
public void stopMirrorLogging() { | ||
execute(""); | ||
} | ||
|
||
private String getMirrorLog(String fileName) { | ||
StringBuilder builder = new StringBuilder(); | ||
|
||
try (BufferedReader reader = | ||
FileUtilities.getReader(new File(KoLConstants.ROOT_LOCATION, "chats/" + fileName))) { | ||
String line; | ||
|
||
// Read the full file to a string | ||
while ((line = FileUtilities.readLine(reader)) != null) { | ||
if (builder.length() > 0) { | ||
builder.append("\n"); | ||
} | ||
|
||
builder.append(line); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return builder.toString(); | ||
} | ||
|
||
@Test | ||
public void testMirrorWritesHTML() { | ||
// Open the mirror | ||
execute("chats/test_writes_html"); | ||
|
||
// When `> ` is used as a prefix, the RequestLogger will colorize it assuming its a command | ||
// input. | ||
RequestLogger.printLine("> Fake command input"); | ||
|
||
// Log another line, this should be raw. | ||
RequestLogger.printLine("Raw Line"); | ||
|
||
// Close the mirror | ||
execute(""); | ||
|
||
String mirrorOutput = getMirrorLog("test_writes_html.html"); | ||
|
||
assertTrue(mirrorOutput.contains("<font color=olive>> Fake command input</font><br>")); | ||
assertTrue(mirrorOutput.contains("Raw Line<br>")); | ||
} | ||
|
||
@Test | ||
public void testMirrorClose() { | ||
execute("chats/test_mirror_closes"); | ||
|
||
// Write to the mirror log | ||
RequestLogger.printLine("Some input"); | ||
|
||
// Close the mirror | ||
execute(""); | ||
|
||
// The first test, we're checking that CommandBuffer has no file | ||
assertNull(KoLConstants.commandBuffer.getLogFile()); | ||
|
||
// The second test, write to the command buffer again | ||
RequestLogger.printLine("Should not be seen"); | ||
|
||
// Now read the log and verify that it was not written | ||
String mirrorOutput = getMirrorLog("test_mirror_closes.html"); | ||
|
||
// Test that the second line is not in the output | ||
assertFalse(mirrorOutput.contains("Should not be seen")); | ||
} | ||
|
||
@Test | ||
public void testMultipleMirrorsOpened() { | ||
execute("chats/mirror_1"); | ||
|
||
// Write to the mirror log | ||
RequestLogger.printLine("Mirror 1 Log"); | ||
|
||
// Switch mirrors to mirror_2 | ||
execute("chats/mirror_2"); | ||
|
||
// Write to the mirror log | ||
RequestLogger.printLine("Mirror 2 Log"); | ||
|
||
// Close the mirror | ||
execute(""); | ||
|
||
// Assert that mirror_1 only contains Mirror 1 Log | ||
assertTrue(getMirrorLog("mirror_1.html").contains("Mirror 1 Log")); | ||
assertFalse(getMirrorLog("mirror_2.html").contains("Mirror 1 Log")); | ||
|
||
// Assert that mirror_2 only contains Mirror 2 Log | ||
assertFalse(getMirrorLog("mirror_2.html").contains("Mirror 1 Log")); | ||
assertTrue(getMirrorLog("mirror_2.html").contains("Mirror 2 Log")); | ||
} | ||
|
||
@CsvSource({ | ||
"file,file.html", | ||
"file.html,file.html", | ||
"file.txt,file.txt", | ||
"file.csv,file.csv.html" | ||
}) | ||
public void testMirrorFileNames(String mirrorName, String fileName) { | ||
execute("chats/" + mirrorName); | ||
|
||
RequestLogger.printLine("Filler Line"); | ||
|
||
execute(""); | ||
|
||
assertTrue(getMirrorLog(fileName).contains("Filler Line")); | ||
} | ||
} |