<commit_before>// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;
using Xunit.Sdk;

namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
    public static class SyntaxTreeNodeVerifier
    {
        internal static void Verify(SyntaxTreeNode node, string[] baseline)
        {
            var walker = new Walker(baseline);
            walker.Visit(node);
            walker.AssertReachedEndOfBaseline();
        }

        private class Walker : SyntaxTreeNodeWalker
        {
            private readonly string[] _baseline;
            private readonly SyntaxTreeNodeWriter _visitor;
            private readonly StringWriter _writer;

            private int _index;

            public Walker(string[] baseline)
            {
                _writer = new StringWriter();

                _visitor = new SyntaxTreeNodeWriter(_writer);
                _baseline = baseline;
            }

            public TextWriter Writer { get; }

            public override void Visit(SyntaxTreeNode node)
            {
                var expected = _index < _baseline.Length ? _baseline[_index++] : null;

                // Write the node as text for comparison
                _writer.GetStringBuilder().Clear();
                _visitor.Visit(node);
                var actual = _writer.GetStringBuilder().ToString();
                var actualLineCount = actual.Split(new[] { "\r\n" }, StringSplitOptions.None).Length;

                var expectedLineIndex = 1;
                while (expectedLineIndex++ < actualLineCount && _index < _baseline.Length)
                {
                    expected += $"\r\n{_baseline[_index++]}";
                }
<commit_msg>Use correct newline string when splitting baselines<commit_after>// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;
using Xunit.Sdk;

namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
    public static class SyntaxTreeNodeVerifier
    {
        internal static void Verify(SyntaxTreeNode node, string[] baseline)
        {
            var walker = new Walker(baseline);
            walker.Visit(node);
            walker.AssertReachedEndOfBaseline();
        }

        private class Walker : SyntaxTreeNodeWalker
        {
            private readonly string[] _baseline;
            private readonly SyntaxTreeNodeWriter _visitor;
            private readonly StringWriter _writer;

            private int _index;

            public Walker(string[] baseline)
            {
                _writer = new StringWriter();

                _visitor = new SyntaxTreeNodeWriter(_writer);
                _baseline = baseline;
            }

            public TextWriter Writer { get; }

            public override void Visit(SyntaxTreeNode node)
            {
                var expected = _index < _baseline.Length ? _baseline[_index++] : null;

                // Write the node as text for comparison
                _writer.GetStringBuilder().Clear();
                _visitor.Visit(node);
                var actual = _writer.GetStringBuilder().ToString();
                var actualLineCount = actual.Split(new[] { _writer.NewLine }, StringSplitOptions.None).Length;

                var expectedLineIndex = 1;
                while (expectedLineIndex++ < actualLineCount && _index < _baseline.Length)
                {
                    expected += $"{_writer.NewLine}{_baseline[_index++]}";
                }

{'fraction_non_alphanumeric': 0.08195020746887967, 'fraction_numerical': 0.0015560165975103733, 'mean_word_length': 1.9922420480993017, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3320369', 'n_tokens_mistral': 966, 'n_tokens_neox': 907, 'n_words': 264}