Exemple #1
0
        protected void RunTest(string folderName, string fileName)
        {
            var filePath = Path.Combine(
                this.rootDirectory.FullName,
                "TestFiles",
                folderName,
                fileName + ".cst"
                );
            var fileReaderResult =
                FileReader.ReadFile(filePath, new FileSystem(), CancellationToken.None).Result;

            var formatter = new CodeFormatter();
            var result    = formatter.Format(
                fileReaderResult.FileContents,
                new PrinterOptions()
            {
                Width = PrinterOptions.WidthUsedByTests
            }
                );

            var actualFilePath = filePath.Replace(".cst", ".actual.cst");

            File.WriteAllText(actualFilePath, result.Code, fileReaderResult.Encoding);

            var filePathToChange = filePath;
            var expectedFilePath = actualFilePath.Replace(".actual.", ".expected.");

            var expectedCode = fileReaderResult.FileContents;

            if (File.Exists(expectedFilePath))
            {
                expectedCode     = File.ReadAllText(expectedFilePath, Encoding.UTF8);
                filePathToChange = expectedFilePath;
            }

            if (Environment.GetEnvironmentVariable("NormalizeLineEndings") != null)
            {
                expectedCode = expectedCode.Replace("\r\n", "\n");
                result.Code  = result.Code.Replace("\r\n", "\n");
            }

            var comparer = new SyntaxNodeComparer(
                expectedCode,
                result.Code,
                CancellationToken.None
                );

            result.Errors.Should().BeEmpty();
            result.FailureMessage.Should().BeEmpty();

            if (result.Code != expectedCode && !BuildServerDetector.Detected)
            {
                DiffRunner.Launch(filePathToChange, actualFilePath);
            }
            result.Code.Should().Be(expectedCode);

            var compareResult = comparer.CompareSource();

            compareResult.Should().BeNullOrEmpty();
        }
Exemple #2
0
        protected void RunTest(string folderName, string fileName)
        {
            var filePath = Path.Combine(
                this.rootDirectory.FullName,
                "TestFiles",
                folderName,
                fileName + ".cst"
                );
            var code = File.ReadAllText(filePath);

            var formatter = new CodeFormatter();
            var result    = formatter.Format(code, new Options());

            var actualFilePath = filePath.Replace(".cst", ".actual.cst");

            File.WriteAllText(actualFilePath, result.Code, Encoding.UTF8);

            var filePathToChange = filePath;
            var expectedFilePath = actualFilePath.Replace(
                ".actual.",
                ".expected."
                );

            if (File.Exists(expectedFilePath))
            {
                code             = File.ReadAllText(expectedFilePath, Encoding.UTF8);
                filePathToChange = expectedFilePath;
            }

            var comparer = new SyntaxNodeComparer(
                code,
                result.Code,
                CancellationToken.None
                );

            if (result.Code != code && !BuildServerDetector.Detected)
            {
                DiffRunner.Launch(filePathToChange, actualFilePath);
            }
            result.Code.Should().Be(code);

            var compareResult = comparer.CompareSource();

            compareResult.Should().BeNullOrEmpty();
        }
Exemple #3
0
        public void Default_SyntaxNodeComparer()
        {
            var syntaxNodeComparer = new SyntaxNodeComparer(code, code, CancellationToken.None);

            syntaxNodeComparer.CompareSource();
        }