Exemple #1
0
        private Program ParseModuleContent(ModuleData module)
        {
            var parser = new JavaScriptParser(module.Content, new ParserOptions {
                Loc = true, Range = true, SourceType = SourceType.Module, Tolerant = true
            });

            try { return(parser.ParseModule()); }
            catch (Exception ex) { throw _logger.ParsingModuleFileFailed(module.FilePath, GetFileProviderHint(module.File), ex); }
        }
 private static void ExecuteTest(JavaScriptParser parser, Test262File file)
 {
     if (file.Type == ProgramType.Script)
     {
         parser.ParseScript(file.Strict);
     }
     else
     {
         parser.ParseModule();
     }
 }
Exemple #3
0
        public static string Parse(string code)
        {
            var parser  = new JavaScriptParser(code);
            var program = parser.ParseModule();

            //StringBuilder sb = new StringBuilder();
            //StringWriter sw = new StringWriter(sb);
            //var w = new JsonTextWriter(sw);

            //program.WriteJson(sw);
            return("");
        }
Exemple #4
0
        private static string ParseAndFormat(SourceType sourceType, string source, ParserOptions options)
        {
            var          parser  = new JavaScriptParser(source, options);
            var          program = sourceType == SourceType.Script ?  (Program)parser.ParseScript() : parser.ParseModule();
            const string indent  = "  ";

            return(program.ToJsonString(
                       AstJson.Options.Default
                       .WithIncludingLineColumn(true)
                       .WithIncludingRange(true),
                       indent
                       ));
        }
Exemple #5
0
    public static async Task <int> Main(string[] args)
    {
        var rootDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) ?? string.Empty;
        var projectRoot   = Path.Combine(rootDirectory, "../../..");

        var allowListFile = Path.Combine(projectRoot, "allow-list.txt");
        var lines         = await File.ReadAllLinesAsync(allowListFile);

        var knownFailing = new HashSet <string>(lines
                                                .Where(x => !string.IsNullOrWhiteSpace(x) && !x.StartsWith("#"))
                                                );

        // this should be same in both Test262Harness.settings.json and here
        const string Sha    = "08a9fc2b974f83a9835174cede20a7935f126015";
        var          stream = await Test262StreamExtensions.FromGitHub(Sha);

        // we materialize to give better feedback on progress
        var test262Files = new ConcurrentBag <Test262File>();

        TestExecutionSummary?summary = null;

        AnsiConsole.Progress()
        .Columns(
            new TaskDescriptionColumn(),
            new ProgressBarColumn(),
            new PercentageColumn(),
            new SpinnerColumn(),
            new ElapsedTimeColumn()
            )
        .Start(ctx =>
        {
            var readTask = ctx.AddTask("Loading tests", maxValue: 90_000);
            readTask.StartTask();

            test262Files   = new ConcurrentBag <Test262File>(stream.GetTestFiles());
            readTask.Value = 100;
            readTask.StopTask();

            AnsiConsole.WriteLine();
            AnsiConsole.MarkupLine("Found [green]{0}[/] test cases to test against", test262Files.Count);

            var testTask = ctx.AddTask("Running tests", maxValue: test262Files.Count);

            var options = new Test262RunnerOptions
            {
                Execute = static file =>
                {
                    var parser = new JavaScriptParser(file.Program);
                    if (file.Type == ProgramType.Script)
                    {
                        parser.ParseScript(file.Strict);
                    }
                    else
                    {
                        parser.ParseModule();
                    }
                },
                IsIgnored      = file => knownFailing.Contains(file.ToString()),
                IsParseError   = exception => exception is ParserException,
                ShouldThrow    = file => file.NegativeTestCase?.Type == ExpectedErrorType.SyntaxError || file.NegativeTestCase?.Phase == TestingPhase.Parse,
                OnTestExecuted = _ => testTask.Increment(1)
            };

            var executor = new Test262Runner(options);
            summary      = executor.Run(test262Files);
            testTask.StopTask();
        });