transcendental-lisp/test/file/FilePositionTrackerTest.java

66 lines
1.8 KiB
Java
Raw Normal View History

package file;
import static org.junit.Assert.assertTrue;
import java.util.Objects;
2017-02-06 13:44:35 -05:00
import org.junit.*;
2017-03-15 13:37:39 -04:00
public class FilePositionTrackerTest {
2016-12-12 14:57:34 -05:00
public static final String FILE_NAME = "testFile";
private FilePositionTracker trackerUnderTest;
2016-12-12 14:57:34 -05:00
private FilePosition createFilePosition(int lineNumber, int columnNumber) {
FilePosition position = new FilePosition(FILE_NAME);
position.setLineNumber(lineNumber);
position.setColumnNumber(columnNumber);
return position;
}
private void assertTrackerPositionEquals(FilePosition expectedPosition) {
assertTrue(arePositionsEqual(expectedPosition, trackerUnderTest.getCurrentPosition()));
}
private boolean arePositionsEqual(FilePosition position1, FilePosition position2) {
return Objects.equals(position1.getFileName(), position2.getFileName())
&& Objects.equals(position1.getLineNumber(), position2.getLineNumber())
&& Objects.equals(position1.getColumnNumber(), position2.getColumnNumber());
}
@Before
2017-03-24 09:36:44 -04:00
public void setUp() {
trackerUnderTest = new FilePositionTracker(FILE_NAME);
}
@Test
public void noMovement_ReturnsInitialPosition() {
assertTrackerPositionEquals(createFilePosition(1, 0));
}
@Test
public void advanceOneColumn_ReturnsCorrectPosition() {
trackerUnderTest.incrementColumn();
assertTrackerPositionEquals(createFilePosition(1, 1));
}
@Test
public void advanceOneLine_ReturnsCorrectPosition() {
trackerUnderTest.incrementLine();
assertTrackerPositionEquals(createFilePosition(2, 0));
}
@Test
public void advanceOneLine_ResetsColumn() {
trackerUnderTest.incrementColumn();
trackerUnderTest.incrementLine();
assertTrackerPositionEquals(createFilePosition(2, 0));
}
}