transcendental-lisp/test/file/FilePositionTrackerTester.java

101 lines
2.9 KiB
Java
Raw Normal View History

package file;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
public class FilePositionTrackerTester {
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;
}
@Before
public void setUp() throws Exception {
trackerUnderTest = new FilePositionTracker(FILE_NAME);
}
@Test
public void filePositionEquality_CorrectlyReturnsTrue() {
FilePosition positionOne = createFilePosition(5, 9);
FilePosition positionTwo = createFilePosition(5, 9);
assertTrue(positionOne.isEqual(positionTwo));
}
@Test
public void filePositionEquality_CorrectlyReturnsFalseWithDifferentLine() {
FilePosition positionOne = createFilePosition(5, 9);
FilePosition positionTwo = createFilePosition(8, 9);
assertFalse(positionOne.isEqual(positionTwo));
}
@Test
public void filePositionEquality_CorrectlyReturnsFalseWithDifferentColumn() {
FilePosition positionOne = createFilePosition(5, 9);
FilePosition positionTwo = createFilePosition(5, 10);
assertFalse(positionOne.isEqual(positionTwo));
}
@Test
public void filePositionEquality_CorrectlyReturnsFalseWithDifferentFileName() {
FilePosition positionOne = new FilePosition("FileOne");
positionOne.setLineNumber(5);
positionOne.setColumnNumber(9);
FilePosition positionTwo = new FilePosition("FileTwo");
positionTwo.setLineNumber(5);
positionTwo.setColumnNumber(9);
assertFalse(positionOne.isEqual(positionTwo));
}
@Test
public void noMovement_ReturnsInitialPosition() {
FilePosition expectedPosition = createFilePosition(1, 0);
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
}
@Test
public void advanceOneColumn_ReturnsCorrectPosition() {
FilePosition expectedPosition = createFilePosition(1, 1);
trackerUnderTest.incrementColumn();
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
}
@Test
public void advanceOneLine_ReturnsCorrectPosition() {
FilePosition expectedPosition = createFilePosition(2, 0);
trackerUnderTest.incrementLine();
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
}
@Test
public void advanceOneLine_ResetsColumn() {
FilePosition expectedPosition = createFilePosition(2, 0);
trackerUnderTest.incrementColumn();
trackerUnderTest.incrementLine();
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
}
}