Ejemplo n.º 1
0
        //------------------------------------------------------------------------------
        public static String NormalizeLineEndings(String text, EolType eol)
        {
            String eolString = (eol == EolType.Unix) ? "\n" : "\r\n";

            String normalized = Regex.Replace(text, @"\r*\n", eolString, RegexOptions.Multiline);

            return(normalized);
        }
Ejemplo n.º 2
0
        //
        // Public methods
        //

        //------------------------------------------------------------------------------
        public static String EolTypeToEolString(EolType eolType)
        {
            switch (eolType)
            {
            case EolType.Unix:
                return("\n");

            case EolType.Windows:
                return("\r\n");
            }

            throw new Exception(String.Format("Unsupported EOL string!"));
        }
Ejemplo n.º 3
0
        public async Task ValidCsprojFormatPathLoadUtf8BomTest(string csprojPath, EolType eol, string eolString)
        {
            // delay to avoid file read conflict
            await Task.Delay(TimeSpan.FromMilliseconds(100));

            // Load Should be success
            var csproj = Project.Load(csprojPath);

            csproj.Root.ToString().Should().NotBeNullOrEmpty();

            // Encoding
            csproj.Encoding.Should().Be(new UTF8Encoding(true));

            // Eol
            csproj.Eol.Should().Be(eol);
            csproj.Eol.ToEolString().Should().Be(eolString);

            // Initialized Should be true
            csproj.Initialized.Should().BeTrue();

            // TODO: Save test
        }
Ejemplo n.º 4
0
        public async Task ValidCsprojFormatStreamLoadUtf8Test(string csprojPath, EolType eol, string eolString)
        {
            // delay to avoid file read conflict
            await Task.Delay(TimeSpan.FromMilliseconds(100));

            // Load Should be success
            using (var stream = File.Open(csprojPath, FileMode.Open, FileAccess.Read))
            {
                var csproj = Project.Load(stream);
                csproj.Root.ToString().Should().NotBeNullOrEmpty();

                // Encoding
                csproj.Encoding.Should().Be(new UTF8Encoding(false));

                // Eol
                csproj.Eol.Should().Be(eol);
                csproj.Eol.ToEolString().Should().Be(eolString);

                // Initialized Should be true
                csproj.Initialized.Should().BeTrue();

                // TODO: Save test
            }
        }
Ejemplo n.º 5
0
 public static string ToEolString(this EolType eol)
 => eol == EolType.CRLF ? "\r\n" : "\n";