private static void TestPositions(bool coffeeScript, string[] lines, FilePosition[] positions) { var path = coffeeScript ? "path.coffee" : "path"; var processor = new TestableMochaLineNumberProcessor(); processor.Mock <IFileSystemWrapper>().Setup(x => x.GetLines(It.IsAny <string>())).Returns(lines); var file = new ReferencedFile { IsLocal = true, IsFileUnderTest = true, Path = path }; processor.ClassUnderTest.Process(file, String.Join("\n", lines), new ChutzpahTestSettingsFile()); Assert.True( file.FilePositions.Contains(positions.Length - 1), "Should not have less than the expected number of FilePositions"); Assert.False( file.FilePositions.Contains(positions.Length), "Should not have more than the expected number of FilePositions"); for (int i = 0; i < positions.Length; i++) { var expectedPosition = positions[i]; var actualPosition = file.FilePositions[i]; Assert.True( expectedPosition.Line == actualPosition.Line, string.Format("Line indexes should match for position {0}.\nActual: {1}, Expected: {2}", i, actualPosition.Line, expectedPosition.Line)); Assert.True( expectedPosition.Column == actualPosition.Column, string.Format("Column indexes should match for position {0}.\nActual: {1}, Expected: {2}", i, actualPosition.Column, expectedPosition.Column)); } }
public void Will_get_skip_if_file_is_not_under_test() { var processor = new TestableMochaLineNumberProcessor(); var file = new ReferencedFile { IsLocal = true, IsFileUnderTest = false, Path = "path" }; processor.ClassUnderTest.Process(new Mock<IFrameworkDefinition>().Object, file, "", new ChutzpahTestSettingsFile().InheritFromDefault()); processor.Mock<IFileSystemWrapper>().Verify(x => x.GetLines(It.IsAny<string>()), Times.Never()); }
public void Will_get_line_number_for_test_with_quotes_in_title() { var processor = new TestableMochaLineNumberProcessor(); var file = new ReferencedFile { IsLocal = true, IsFileUnderTest = true, Path = "path" }; var text = @"describe ( 'modu\""le\'1', function () { it ('t\""e\'st1', function(){}); };"; processor.ClassUnderTest.Process(new Mock <IFrameworkDefinition>().Object, file, text, new ChutzpahTestSettingsFile().InheritFromDefault()); Assert.Equal(2, file.FilePositions[0].Line); Assert.Equal(7, file.FilePositions[0].Column); }
public void Will_get_line_number_for_test_with_quotes_in_title() { var processor = new TestableMochaLineNumberProcessor(); var file = new ReferencedFile { IsLocal = true, IsFileUnderTest = true, Path = "path" }; processor.Mock<IFileSystemWrapper>().Setup(x => x.GetLines("path")).Returns(new string[] { "describe ( 'modu\"le\\'1', function () {", " it (\'t\"e\\'st1\', function(){}); ", "};" }); processor.ClassUnderTest.Process(new Mock<IFrameworkDefinition>().Object, file, "", new ChutzpahTestSettingsFile().InheritFromDefault()); Assert.Equal(2, file.FilePositions[0].Line); Assert.Equal(7, file.FilePositions[0].Column); }