<commit_before>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NuGet.Test;

namespace NuGet.VisualStudio.Test {
    [TestClass]
    public class PathHelperTest {

        [TestMethod]
        public void ThrowsIfInputIsNull() {
            // Act & Assert
            ExceptionAssert.ThrowsArgNull(() => PathHelper.SmartTruncate(null, 10), "path");
        }

        [TestMethod]
        public void ThrowsIfMaxLengthIsLessThan6() {
            // Act & Assert
            ExceptionAssert.ThrowsArgOutOfRange(() => PathHelper.SmartTruncate("", 5), "maxWidth", 6, null, true);
            ExceptionAssert.ThrowsArgOutOfRange(() => PathHelper.SmartTruncate("", -4), "maxWidth", 6, null, true);
        }

        [TestMethod]
        public void ReturnsTheSameStringIfItIsEqualToMaxWidthValue() {
            // Arrange
            string input = "abcdef";
            int maxWidth = 6;

            // Act
            string output = PathHelper.SmartTruncate(input, maxWidth);

            // Assert
            Assert.AreEqual(input, output);
        }

        [TestMethod]
        public void ReturnsTheSameStringIfItIsShorterThanMaxWidthValue() {
            // Arrange
            string input = @"c:\user\documents\projects";
            int maxWidth = 30;

            // Act
            string output = PathHelper.SmartTruncate(input, maxWidth);

            // Assert
            Assert.AreEqual(input, output);
        }

        [TestMethod]
        public void TruncateIfInputIsLongerThanMaxWidth() {
            // Arrange
            string input = @"c:\user\documents\projects";
            int maxWidth = 20;

            // Act
            string output = PathHelper.SmartTruncate(input, maxWidth);

            // Assert
            Assert.AreEqual(@"c:\...\projects\", output);
        }

        [TestMethod]
        public void TruncateIfInputIsLongerThanMaxWidth2() {
            // Arrange
            string input = @"c:\user\documents\projects\";
            int maxWidth = 26;

            // Act
            string output = PathHelper.SmartTruncate(input, maxWidth);

            // Assert
            Assert.AreEqual(@"c:\...\projects\", output);
        }

        [TestMethod]
        public void TruncateFolderNameIfItIsTooLong() {
            // Arrange
            string input = @"c:\thisisaverylongname";
            int maxWidth = 10;

            // Act
            string output = PathHelper.SmartTruncate(input, maxWidth);

            // Assert
            Assert.IsTrue(output.Length == maxWidth);
            Assert.AreEqual(@"c:\...ame\", output);
        }
    }
}<commit_msg>Add unit tests for PathHelper.EscapePSPath() method<commit_after>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NuGet.Test;

namespace NuGet.VisualStudio.Test {
    [TestClass]
    public class PathHelperTest {

        [TestMethod]
        public void ThrowsIfInputIsNull() {
            // Act & Assert
            ExceptionAssert.ThrowsArgNull(() => PathHelper.SmartTruncate(null, 10), "path");
        }

        [TestMethod]
        public void ThrowsIfMaxLengthIsLessThan6() {
            // Act & Assert
            ExceptionAssert.ThrowsArgOutOfRange(() => PathHelper.SmartTruncate("", 5), "maxWidth", 6, null, true);
            ExceptionAssert.ThrowsArgOutOfRange(() => PathHelper.SmartTruncate("", -4), "maxWidth", 6, null, true);
        }

        [TestMethod]
        public void ReturnsTheSameStringIfItIsEqualToMaxWidthValue() {
            // Arrange
            string input = "abcdef";
            int maxWidth = 6;

            // Act
            string output = PathHelper.SmartTruncate(input, maxWidth);

            // Assert
            Assert.AreEqual(input, output);
        }

        [TestMethod]
        public void ReturnsTheSameStringIfItIsShorterThanMaxWidthValue() {
            // Arrange
            string input = @"c:\user\documents\projects";
            int maxWidth = 30;

            // Act
            string output = PathHelper.SmartTruncate(input, maxWidth);

            // Assert
            Assert.AreEqual(input, output);
        }

        [TestMethod]
        public void TruncateIfInputIsLongerThanMaxWidth() {
            // Arrange
            string input = @"c:\user\documents\projects";
            int maxWidth = 20;

            // Act
            string output = PathHelper.SmartTruncate(input, maxWidth);

            // Assert
            Assert.AreEqual(@"c:\...\projects\", output);
        }

        [TestMethod]
        public void TruncateIfInputIsLongerThanMaxWidth2() {
            // Arrange
            string input = @"c:\user\documents\projects\";
            int maxWidth = 26;

            // Act
            string output = PathHelper.SmartTruncate(input, maxWidth);

            // Assert
            Assert.AreEqual(@"c:\...\projects\", output);
        }

        [TestMethod]
        public void TruncateFolderNameIfItIsTooLong() {
            // Arrange
            string input = @"c:\thisisaverylongname";
            int maxWidth = 10;

            // Act
            string output = PathHelper.SmartTruncate(input, maxWidth);

            // Assert
            Assert.IsTrue(output.Length == maxWidth);
            Assert.AreEqual(@"c:\...ame\", output);
        }

        [TestMethod]
        public void EscapePSPathTest() {
            TestEscapePSPath("", "''");
            TestEscapePSPath("abc", "'abc'");
            TestEscapePSPath("a$$b", "'a$$b'");
            TestEscapePSPath("'a$$'b", "\"'a`$`$'b\"");
            TestEscapePSPath("hello world", "'hello world'");
            TestEscapePSPath("Gun 'n Roses", "\"Gun 'n Roses\"");
        }

        private static void TestEscapePSPath(string input, string expectedOutput) {
            string output = PathHelper.EscapePSPath(input);
            Assert.AreEqual(expectedOutput, output);
        }
    }
}
{'fraction_non_alphanumeric': 0.11662993727750466, 'fraction_numerical': 0.005763688760806916, 'mean_word_length': 1.7725563909774436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3212194', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1554, 'n_words': 312}