Exemple #1
0
        /// <summary>
        /// Validates a given <paramref name="tsFileName"/>.
        /// </summary>
        private static void CheckTypeScriptTestCases(string tsFileName)
        {
            tsFileName = TypeScript.Net.Core.Path.NormalizePath(tsFileName);
            var tsFileContent = File.ReadAllText(tsFileName);
            var tsInputFile   = new TestFile(tsFileName, tsFileContent);
            List <Diagnostic> diagnostics;

            // Getting diagnostic for the file.
            diagnostics = TypeCheckingHelper.ParseAndCheck(tsInputFile, ParsingOptions.TypeScriptParsingOptions);

            // Check that number of errors is correct
            var expectedErrorCount = GetExpectedErrorCount(tsFileName);

            if (expectedErrorCount == 0 && diagnostics.Count != 0)
            {
                // Special case: expecting no errors but got some
                string message =
                    $"Expecting 0 errors but got {diagnostics.Count}. All diagnostics: {DiagnosticMessages(diagnostics)}";

                CustomAssert.Fail(message);
            }

            if (expectedErrorCount != 0)
            {
                // Now, trying to compare actual content with an expected one.

                // To simplify future diagnostic, we're going to do following trick:

                // First, we'll compare content scrumbling file names in the error file (this will simplify migration
                // of the existing cases from TypeScript code base).
                // Second, if they're different we'll dump both expected and actual content.

                // So we're expecting errors, let's check that they're the same.
                var expectedErrorContent = ReadExpectedNormalizedErrorContent(tsFileName);

                // Dumping the file content for further diagnostic
                var actualErrorContent = GetActualNormalizedErrorContent(tsInputFile, diagnostics);

                try
                {
                    Assert.Equal(expectedErrorContent, actualErrorContent);
                }
                catch (Exception e)
                {
                    CustomAssert.Fail(
                        "Expected and actual files are different.\r\n" +
                        "Expected: \r\n" +
                        expectedErrorContent + "\r\n" +
                        "Actual: \r\n" +
                        actualErrorContent + "\r\n" +
                        "Original error:\r\n" + e.ToString());
                }
            }
        }
Exemple #2
0
 private static List <Diagnostic> GetSemanticDiagnostics(string code)
 {
     return(TypeCheckingHelper.GetSemanticDiagnostics(useCachedVersion: false, codes: code));
 }