transcendental-lisp/test/file/FilePositionTrackerTester.java

116 lines
3.5 KiB
Java

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 {
public static final String FILE_NAME = "testFileName";
private FilePositionTracker trackerUnderTest;
@Before
public void setUp() throws Exception {
trackerUnderTest = new FilePositionTracker(FILE_NAME);
}
@Test
public void filePositionEquality_CorrectlyReturnsTrue() {
FilePosition positionOne = new FilePosition(FILE_NAME);
positionOne.setLineNumber(5);
positionOne.setColumnNumber(9);
FilePosition positionTwo = new FilePosition(FILE_NAME);
positionTwo.setLineNumber(5);
positionTwo.setColumnNumber(9);
assertTrue(positionOne.isEqual(positionTwo));
}
@Test
public void filePositionEquality_CorrectlyReturnsFalseWithDifferentLine() {
FilePosition positionOne = new FilePosition(FILE_NAME);
positionOne.setLineNumber(5);
positionOne.setColumnNumber(9);
FilePosition positionTwo = new FilePosition(FILE_NAME);
positionTwo.setLineNumber(8);
positionTwo.setColumnNumber(9);
assertFalse(positionOne.isEqual(positionTwo));
}
@Test
public void filePositionEquality_CorrectlyReturnsFalseWithDifferentColumn() {
FilePosition positionOne = new FilePosition(FILE_NAME);
positionOne.setLineNumber(5);
positionOne.setColumnNumber(9);
FilePosition positionTwo = new FilePosition(FILE_NAME);
positionTwo.setLineNumber(5);
positionTwo.setColumnNumber(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 = new FilePosition(FILE_NAME);
expectedPosition.setLineNumber(1);
expectedPosition.setColumnNumber(0);
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
}
@Test
public void advanceOneColumn_ReturnsCorrectPosition() {
FilePosition expectedPosition = new FilePosition(FILE_NAME);
expectedPosition.setLineNumber(1);
expectedPosition.setColumnNumber(1);
trackerUnderTest.incrementColumn();
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
}
@Test
public void advanceOneLine_ReturnsCorrectPosition() {
FilePosition expectedPosition = new FilePosition(FILE_NAME);
expectedPosition.setLineNumber(2);
expectedPosition.setColumnNumber(0);
trackerUnderTest.incrementLine();
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
}
@Test
public void advanceOneLine_ResetsColumn() {
FilePosition expectedPosition = new FilePosition(FILE_NAME);
expectedPosition.setLineNumber(2);
expectedPosition.setColumnNumber(0);
trackerUnderTest.incrementColumn();
trackerUnderTest.incrementLine();
assertTrue(expectedPosition.isEqual(trackerUnderTest.getCurrentPosition()));
}
}