<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Reflection;

using NUnit.Framework;

namespace Scallion.Tests.Internal
{
    /// <summary>
    /// Provides a set of static methods for test assertions.
    /// </summary>
    internal static class HelperExtensions
    {
        /// <summary>
        /// Inserts a temporary string into the end of this file path.
        /// </summary>
        /// <param name="sourcePath">The file path that the <paramref name="suffix"/> is inserted</param>
        /// <param name="suffix">The string to be inserted. By default, this value is "temp"</param>
        /// <returns>A new string that the <paramref name="suffix"/> is inserted</returns>
        public static string GetTempPath(this string sourcePath, string suffix = "temp")
        {
            return new Regex(@"(?<=([^\\]+\\)+[^.]*(\.[^.]*)*)(?=(\.[^.\\]+)?$)", RegexOptions.Compiled)
                .Replace(sourcePath, "-" + suffix, 1);
        }

        /// <summary>
        /// Asserts properties equality recursively between specified objects.
        /// The assertion fails if their properties do not equal each other.
        /// </summary>
        /// <param name="actual">The object to be compared</param>
        /// <param name="expected">The object that the test expects</param>
        public static void AssertPropertyValuesAreEquals(this object actual, object expected)
        {
            var properties = expected.GetType().GetProperties().Where(p => p.CanWrite);
            foreach (PropertyInfo property in properties)
            {
                object expectedValue = property.GetValue(expected, null);
                object actualValue = property.GetValue(actual, null);

                if (actualValue is ICollection)
                    // Comparison for elements contained in the list<commit_msg>Fix a test helper to evaluate null value<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Reflection;

using NUnit.Framework;

namespace Scallion.Tests.Internal
{
    /// <summary>
    /// Provides a set of static methods for test assertions.
    /// </summary>
    internal static class HelperExtensions
    {
        /// <summary>
        /// Inserts a temporary string into the end of this file path.
        /// </summary>
        /// <param name="sourcePath">The file path that the <paramref name="suffix"/> is inserted</param>
        /// <param name="suffix">The string to be inserted. By default, this value is "temp"</param>
        /// <returns>A new string that the <paramref name="suffix"/> is inserted</returns>
        public static string GetTempPath(this string sourcePath, string suffix = "temp")
        {
            return new Regex(@"(?<=([^\\]+\\)+[^.]*(\.[^.]*)*)(?=(\.[^.\\]+)?$)", RegexOptions.Compiled)
                .Replace(sourcePath, "-" + suffix, 1);
        }

        /// <summary>
        /// Asserts properties equality recursively between specified objects.
        /// The assertion fails if their properties do not equal each other.
        /// </summary>
        /// <param name="actual">The object to be compared</param>
        /// <param name="expected">The object that the test expects</param>
        public static void AssertPropertyValuesAreEquals(this object actual, object expected)
        {
            var properties = expected.GetType().GetProperties().Where(p => p.CanWrite);
            foreach (PropertyInfo property in properties)
            {
                object expectedValue = property.GetValue(expected, null);
                object actualValue = property.GetValue(actual, null);

                if (actualValue == null)
                    Assert.Null(expectedValue);
                else if (actualValue is ICollection)
                    // Comparison for elements contained in the list
{'fraction_non_alphanumeric': 0.12658858709195117, 'fraction_numerical': 0.00049838026414154, 'mean_word_length': 2.347789824854045, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, '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': '2128945', 'n_tokens_mistral': 1015, 'n_tokens_neox': 970, 'n_words': 331}