aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/java/coffee/liz/abstractionengine
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/java/coffee/liz/abstractionengine')
-rw-r--r--core/src/test/java/coffee/liz/abstractionengine/app/ui/editor/vim/VimEngineTest.java880
-rw-r--r--core/src/test/java/coffee/liz/abstractionengine/grid/system/GridCollisionPropagatationSystemTest.java240
-rw-r--r--core/src/test/java/coffee/liz/abstractionengine/grid/system/GridIndexSystemTest.java82
-rw-r--r--core/src/test/java/coffee/liz/abstractionengine/grid/system/GridMovementSystemTest.java44
-rw-r--r--core/src/test/java/coffee/liz/abstractionengine/grid/system/GridPhysicsSystemTest.java42
5 files changed, 644 insertions, 644 deletions
diff --git a/core/src/test/java/coffee/liz/abstractionengine/app/ui/editor/vim/VimEngineTest.java b/core/src/test/java/coffee/liz/abstractionengine/app/ui/editor/vim/VimEngineTest.java
index 31d823a..5248904 100644
--- a/core/src/test/java/coffee/liz/abstractionengine/app/ui/editor/vim/VimEngineTest.java
+++ b/core/src/test/java/coffee/liz/abstractionengine/app/ui/editor/vim/VimEngineTest.java
@@ -13,566 +13,566 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class VimEngineTest {
- private static class FakeBuffer implements EditorBuffer {
- private String text;
- private int cursor;
- private int selectionStart;
- private int selectionEnd;
- private boolean hasSelection;
+ private static class FakeBuffer implements EditorBuffer {
+ private String text;
+ private int cursor;
+ private int selectionStart;
+ private int selectionEnd;
+ private boolean hasSelection;
- private FakeBuffer(final String text, final int cursor) {
- this.text = text;
- this.cursor = Math.max(0, Math.min(cursor, text.length()));
- this.selectionStart = 0;
- this.selectionEnd = 0;
- this.hasSelection = false;
- }
+ private FakeBuffer(final String text, final int cursor) {
+ this.text = text;
+ this.cursor = Math.max(0, Math.min(cursor, text.length()));
+ this.selectionStart = 0;
+ this.selectionEnd = 0;
+ this.hasSelection = false;
+ }
- @Override
- public String getText() {
- return text;
- }
+ @Override
+ public String getText() {
+ return text;
+ }
- @Override
- public void setText(final String text) {
- this.text = text;
- this.cursor = Math.max(0, Math.min(cursor, text.length()));
- if (hasSelection) {
- this.selectionStart = Math.max(0, Math.min(selectionStart, text.length()));
- this.selectionEnd = Math.max(0, Math.min(selectionEnd, text.length()));
- this.hasSelection = selectionStart != selectionEnd;
- }
- }
+ @Override
+ public void setText(final String text) {
+ this.text = text;
+ this.cursor = Math.max(0, Math.min(cursor, text.length()));
+ if (hasSelection) {
+ this.selectionStart = Math.max(0, Math.min(selectionStart, text.length()));
+ this.selectionEnd = Math.max(0, Math.min(selectionEnd, text.length()));
+ this.hasSelection = selectionStart != selectionEnd;
+ }
+ }
- @Override
- public int getCursorPosition() {
- return cursor;
- }
+ @Override
+ public int getCursorPosition() {
+ return cursor;
+ }
- @Override
- public void setCursorPosition(final int cursorPosition) {
- this.cursor = Math.max(0, Math.min(cursorPosition, text.length()));
- }
+ @Override
+ public void setCursorPosition(final int cursorPosition) {
+ this.cursor = Math.max(0, Math.min(cursorPosition, text.length()));
+ }
- @Override
- public int getCursorLine() {
- int line = 0;
- for (int i = 0; i < Math.min(cursor, text.length()); i++) {
- if (text.charAt(i) == '\n') {
- line++;
- }
- }
- return line;
- }
+ @Override
+ public int getCursorLine() {
+ int line = 0;
+ for (int i = 0; i < Math.min(cursor, text.length()); i++) {
+ if (text.charAt(i) == '\n') {
+ line++;
+ }
+ }
+ return line;
+ }
- @Override
- public int getLines() {
- if (text.isEmpty()) {
- return 1;
- }
- int lines = 1;
- for (int i = 0; i < text.length(); i++) {
- if (text.charAt(i) == '\n') {
- lines++;
- }
- }
- return lines;
- }
+ @Override
+ public int getLines() {
+ if (text.isEmpty()) {
+ return 1;
+ }
+ int lines = 1;
+ for (int i = 0; i < text.length(); i++) {
+ if (text.charAt(i) == '\n') {
+ lines++;
+ }
+ }
+ return lines;
+ }
- @Override
- public void moveCursorLine(final int line) {
- final int targetLine = Math.max(0, Math.min(line, getLines() - 1));
- final int currentLineStart = findLineStartByNumber(getCursorLine());
- final int currentColumn = cursor - currentLineStart;
- final int targetStart = findLineStartByNumber(targetLine);
- final int targetEndExclusive = findLineEndExclusive(targetStart);
- this.cursor = Math.min(targetStart + currentColumn, targetEndExclusive);
- }
+ @Override
+ public void moveCursorLine(final int line) {
+ final int targetLine = Math.max(0, Math.min(line, getLines() - 1));
+ final int currentLineStart = findLineStartByNumber(getCursorLine());
+ final int currentColumn = cursor - currentLineStart;
+ final int targetStart = findLineStartByNumber(targetLine);
+ final int targetEndExclusive = findLineEndExclusive(targetStart);
+ this.cursor = Math.min(targetStart + currentColumn, targetEndExclusive);
+ }
- @Override
- public void setSelectionEndpoints(final int selectionStart, final int cursorPosition) {
- final int clampedSelectionStart = Math.max(0, Math.min(selectionStart, text.length()));
- this.cursor = Math.max(0, Math.min(cursorPosition, text.length()));
- this.selectionStart = Math.min(clampedSelectionStart, this.cursor);
- this.selectionEnd = Math.max(clampedSelectionStart, this.cursor);
- this.hasSelection = this.selectionStart != this.selectionEnd;
- }
+ @Override
+ public void setSelectionEndpoints(final int selectionStart, final int cursorPosition) {
+ final int clampedSelectionStart = Math.max(0, Math.min(selectionStart, text.length()));
+ this.cursor = Math.max(0, Math.min(cursorPosition, text.length()));
+ this.selectionStart = Math.min(clampedSelectionStart, this.cursor);
+ this.selectionEnd = Math.max(clampedSelectionStart, this.cursor);
+ this.hasSelection = this.selectionStart != this.selectionEnd;
+ }
- @Override
- public void clearSelection() {
- this.hasSelection = false;
- this.selectionStart = 0;
- this.selectionEnd = 0;
- }
+ @Override
+ public void clearSelection() {
+ this.hasSelection = false;
+ this.selectionStart = 0;
+ this.selectionEnd = 0;
+ }
- private int findLineStartByNumber(final int targetLine) {
- int line = 0;
- int index = 0;
- while (line < targetLine && index < text.length()) {
- if (text.charAt(index) == '\n') {
- line++;
- }
- index++;
- }
- return index;
- }
+ private int findLineStartByNumber(final int targetLine) {
+ int line = 0;
+ int index = 0;
+ while (line < targetLine && index < text.length()) {
+ if (text.charAt(index) == '\n') {
+ line++;
+ }
+ index++;
+ }
+ return index;
+ }
- private int findLineEndExclusive(final int lineStart) {
- int index = lineStart;
- while (index < text.length() && text.charAt(index) != '\n') {
- index++;
- }
- return index;
- }
- }
+ private int findLineEndExclusive(final int lineStart) {
+ int index = lineStart;
+ while (index < text.length() && text.charAt(index) != '\n') {
+ index++;
+ }
+ return index;
+ }
+ }
- @Test
- public void visualSelectionAndEscapeRestoresCursorToSelectionStart() {
- final FakeBuffer buffer = new FakeBuffer("abcdef\n", 1);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void visualSelectionAndEscapeRestoresCursorToSelectionStart() {
+ final FakeBuffer buffer = new FakeBuffer("abcdef\n", 1);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'v', 'l', 'l');
+ type(controller, 'v', 'l', 'l');
- assertEquals(1, buffer.selectionStart);
- assertEquals(3, buffer.selectionEnd);
- assertEquals(3, buffer.getCursorPosition());
+ assertEquals(1, buffer.selectionStart);
+ assertEquals(3, buffer.selectionEnd);
+ assertEquals(3, buffer.getCursorPosition());
- controller.handleKeyDown(Input.Keys.ESCAPE);
+ controller.handleKeyDown(Input.Keys.ESCAPE);
- assertFalse(buffer.hasSelection);
- assertEquals(1, buffer.getCursorPosition());
- }
+ assertFalse(buffer.hasSelection);
+ assertEquals(1, buffer.getCursorPosition());
+ }
- @Test
- public void normalModeUsesBlockCursorAndRelativeLines() {
- final FakeBuffer buffer = new FakeBuffer("abc", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void normalModeUsesBlockCursorAndRelativeLines() {
+ final FakeBuffer buffer = new FakeBuffer("abc", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- assertEquals(CursorStyle.BLOCK, controller.getRenderState().cursorStyle());
- assertEquals(LineNumberMode.RELATIVE, controller.getRenderState().lineNumberMode());
- }
+ assertEquals(CursorStyle.BLOCK, controller.getRenderState().cursorStyle());
+ assertEquals(LineNumberMode.RELATIVE, controller.getRenderState().lineNumberMode());
+ }
- @Test
- public void insertModeUsesCaretAndAbsoluteLines() {
- final FakeBuffer buffer = new FakeBuffer("abc", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void insertModeUsesCaretAndAbsoluteLines() {
+ final FakeBuffer buffer = new FakeBuffer("abc", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'i');
+ type(controller, 'i');
- assertEquals(CursorStyle.CARET, controller.getRenderState().cursorStyle());
- assertEquals(LineNumberMode.ABSOLUTE, controller.getRenderState().lineNumberMode());
- }
+ assertEquals(CursorStyle.CARET, controller.getRenderState().cursorStyle());
+ assertEquals(LineNumberMode.ABSOLUTE, controller.getRenderState().lineNumberMode());
+ }
- @Test
- public void enteringVisualModeDoesNotMoveCursor() {
- final FakeBuffer buffer = new FakeBuffer("abcdef", 2);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void enteringVisualModeDoesNotMoveCursor() {
+ final FakeBuffer buffer = new FakeBuffer("abcdef", 2);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- controller.handleKeyTyped('v');
+ controller.handleKeyTyped('v');
- assertEquals(2, buffer.getCursorPosition());
- }
+ assertEquals(2, buffer.getCursorPosition());
+ }
- @Test
- public void visualModeCanMoveLeftToShrinkSelection() {
- final FakeBuffer buffer = new FakeBuffer("abcdef", 1);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void visualModeCanMoveLeftToShrinkSelection() {
+ final FakeBuffer buffer = new FakeBuffer("abcdef", 1);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'v', 'l', 'l');
- assertEquals(1, buffer.selectionStart);
- assertEquals(3, buffer.selectionEnd);
+ type(controller, 'v', 'l', 'l');
+ assertEquals(1, buffer.selectionStart);
+ assertEquals(3, buffer.selectionEnd);
- type(controller, 'h');
- assertEquals(1, buffer.selectionStart);
- assertEquals(2, buffer.selectionEnd);
- assertEquals(2, buffer.getCursorPosition());
- }
+ type(controller, 'h');
+ assertEquals(1, buffer.selectionStart);
+ assertEquals(2, buffer.selectionEnd);
+ assertEquals(2, buffer.getCursorPosition());
+ }
- @Test
- public void visualBackwardSelectionIncludesAnchorCharacter() {
- final FakeBuffer buffer = new FakeBuffer("abcdef", 3);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void visualBackwardSelectionIncludesAnchorCharacter() {
+ final FakeBuffer buffer = new FakeBuffer("abcdef", 3);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'v', 'h');
+ type(controller, 'v', 'h');
- assertTrue(buffer.hasSelection);
- assertEquals("cd", buffer.getText().substring(buffer.selectionStart, buffer.selectionEnd));
- }
+ assertTrue(buffer.hasSelection);
+ assertEquals("cd", buffer.getText().substring(buffer.selectionStart, buffer.selectionEnd));
+ }
- @Test
- public void visualZeroMotionBackwardIncludesAnchorCharacter() {
- final FakeBuffer buffer = new FakeBuffer("abcdef", 3);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void visualZeroMotionBackwardIncludesAnchorCharacter() {
+ final FakeBuffer buffer = new FakeBuffer("abcdef", 3);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'v', '0');
+ type(controller, 'v', '0');
- assertTrue(buffer.hasSelection);
- assertEquals("abcd", buffer.getText().substring(buffer.selectionStart, buffer.selectionEnd));
- }
+ assertTrue(buffer.hasSelection);
+ assertEquals("abcd", buffer.getText().substring(buffer.selectionStart, buffer.selectionEnd));
+ }
- @Test
- public void visualModeGgMovesToStartAndKeepsSelection() {
- final FakeBuffer buffer = new FakeBuffer("one\ntwo\nthree", 7);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void visualModeGgMovesToStartAndKeepsSelection() {
+ final FakeBuffer buffer = new FakeBuffer("one\ntwo\nthree", 7);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'v', 'g', 'g');
+ type(controller, 'v', 'g', 'g');
- assertEquals(0, buffer.getCursorPosition());
- assertTrue(buffer.hasSelection);
- assertEquals("one\ntwo\n", buffer.getText().substring(buffer.selectionStart, buffer.selectionEnd));
- }
+ assertEquals(0, buffer.getCursorPosition());
+ assertTrue(buffer.hasSelection);
+ assertEquals("one\ntwo\n", buffer.getText().substring(buffer.selectionStart, buffer.selectionEnd));
+ }
- @Test
- public void visualLineSelectionWorksWithShiftV() {
- final FakeBuffer buffer = new FakeBuffer("one\ntwo\nthree\n", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void visualLineSelectionWorksWithShiftV() {
+ final FakeBuffer buffer = new FakeBuffer("one\ntwo\nthree\n", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'V', 'j');
+ type(controller, 'V', 'j');
- assertTrue(buffer.hasSelection);
- assertEquals(0, buffer.selectionStart);
- assertEquals(8, buffer.selectionEnd);
- }
+ assertTrue(buffer.hasSelection);
+ assertEquals(0, buffer.selectionStart);
+ assertEquals(8, buffer.selectionEnd);
+ }
- @Test
- public void visualLineJThenKUpdatesSelectionAndCursorLine() {
- final FakeBuffer buffer = new FakeBuffer("one\ntwo\nthree\n", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void visualLineJThenKUpdatesSelectionAndCursorLine() {
+ final FakeBuffer buffer = new FakeBuffer("one\ntwo\nthree\n", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'V', 'j');
- assertEquals(0, buffer.selectionStart);
- assertEquals(8, buffer.selectionEnd);
+ type(controller, 'V', 'j');
+ assertEquals(0, buffer.selectionStart);
+ assertEquals(8, buffer.selectionEnd);
- type(controller, 'k');
- assertEquals(0, buffer.selectionStart);
- assertEquals(4, buffer.selectionEnd);
- assertEquals(0, buffer.getCursorLine());
- }
+ type(controller, 'k');
+ assertEquals(0, buffer.selectionStart);
+ assertEquals(4, buffer.selectionEnd);
+ assertEquals(0, buffer.getCursorLine());
+ }
- @Test
- public void visualLineModeDoesNotMoveCursorPastLastRealTrailingEmptyLine() {
- final FakeBuffer buffer = new FakeBuffer("a\n\n\n", 2);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void visualLineModeDoesNotMoveCursorPastLastRealTrailingEmptyLine() {
+ final FakeBuffer buffer = new FakeBuffer("a\n\n\n", 2);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'V', 'j');
+ type(controller, 'V', 'j');
- assertEquals(3, buffer.getCursorPosition());
- assertEquals(2, buffer.getCursorLine());
- }
+ assertEquals(3, buffer.getCursorPosition());
+ assertEquals(2, buffer.getCursorLine());
+ }
- @Test
- public void openLineBelowPlacesCursorOnNewLine() {
- final FakeBuffer buffer = new FakeBuffer("abc\ndef", 1);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void openLineBelowPlacesCursorOnNewLine() {
+ final FakeBuffer buffer = new FakeBuffer("abc\ndef", 1);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- controller.handleKeyTyped('o');
+ controller.handleKeyTyped('o');
- assertEquals("abc\n\ndef", buffer.getText());
- assertEquals(4, buffer.getCursorPosition());
- }
+ assertEquals("abc\n\ndef", buffer.getText());
+ assertEquals(4, buffer.getCursorPosition());
+ }
- @Test
- public void moveDownCanReachTrailingEmptyLines() {
- final FakeBuffer buffer = new FakeBuffer("a\n\n\n", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void moveDownCanReachTrailingEmptyLines() {
+ final FakeBuffer buffer = new FakeBuffer("a\n\n\n", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'j', 'j', 'j');
+ type(controller, 'j', 'j', 'j');
- assertEquals(3, buffer.getCursorPosition());
- }
+ assertEquals(3, buffer.getCursorPosition());
+ }
- @Test
- public void openLineBelowOnTrailingEmptyLineMovesOneLineDown() {
- final FakeBuffer buffer = new FakeBuffer("a\n\n\n", 2);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void openLineBelowOnTrailingEmptyLineMovesOneLineDown() {
+ final FakeBuffer buffer = new FakeBuffer("a\n\n\n", 2);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- controller.handleKeyTyped('o');
+ controller.handleKeyTyped('o');
- assertEquals("a\n\n\n\n", buffer.getText());
- assertEquals(3, buffer.getCursorPosition());
- }
+ assertEquals("a\n\n\n\n", buffer.getText());
+ assertEquals(3, buffer.getCursorPosition());
+ }
- @Test
- public void gMovesToLastNavigableCharacter() {
- final FakeBuffer buffer = new FakeBuffer("alpha\nbeta\n", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void gMovesToLastNavigableCharacter() {
+ final FakeBuffer buffer = new FakeBuffer("alpha\nbeta\n", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- controller.handleKeyTyped('G');
+ controller.handleKeyTyped('G');
- assertEquals(9, buffer.getCursorPosition());
- }
+ assertEquals(9, buffer.getCursorPosition());
+ }
- @Test
- public void ggMovesToTopOfFile() {
- final FakeBuffer buffer = new FakeBuffer("alpha\nbeta\n", 9);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void ggMovesToTopOfFile() {
+ final FakeBuffer buffer = new FakeBuffer("alpha\nbeta\n", 9);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'g', 'g');
+ type(controller, 'g', 'g');
- assertEquals(0, buffer.getCursorPosition());
- }
+ assertEquals(0, buffer.getCursorPosition());
+ }
- @Test
- public void ddThenPastePlacesLineBelow() {
- final FakeBuffer buffer = new FakeBuffer("a\nb", 2);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void ddThenPastePlacesLineBelow() {
+ final FakeBuffer buffer = new FakeBuffer("a\nb", 2);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'd', 'd', 'p');
+ type(controller, 'd', 'd', 'p');
- assertEquals("a\nb\n", buffer.getText());
- }
+ assertEquals("a\nb\n", buffer.getText());
+ }
- @Test
- public void yyThenPastePlacesLineBelow() {
- final FakeBuffer buffer = new FakeBuffer("one\ntwo\n", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void yyThenPastePlacesLineBelow() {
+ final FakeBuffer buffer = new FakeBuffer("one\ntwo\n", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'y', 'y', 'p');
+ type(controller, 'y', 'y', 'p');
- assertEquals("one\none\ntwo\n", buffer.getText());
- }
+ assertEquals("one\none\ntwo\n", buffer.getText());
+ }
- @Test
- public void dwDeletesWord() {
- final FakeBuffer buffer = new FakeBuffer("one two", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void dwDeletesWord() {
+ final FakeBuffer buffer = new FakeBuffer("one two", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'd', 'w');
+ type(controller, 'd', 'w');
- assertEquals("two", buffer.getText());
- }
+ assertEquals("two", buffer.getText());
+ }
- @Test
- public void dlDeletesExactlyOneCharacter() {
- final FakeBuffer buffer = new FakeBuffer("abcd", 1);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void dlDeletesExactlyOneCharacter() {
+ final FakeBuffer buffer = new FakeBuffer("abcd", 1);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'd', 'l');
+ type(controller, 'd', 'l');
- assertEquals("acd", buffer.getText());
- }
+ assertEquals("acd", buffer.getText());
+ }
- @Test
- public void dlOnLastCharacterDeletesLastCharacter() {
- final FakeBuffer buffer = new FakeBuffer("abcd", 3);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void dlOnLastCharacterDeletesLastCharacter() {
+ final FakeBuffer buffer = new FakeBuffer("abcd", 3);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'd', 'l');
+ type(controller, 'd', 'l');
- assertEquals("abc", buffer.getText());
- assertEquals(2, buffer.getCursorPosition());
- }
+ assertEquals("abc", buffer.getText());
+ assertEquals(2, buffer.getCursorPosition());
+ }
- @Test
- public void undoRevertsLatestEdit() {
- final FakeBuffer buffer = new FakeBuffer("abc", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void undoRevertsLatestEdit() {
+ final FakeBuffer buffer = new FakeBuffer("abc", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- controller.handleKeyTyped('x');
- assertEquals("bc", buffer.getText());
+ controller.handleKeyTyped('x');
+ assertEquals("bc", buffer.getText());
- controller.handleKeyTyped('u');
- assertEquals("abc", buffer.getText());
- assertEquals(0, buffer.getCursorPosition());
- }
+ controller.handleKeyTyped('u');
+ assertEquals("abc", buffer.getText());
+ assertEquals(0, buffer.getCursorPosition());
+ }
- @Test
- public void ctrlRRedoesAfterUndo() {
- final FakeBuffer buffer = new FakeBuffer("abc", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void ctrlRRedoesAfterUndo() {
+ final FakeBuffer buffer = new FakeBuffer("abc", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- controller.handleKeyTyped('x');
- controller.handleKeyTyped('u');
- controller.handleKeyDown(Input.Keys.R, true);
+ controller.handleKeyTyped('x');
+ controller.handleKeyTyped('u');
+ controller.handleKeyDown(Input.Keys.R, true);
- assertEquals("bc", buffer.getText());
- }
+ assertEquals("bc", buffer.getText());
+ }
- @Test
- public void keyDownMotionReturnsSuppressTypedAndMovesCursor() {
- final FakeBuffer buffer = new FakeBuffer("abc\ndef", 1);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void keyDownMotionReturnsSuppressTypedAndMovesCursor() {
+ final FakeBuffer buffer = new FakeBuffer("abc\ndef", 1);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- final boolean handled = controller.onKeyDown(new KeyEvent(Input.Keys.J, Set.of()));
+ final boolean handled = controller.onKeyDown(new KeyEvent(Input.Keys.J, Set.of()));
- assertTrue(handled);
- assertEquals(5, buffer.getCursorPosition());
- }
+ assertTrue(handled);
+ assertEquals(5, buffer.getCursorPosition());
+ }
- @Test
- public void keyDownShiftVStartsVisualLineMode() {
- final FakeBuffer buffer = new FakeBuffer("one\ntwo\nthree\n", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void keyDownShiftVStartsVisualLineMode() {
+ final FakeBuffer buffer = new FakeBuffer("one\ntwo\nthree\n", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- final boolean handled = controller.onKeyDown(new KeyEvent(Input.Keys.V, Set.of(EditorModifier.SHIFT)));
+ final boolean handled = controller.onKeyDown(new KeyEvent(Input.Keys.V, Set.of(EditorModifier.SHIFT)));
- assertTrue(handled);
- assertEquals("-- VISUAL LINE --", controller.getStatusText());
- }
+ assertTrue(handled);
+ assertEquals("-- VISUAL LINE --", controller.getStatusText());
+ }
- @Test
- public void controlCharacterRRedoesAfterUndo() {
- final FakeBuffer buffer = new FakeBuffer("abc", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void controlCharacterRRedoesAfterUndo() {
+ final FakeBuffer buffer = new FakeBuffer("abc", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- controller.handleKeyTyped('x');
- controller.handleKeyTyped('u');
- controller.handleKeyTyped((char) 18);
+ controller.handleKeyTyped('x');
+ controller.handleKeyTyped('u');
+ controller.handleKeyTyped((char) 18);
- assertEquals("bc", buffer.getText());
- }
+ assertEquals("bc", buffer.getText());
+ }
- @Test
- public void searchAndNextFindMatches() {
- final FakeBuffer buffer = new FakeBuffer("cat dog cat", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void searchAndNextFindMatches() {
+ final FakeBuffer buffer = new FakeBuffer("cat dog cat", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- controller.handleKeyTyped('/');
- controller.handleKeyTyped('c');
- controller.handleKeyTyped('a');
- controller.handleKeyTyped('t');
- controller.handleKeyTyped('\n');
+ controller.handleKeyTyped('/');
+ controller.handleKeyTyped('c');
+ controller.handleKeyTyped('a');
+ controller.handleKeyTyped('t');
+ controller.handleKeyTyped('\n');
- assertEquals(8, buffer.getCursorPosition());
+ assertEquals(8, buffer.getCursorPosition());
- controller.handleKeyTyped('n');
- assertEquals(0, buffer.getCursorPosition());
- }
+ controller.handleKeyTyped('n');
+ assertEquals(0, buffer.getCursorPosition());
+ }
- @Test
- public void countMotionAdvancesMultipleCharacters() {
- final FakeBuffer buffer = new FakeBuffer("abcdef", 0);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void countMotionAdvancesMultipleCharacters() {
+ final FakeBuffer buffer = new FakeBuffer("abcdef", 0);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, '3', 'l');
+ type(controller, '3', 'l');
- assertEquals(3, buffer.getCursorPosition());
- }
+ assertEquals(3, buffer.getCursorPosition());
+ }
- @Test
- public void bStopsAtPunctuationWordBeforeSymbols() {
- final FakeBuffer buffer = new FakeBuffer("let lambda = ", 12);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void bStopsAtPunctuationWordBeforeSymbols() {
+ final FakeBuffer buffer = new FakeBuffer("let lambda = ", 12);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'b');
+ type(controller, 'b');
- assertEquals(11, buffer.getCursorPosition());
- }
+ assertEquals(11, buffer.getCursorPosition());
+ }
- @Test
- public void wStopsAtPunctuationWordBeforeSymbols() {
- final FakeBuffer buffer = new FakeBuffer("let lambda = ", 4);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void wStopsAtPunctuationWordBeforeSymbols() {
+ final FakeBuffer buffer = new FakeBuffer("let lambda = ", 4);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'w');
+ type(controller, 'w');
- assertEquals(11, buffer.getCursorPosition());
- }
+ assertEquals(11, buffer.getCursorPosition());
+ }
- @Test
- public void secondWFromPunctuationMovesToNextIdentifier() {
- final FakeBuffer buffer = new FakeBuffer("let lambda = x", 4);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void secondWFromPunctuationMovesToNextIdentifier() {
+ final FakeBuffer buffer = new FakeBuffer("let lambda = x", 4);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'w', 'w');
+ type(controller, 'w', 'w');
- assertEquals(13, buffer.getCursorPosition());
- }
+ assertEquals(13, buffer.getCursorPosition());
+ }
- @Test
- public void secondBFromPunctuationMovesToPreviousIdentifier() {
- final FakeBuffer buffer = new FakeBuffer("let lambda = ", 12);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void secondBFromPunctuationMovesToPreviousIdentifier() {
+ final FakeBuffer buffer = new FakeBuffer("let lambda = ", 12);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'b', 'b');
+ type(controller, 'b', 'b');
- assertEquals(4, buffer.getCursorPosition());
- }
+ assertEquals(4, buffer.getCursorPosition());
+ }
- @Test
- public void appendMovesPastCurrentCharacter() {
- final FakeBuffer buffer = new FakeBuffer("abc", 1);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void appendMovesPastCurrentCharacter() {
+ final FakeBuffer buffer = new FakeBuffer("abc", 1);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- controller.handleKeyTyped('a');
- insertCharacter(buffer, 'X');
- controller.handleKeyDown(Input.Keys.ESCAPE);
+ controller.handleKeyTyped('a');
+ insertCharacter(buffer, 'X');
+ controller.handleKeyDown(Input.Keys.ESCAPE);
- assertEquals("abXc", buffer.getText());
- }
+ assertEquals("abXc", buffer.getText());
+ }
- @Test
- public void appendAtEndOfLineInsertsAfterLastCharacter() {
- final FakeBuffer buffer = new FakeBuffer("abc", 2);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void appendAtEndOfLineInsertsAfterLastCharacter() {
+ final FakeBuffer buffer = new FakeBuffer("abc", 2);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- controller.handleKeyTyped('a');
- insertCharacter(buffer, 'X');
- controller.handleKeyDown(Input.Keys.ESCAPE);
+ controller.handleKeyTyped('a');
+ insertCharacter(buffer, 'X');
+ controller.handleKeyDown(Input.Keys.ESCAPE);
- assertEquals("abcX", buffer.getText());
- }
+ assertEquals("abcX", buffer.getText());
+ }
- @Test
- public void verticalMoveUsesCurrentColumnNotStaleColumn() {
- final FakeBuffer buffer = new FakeBuffer("12345678\n12\n12345678\n", 6);
- final VimEngine controller = new VimEngine(buffer, status -> {
- });
+ @Test
+ public void verticalMoveUsesCurrentColumnNotStaleColumn() {
+ final FakeBuffer buffer = new FakeBuffer("12345678\n12\n12345678\n", 6);
+ final VimEngine controller = new VimEngine(buffer, status -> {
+ });
- type(controller, 'j');
- assertEquals(10, buffer.getCursorPosition());
+ type(controller, 'j');
+ assertEquals(10, buffer.getCursorPosition());
- type(controller, 'h');
- assertEquals(9, buffer.getCursorPosition());
+ type(controller, 'h');
+ assertEquals(9, buffer.getCursorPosition());
- type(controller, 'k');
- assertEquals(0, buffer.getCursorPosition());
- }
+ type(controller, 'k');
+ assertEquals(0, buffer.getCursorPosition());
+ }
- private static void type(final VimEngine controller, final char... chars) {
- for (final char character : chars) {
- controller.handleKeyTyped(character);
- }
- }
+ private static void type(final VimEngine controller, final char... chars) {
+ for (final char character : chars) {
+ controller.handleKeyTyped(character);
+ }
+ }
- private static void insertCharacter(final FakeBuffer buffer, final char character) {
- final int cursor = buffer.getCursorPosition();
- final String text = buffer.getText();
- buffer.setText(text.substring(0, cursor) + character + text.substring(cursor));
- buffer.setCursorPosition(cursor + 1);
- }
+ private static void insertCharacter(final FakeBuffer buffer, final char character) {
+ final int cursor = buffer.getCursorPosition();
+ final String text = buffer.getText();
+ buffer.setText(text.substring(0, cursor) + character + text.substring(cursor));
+ buffer.setCursorPosition(cursor + 1);
+ }
}
diff --git a/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridCollisionPropagatationSystemTest.java b/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridCollisionPropagatationSystemTest.java
index 3743f3e..9f1ff41 100644
--- a/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridCollisionPropagatationSystemTest.java
+++ b/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridCollisionPropagatationSystemTest.java
@@ -25,164 +25,164 @@ import java.util.List;
import java.util.Set;
final class GridCollisionPropagatationSystemTest {
- private static final Duration FRAME = Duration.ZERO;
- private static final GridCollidable WALL_COLLIDABLE = (me, them) -> CollisionBehavior.builder()
- .collisionBehaviorType(CollisionBehaviorType.WALL).priority(10).build();
- private static final GridCollidable PROPAGATE_COLLIDABLE = (me, them) -> CollisionBehavior.builder()
- .collisionBehaviorType(CollisionBehaviorType.PROPAGATE).priority(0).build();
+ private static final Duration FRAME = Duration.ZERO;
+ private static final GridCollidable WALL_COLLIDABLE = (me, them) -> CollisionBehavior.builder()
+ .collisionBehaviorType(CollisionBehaviorType.WALL).priority(10).build();
+ private static final GridCollidable PROPAGATE_COLLIDABLE = (me, them) -> CollisionBehavior.builder()
+ .collisionBehaviorType(CollisionBehaviorType.PROPAGATE).priority(0).build();
- @Getter
- private static class SwallowCollidable implements GridCollidable {
- private final Set<Entity> swallowed = new HashSet<>();
- @Override
- public <T> void onSwallow(final Entity them, final World<T> world) {
- swallowed.add(them);
- }
+ @Getter
+ private static class SwallowCollidable implements GridCollidable {
+ private final Set<Entity> swallowed = new HashSet<>();
+ @Override
+ public <T> void onSwallow(final Entity them, final World<T> world) {
+ swallowed.add(them);
+ }
- @Override
- public CollisionBehavior getCollisionBehaviorBetween(final Entity me, final Entity them) {
- return CollisionBehavior.builder().collisionBehaviorType(CollisionBehaviorType.SWALLOW).priority(0).build();
- }
- }
+ @Override
+ public CollisionBehavior getCollisionBehaviorBetween(final Entity me, final Entity them) {
+ return CollisionBehavior.builder().collisionBehaviorType(CollisionBehaviorType.SWALLOW).priority(0).build();
+ }
+ }
- @Test
- public void testPrioritization() {
- final World<GridInputState> world = mockWorld();
- final GridIndexSystem indexSystem = mock(GridIndexSystem.class);
- when(indexSystem.inBounds(any())).thenReturn(true);
- when(world.getSystem(GridIndexSystem.class)).thenReturn(indexSystem);
+ @Test
+ public void testPrioritization() {
+ final World<GridInputState> world = mockWorld();
+ final GridIndexSystem indexSystem = mock(GridIndexSystem.class);
+ when(indexSystem.inBounds(any())).thenReturn(true);
+ when(world.getSystem(GridIndexSystem.class)).thenReturn(indexSystem);
- final Entity pusher = Entity.builder().id(1).build().add(PROPAGATE_COLLIDABLE).add(new GridMomentum(Vec2i.EAST))
- .add(new GridPosition(Vec2i.ZERO));
- final Entity toPropagate = Entity.builder().id(2).build().add(PROPAGATE_COLLIDABLE)
- .add(new GridPosition(Vec2i.EAST));
- final Entity wall = Entity.builder().id(3).build().add(WALL_COLLIDABLE).add(new GridPosition(Vec2i.EAST));
+ final Entity pusher = Entity.builder().id(1).build().add(PROPAGATE_COLLIDABLE).add(new GridMomentum(Vec2i.EAST))
+ .add(new GridPosition(Vec2i.ZERO));
+ final Entity toPropagate = Entity.builder().id(2).build().add(PROPAGATE_COLLIDABLE)
+ .add(new GridPosition(Vec2i.EAST));
+ final Entity wall = Entity.builder().id(3).build().add(WALL_COLLIDABLE).add(new GridPosition(Vec2i.EAST));
- // Propagation takes priority because priority(0) is lower
- when(world.query(Set.of(GridMomentum.class, GridPosition.class, GridCollidable.class)))
- .thenReturn(Set.of(pusher));
+ // Propagation takes priority because priority(0) is lower
+ when(world.query(Set.of(GridMomentum.class, GridPosition.class, GridCollidable.class)))
+ .thenReturn(Set.of(pusher));
- when(indexSystem.entitiesAt(Vec2i.ZERO)).thenReturn(List.of(pusher));
- when(indexSystem.entitiesAt(Vec2i.EAST)).thenReturn(List.of(toPropagate, wall));
+ when(indexSystem.entitiesAt(Vec2i.ZERO)).thenReturn(List.of(pusher));
+ when(indexSystem.entitiesAt(Vec2i.EAST)).thenReturn(List.of(toPropagate, wall));
- final GridCollisionPropagatationSystem system = new GridCollisionPropagatationSystem();
- system.update(world, mock(GridInputState.class), FRAME);
+ final GridCollisionPropagatationSystem system = new GridCollisionPropagatationSystem();
+ system.update(world, mock(GridInputState.class), FRAME);
- assertEquals(Vec2i.EAST, pusher.get(GridMomentum.class).getVelocity());
- assertEquals(Vec2i.EAST, toPropagate.get(GridMomentum.class).getVelocity());
- }
+ assertEquals(Vec2i.EAST, pusher.get(GridMomentum.class).getVelocity());
+ assertEquals(Vec2i.EAST, toPropagate.get(GridMomentum.class).getVelocity());
+ }
- @Test
- public void testWallCollisionHaltsRayMomentum() {
- final World<GridInputState> world = mockWorld();
- final GridIndexSystem indexSystem = mock(GridIndexSystem.class);
- when(indexSystem.inBounds(any())).thenReturn(true);
- when(world.getSystem(GridIndexSystem.class)).thenReturn(indexSystem);
+ @Test
+ public void testWallCollisionHaltsRayMomentum() {
+ final World<GridInputState> world = mockWorld();
+ final GridIndexSystem indexSystem = mock(GridIndexSystem.class);
+ when(indexSystem.inBounds(any())).thenReturn(true);
+ when(world.getSystem(GridIndexSystem.class)).thenReturn(indexSystem);
- final Entity pusher = Entity.builder().id(1).build().add(PROPAGATE_COLLIDABLE).add(new GridMomentum(Vec2i.EAST))
- .add(new GridPosition(Vec2i.ZERO));
- final Entity toPropagate = Entity.builder().id(2).build().add(PROPAGATE_COLLIDABLE)
- .add(new GridMomentum(Vec2i.EAST)).add(new GridPosition(Vec2i.EAST));
- final Entity wall = Entity.builder().id(3).build().add(WALL_COLLIDABLE)
- .add(new GridPosition(Vec2i.EAST.scale(2, 0)));
+ final Entity pusher = Entity.builder().id(1).build().add(PROPAGATE_COLLIDABLE).add(new GridMomentum(Vec2i.EAST))
+ .add(new GridPosition(Vec2i.ZERO));
+ final Entity toPropagate = Entity.builder().id(2).build().add(PROPAGATE_COLLIDABLE)
+ .add(new GridMomentum(Vec2i.EAST)).add(new GridPosition(Vec2i.EAST));
+ final Entity wall = Entity.builder().id(3).build().add(WALL_COLLIDABLE)
+ .add(new GridPosition(Vec2i.EAST.scale(2, 0)));
- when(world.query(Set.of(GridMomentum.class, GridPosition.class, GridCollidable.class)))
- .thenReturn(Set.of(pusher, toPropagate));
+ when(world.query(Set.of(GridMomentum.class, GridPosition.class, GridCollidable.class)))
+ .thenReturn(Set.of(pusher, toPropagate));
- when(indexSystem.entitiesAt(Vec2i.ZERO)).thenReturn(List.of(pusher));
- when(indexSystem.entitiesAt(Vec2i.EAST)).thenReturn(List.of(toPropagate));
- when(indexSystem.entitiesAt(Vec2i.EAST.scale(2, 0))).thenReturn(List.of(wall));
+ when(indexSystem.entitiesAt(Vec2i.ZERO)).thenReturn(List.of(pusher));
+ when(indexSystem.entitiesAt(Vec2i.EAST)).thenReturn(List.of(toPropagate));
+ when(indexSystem.entitiesAt(Vec2i.EAST.scale(2, 0))).thenReturn(List.of(wall));
- final GridCollisionPropagatationSystem system = new GridCollisionPropagatationSystem();
- system.update(world, GridInputState.builder().build(), FRAME);
+ final GridCollisionPropagatationSystem system = new GridCollisionPropagatationSystem();
+ system.update(world, GridInputState.builder().build(), FRAME);
- assertEquals(Vec2i.ZERO, pusher.get(GridMomentum.class).getVelocity());
- assertEquals(Vec2i.ZERO, toPropagate.get(GridMomentum.class).getVelocity());
- }
+ assertEquals(Vec2i.ZERO, pusher.get(GridMomentum.class).getVelocity());
+ assertEquals(Vec2i.ZERO, toPropagate.get(GridMomentum.class).getVelocity());
+ }
- @Test
- public void testGoingOutOfBoundsHaltsMomentum() {
- final World<GridInputState> world = mockWorld();
- final GridIndexSystem indexSystem = mock(GridIndexSystem.class);
+ @Test
+ public void testGoingOutOfBoundsHaltsMomentum() {
+ final World<GridInputState> world = mockWorld();
+ final GridIndexSystem indexSystem = mock(GridIndexSystem.class);
- when(indexSystem.inBounds(any())).thenReturn(false);
- when(world.getSystem(GridIndexSystem.class)).thenReturn(indexSystem);
+ when(indexSystem.inBounds(any())).thenReturn(false);
+ when(world.getSystem(GridIndexSystem.class)).thenReturn(indexSystem);
- final Entity pusher = Entity.builder().id(1).build().add(PROPAGATE_COLLIDABLE).add(new GridMomentum(Vec2i.EAST))
- .add(new GridPosition(Vec2i.ZERO));
+ final Entity pusher = Entity.builder().id(1).build().add(PROPAGATE_COLLIDABLE).add(new GridMomentum(Vec2i.EAST))
+ .add(new GridPosition(Vec2i.ZERO));
- when(world.query(Set.of(GridMomentum.class, GridPosition.class, GridCollidable.class)))
- .thenReturn(Set.of(pusher));
+ when(world.query(Set.of(GridMomentum.class, GridPosition.class, GridCollidable.class)))
+ .thenReturn(Set.of(pusher));
- when(indexSystem.entitiesAt(Vec2i.ZERO)).thenReturn(List.of(pusher));
+ when(indexSystem.entitiesAt(Vec2i.ZERO)).thenReturn(List.of(pusher));
- final GridCollisionPropagatationSystem system = new GridCollisionPropagatationSystem();
- system.update(world, GridInputState.builder().build(), FRAME);
+ final GridCollisionPropagatationSystem system = new GridCollisionPropagatationSystem();
+ system.update(world, GridInputState.builder().build(), FRAME);
- assertEquals(Vec2i.ZERO, pusher.get(GridMomentum.class).getVelocity());
- }
+ assertEquals(Vec2i.ZERO, pusher.get(GridMomentum.class).getVelocity());
+ }
- @Test
- public void testZeroVelocity() {
- final World<GridInputState> world = mockWorld();
- final GridIndexSystem indexSystem = mock(GridIndexSystem.class);
+ @Test
+ public void testZeroVelocity() {
+ final World<GridInputState> world = mockWorld();
+ final GridIndexSystem indexSystem = mock(GridIndexSystem.class);
- when(indexSystem.inBounds(any())).thenReturn(true);
- when(world.getSystem(GridIndexSystem.class)).thenReturn(indexSystem);
+ when(indexSystem.inBounds(any())).thenReturn(true);
+ when(world.getSystem(GridIndexSystem.class)).thenReturn(indexSystem);
- final Entity pusher = Entity.builder().id(1).build().add(PROPAGATE_COLLIDABLE).add(new GridMomentum(Vec2i.ZERO))
- .add(new GridPosition(Vec2i.ZERO));
+ final Entity pusher = Entity.builder().id(1).build().add(PROPAGATE_COLLIDABLE).add(new GridMomentum(Vec2i.ZERO))
+ .add(new GridPosition(Vec2i.ZERO));
- when(world.query(Set.of(GridMomentum.class, GridPosition.class, GridCollidable.class)))
- .thenReturn(Set.of(pusher));
+ when(world.query(Set.of(GridMomentum.class, GridPosition.class, GridCollidable.class)))
+ .thenReturn(Set.of(pusher));
- when(indexSystem.entitiesAt(Vec2i.ZERO)).thenReturn(List.of(pusher));
+ when(indexSystem.entitiesAt(Vec2i.ZERO)).thenReturn(List.of(pusher));
- final GridCollisionPropagatationSystem system = new GridCollisionPropagatationSystem();
- system.update(world, GridInputState.builder().build(), FRAME);
+ final GridCollisionPropagatationSystem system = new GridCollisionPropagatationSystem();
+ system.update(world, GridInputState.builder().build(), FRAME);
- assertEquals(Vec2i.ZERO, pusher.get(GridMomentum.class).getVelocity());
- }
+ assertEquals(Vec2i.ZERO, pusher.get(GridMomentum.class).getVelocity());
+ }
- @Test
- public void testSwallowInteraction() {
- final World<GridInputState> world = mockWorld();
- final GridIndexSystem indexSystem = mock(GridIndexSystem.class);
+ @Test
+ public void testSwallowInteraction() {
+ final World<GridInputState> world = mockWorld();
+ final GridIndexSystem indexSystem = mock(GridIndexSystem.class);
- when(indexSystem.inBounds(any())).thenReturn(true);
- when(world.getSystem(GridIndexSystem.class)).thenReturn(indexSystem);
+ when(indexSystem.inBounds(any())).thenReturn(true);
+ when(world.getSystem(GridIndexSystem.class)).thenReturn(indexSystem);
- final SwallowCollidable swallowCollidable = new SwallowCollidable();
+ final SwallowCollidable swallowCollidable = new SwallowCollidable();
- final Entity pusher = Entity.builder().id(1).build().add(PROPAGATE_COLLIDABLE).add(new GridMomentum(Vec2i.EAST))
- .add(new GridPosition(Vec2i.ZERO));
+ final Entity pusher = Entity.builder().id(1).build().add(PROPAGATE_COLLIDABLE).add(new GridMomentum(Vec2i.EAST))
+ .add(new GridPosition(Vec2i.ZERO));
- final Entity swallower = Entity.builder().id(2).build().add(swallowCollidable)
- .add(new GridPosition(Vec2i.EAST));
+ final Entity swallower = Entity.builder().id(2).build().add(swallowCollidable)
+ .add(new GridPosition(Vec2i.EAST));
- when(world.query(Set.of(GridMomentum.class, GridPosition.class, GridCollidable.class)))
- .thenReturn(Set.of(pusher));
+ when(world.query(Set.of(GridMomentum.class, GridPosition.class, GridCollidable.class)))
+ .thenReturn(Set.of(pusher));
- when(indexSystem.entitiesAt(Vec2i.ZERO)).thenReturn(List.of(pusher));
- when(indexSystem.entitiesAt(Vec2i.EAST)).thenReturn(List.of(swallower));
+ when(indexSystem.entitiesAt(Vec2i.ZERO)).thenReturn(List.of(pusher));
+ when(indexSystem.entitiesAt(Vec2i.EAST)).thenReturn(List.of(swallower));
- final GridCollisionPropagatationSystem system = new GridCollisionPropagatationSystem();
- system.update(world, GridInputState.builder().build(), FRAME);
+ final GridCollisionPropagatationSystem system = new GridCollisionPropagatationSystem();
+ system.update(world, GridInputState.builder().build(), FRAME);
- assertEquals(Vec2i.EAST, pusher.get(GridMomentum.class).getVelocity());
- assertFalse(swallower.has(GridMomentum.class));
+ assertEquals(Vec2i.EAST, pusher.get(GridMomentum.class).getVelocity());
+ assertFalse(swallower.has(GridMomentum.class));
- assertEquals(swallowCollidable.getSwallowed(), Set.of(pusher));
- }
+ assertEquals(swallowCollidable.getSwallowed(), Set.of(pusher));
+ }
- @Test
- public void testDependencies() {
- assertEquals(Set.of(GridMovementSystem.class, GridIndexSystem.class),
- new GridCollisionPropagatationSystem().getDependencies());
- }
+ @Test
+ public void testDependencies() {
+ assertEquals(Set.of(GridMovementSystem.class, GridIndexSystem.class),
+ new GridCollisionPropagatationSystem().getDependencies());
+ }
- @SuppressWarnings("unchecked")
- private static World<GridInputState> mockWorld() {
- return (World<GridInputState>) mock(World.class);
- }
+ @SuppressWarnings("unchecked")
+ private static World<GridInputState> mockWorld() {
+ return (World<GridInputState>) mock(World.class);
+ }
}
diff --git a/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridIndexSystemTest.java b/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridIndexSystemTest.java
index d9afde5..f751927 100644
--- a/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridIndexSystemTest.java
+++ b/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridIndexSystemTest.java
@@ -17,54 +17,54 @@ import java.time.Duration;
import java.util.Set;
class GridIndexSystemTest {
- @Test
- public void testUpdateIndexesEntitiesIntoGridSlots() {
- final GridIndexSystem system = new GridIndexSystem(new Vec2i(4, 4));
- final World<GridInputState> world = mockWorld();
- final Entity alpha = Entity.builder().id(11).build();
- alpha.add(new GridPosition(new Vec2i(1, 2)));
- final Entity beta = Entity.builder().id(12).build();
- beta.add(new GridPosition(new Vec2i(0, 0)));
- when(world.query(Set.of(GridPosition.class))).thenReturn(Set.of(alpha, beta));
+ @Test
+ public void testUpdateIndexesEntitiesIntoGridSlots() {
+ final GridIndexSystem system = new GridIndexSystem(new Vec2i(4, 4));
+ final World<GridInputState> world = mockWorld();
+ final Entity alpha = Entity.builder().id(11).build();
+ alpha.add(new GridPosition(new Vec2i(1, 2)));
+ final Entity beta = Entity.builder().id(12).build();
+ beta.add(new GridPosition(new Vec2i(0, 0)));
+ when(world.query(Set.of(GridPosition.class))).thenReturn(Set.of(alpha, beta));
- system.update(world, GridInputState.builder().movement(Vec2i.NORTH).build(), Duration.ZERO);
+ system.update(world, GridInputState.builder().movement(Vec2i.NORTH).build(), Duration.ZERO);
- assertTrue(system.entitiesAt(new Vec2i(1, 2)).contains(alpha));
- assertTrue(system.entitiesAt(new Vec2i(0, 0)).contains(beta));
- assertTrue(system.entitiesAt(new Vec2i(3, 3)).isEmpty());
- }
+ assertTrue(system.entitiesAt(new Vec2i(1, 2)).contains(alpha));
+ assertTrue(system.entitiesAt(new Vec2i(0, 0)).contains(beta));
+ assertTrue(system.entitiesAt(new Vec2i(3, 3)).isEmpty());
+ }
- @Test
- public void testUpdateClearsPreviousIndexesBeforeRebuilding() {
- final GridIndexSystem system = new GridIndexSystem(new Vec2i(2, 2));
- final World<GridInputState> world = mockWorld();
- final Entity moving = Entity.builder().id(77).build();
- moving.add(new GridPosition(Vec2i.ZERO));
- when(world.query(Set.of(GridPosition.class))).thenReturn(Set.of(moving)).thenReturn(Set.of());
+ @Test
+ public void testUpdateClearsPreviousIndexesBeforeRebuilding() {
+ final GridIndexSystem system = new GridIndexSystem(new Vec2i(2, 2));
+ final World<GridInputState> world = mockWorld();
+ final Entity moving = Entity.builder().id(77).build();
+ moving.add(new GridPosition(Vec2i.ZERO));
+ when(world.query(Set.of(GridPosition.class))).thenReturn(Set.of(moving)).thenReturn(Set.of());
- system.update(world, GridInputState.builder().movement(Vec2i.EAST).build(), Duration.ZERO);
- assertTrue(system.entitiesAt(Vec2i.ZERO).contains(moving));
+ system.update(world, GridInputState.builder().movement(Vec2i.EAST).build(), Duration.ZERO);
+ assertTrue(system.entitiesAt(Vec2i.ZERO).contains(moving));
- system.update(world, GridInputState.builder().movement(Vec2i.NORTH).build(), Duration.ZERO);
- assertTrue(system.entitiesAt(Vec2i.ZERO).isEmpty());
- }
+ system.update(world, GridInputState.builder().movement(Vec2i.NORTH).build(), Duration.ZERO);
+ assertTrue(system.entitiesAt(Vec2i.ZERO).isEmpty());
+ }
- @Test
- public void testEntitiesAtReturnsEmptySetForOutOfBoundsQuery() {
- final GridIndexSystem system = new GridIndexSystem(new Vec2i(2, 2));
+ @Test
+ public void testEntitiesAtReturnsEmptySetForOutOfBoundsQuery() {
+ final GridIndexSystem system = new GridIndexSystem(new Vec2i(2, 2));
- assertEquals(Set.of(), system.entitiesAt(new Vec2i(-1, 0)));
- assertEquals(Set.of(), system.entitiesAt(new Vec2i(2, 1)));
- assertEquals(Set.of(), system.entitiesAt(new Vec2i(1, 2)));
- }
+ assertEquals(Set.of(), system.entitiesAt(new Vec2i(-1, 0)));
+ assertEquals(Set.of(), system.entitiesAt(new Vec2i(2, 1)));
+ assertEquals(Set.of(), system.entitiesAt(new Vec2i(1, 2)));
+ }
- @Test
- public void testDependencies() {
- assertEquals(Set.of(), new GridIndexSystem(Vec2i.ZERO).getDependencies());
- }
+ @Test
+ public void testDependencies() {
+ assertEquals(Set.of(), new GridIndexSystem(Vec2i.ZERO).getDependencies());
+ }
- @SuppressWarnings("unchecked")
- private static World<GridInputState> mockWorld() {
- return (World<GridInputState>) Mockito.mock(World.class);
- }
+ @SuppressWarnings("unchecked")
+ private static World<GridInputState> mockWorld() {
+ return (World<GridInputState>) Mockito.mock(World.class);
+ }
}
diff --git a/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridMovementSystemTest.java b/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridMovementSystemTest.java
index 8bd8ff3..2731a7b 100644
--- a/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridMovementSystemTest.java
+++ b/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridMovementSystemTest.java
@@ -18,31 +18,31 @@ import java.time.Duration;
import java.util.Set;
final class GridMovementSystemTest {
- @Test
- public void testUpdateAssignsMomentumToControllableEntities() {
- final World<GridInputState> world = mockWorld();
- final Entity subject = Entity.builder().id(1).build();
- subject.add(new GridControllable());
- subject.add(new GridPosition(Vec2i.ZERO));
- final Set<Entity> controllableEntities = Set.of(subject);
- when(world.query(Set.of(GridControllable.class, GridPosition.class))).thenReturn(controllableEntities);
+ @Test
+ public void testUpdateAssignsMomentumToControllableEntities() {
+ final World<GridInputState> world = mockWorld();
+ final Entity subject = Entity.builder().id(1).build();
+ subject.add(new GridControllable());
+ subject.add(new GridPosition(Vec2i.ZERO));
+ final Set<Entity> controllableEntities = Set.of(subject);
+ when(world.query(Set.of(GridControllable.class, GridPosition.class))).thenReturn(controllableEntities);
- final GridInputState inputState = GridInputState.builder().movement(Vec2i.SOUTH).build();
- final GridMovementSystem system = new GridMovementSystem();
+ final GridInputState inputState = GridInputState.builder().movement(Vec2i.SOUTH).build();
+ final GridMovementSystem system = new GridMovementSystem();
- system.update(world, inputState, Duration.ofMillis(16));
+ system.update(world, inputState, Duration.ofMillis(16));
- final GridMomentum appliedMomentum = subject.get(GridMomentum.class);
- assertEquals(Vec2i.SOUTH, appliedMomentum.getVelocity());
- }
+ final GridMomentum appliedMomentum = subject.get(GridMomentum.class);
+ assertEquals(Vec2i.SOUTH, appliedMomentum.getVelocity());
+ }
- @Test
- public void testDependencies() {
- assertEquals(Set.of(), new GridMovementSystem().getDependencies());
- }
+ @Test
+ public void testDependencies() {
+ assertEquals(Set.of(), new GridMovementSystem().getDependencies());
+ }
- @SuppressWarnings("unchecked")
- private static World<GridInputState> mockWorld() {
- return (World<GridInputState>) Mockito.mock(World.class);
- }
+ @SuppressWarnings("unchecked")
+ private static World<GridInputState> mockWorld() {
+ return (World<GridInputState>) Mockito.mock(World.class);
+ }
}
diff --git a/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridPhysicsSystemTest.java b/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridPhysicsSystemTest.java
index c3bb01e..c6a0cfe 100644
--- a/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridPhysicsSystemTest.java
+++ b/core/src/test/java/coffee/liz/abstractionengine/grid/system/GridPhysicsSystemTest.java
@@ -18,29 +18,29 @@ import java.time.Duration;
import java.util.Set;
final class GridPhysicsSystemTest {
- @Test
- public void testUpdateMovesEntitiesByMomentumAndResetsVelocity() {
- final World<GridInputState> world = mockWorld();
- final Entity body = Entity.builder().id(3).build();
- body.add(new GridPosition(Vec2i.ZERO));
- body.add(new GridMomentum(Vec2i.EAST));
- when(world.query(Set.of(GridMomentum.class, GridPosition.class))).thenReturn(Set.of(body));
+ @Test
+ public void testUpdateMovesEntitiesByMomentumAndResetsVelocity() {
+ final World<GridInputState> world = mockWorld();
+ final Entity body = Entity.builder().id(3).build();
+ body.add(new GridPosition(Vec2i.ZERO));
+ body.add(new GridMomentum(Vec2i.EAST));
+ when(world.query(Set.of(GridMomentum.class, GridPosition.class))).thenReturn(Set.of(body));
- final GridPhysicsSystem system = new GridPhysicsSystem();
- system.update(world, GridInputState.builder().movement(Vec2i.NORTH).build(), Duration.ZERO);
+ final GridPhysicsSystem system = new GridPhysicsSystem();
+ system.update(world, GridInputState.builder().movement(Vec2i.NORTH).build(), Duration.ZERO);
- final Vec2<Integer> newPosition = body.get(GridPosition.class).getPosition();
- assertEquals(Vec2i.EAST, newPosition);
- assertEquals(Vec2i.ZERO, body.get(GridMomentum.class).getVelocity());
- }
+ final Vec2<Integer> newPosition = body.get(GridPosition.class).getPosition();
+ assertEquals(Vec2i.EAST, newPosition);
+ assertEquals(Vec2i.ZERO, body.get(GridMomentum.class).getVelocity());
+ }
- @Test
- public void testDependencies() {
- assertEquals(Set.of(GridCollisionPropagatationSystem.class), new GridPhysicsSystem().getDependencies());
- }
+ @Test
+ public void testDependencies() {
+ assertEquals(Set.of(GridCollisionPropagatationSystem.class), new GridPhysicsSystem().getDependencies());
+ }
- @SuppressWarnings("unchecked")
- private static World<GridInputState> mockWorld() {
- return (World<GridInputState>) Mockito.mock(World.class);
- }
+ @SuppressWarnings("unchecked")
+ private static World<GridInputState> mockWorld() {
+ return (World<GridInputState>) Mockito.mock(World.class);
+ }
}