<commit_before>﻿// Copyright (c) Umbraco.
// See LICENSE for more details.

using System;
using System.Globalization;
using NUnit.Framework;
using Umbraco.Extensions;

namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.CoreThings
{
    [TestFixture]
    public class TryConvertToTests
    {
        [Test]
        public void ConvertToBoolTest()
        {
            var conv = 1.TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(true, conv.Result);

            conv = "1".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(true, conv.Result);

            conv = 0.TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(false, conv.Result);

            conv = "0".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(false, conv.Result);

            conv = "Yes".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(true, conv.Result);

            conv = "yes".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(true, conv.Result);

            conv = "No".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(false, conv.Result);

            conv = "no".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(false, conv.Result);
        }


        [Test]
        [TestCase("en-US")]
        [TestCase(null)]
        [TestCase("sv-SE")]
        [TestCase("da-DK")]
        [TestCase("tr-TR")]
        public void ConvertToIntegerTest(string culture)
        {
            if (culture is not null)
            {
                CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(culture);
            }
            var conv = "-1".TryConvertTo<int>();
            Assert.IsTrue(conv);
            Assert.AreEqual(-1, conv.Result);

            conv = "100".TryConvertTo<int>();
            Assert.IsTrue(conv);
            Assert.AreEqual(100, conv.Result);

            conv = "100.000".TryConvertTo<int>();<commit_msg>Removes the sv-SE test, as it is expected to fail for "-1"<commit_after>﻿// Copyright (c) Umbraco.
// See LICENSE for more details.

using System;
using System.Globalization;
using NUnit.Framework;
using Umbraco.Extensions;

namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.CoreThings
{
    [TestFixture]
    public class TryConvertToTests
    {
        [Test]
        public void ConvertToBoolTest()
        {
            var conv = 1.TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(true, conv.Result);

            conv = "1".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(true, conv.Result);

            conv = 0.TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(false, conv.Result);

            conv = "0".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(false, conv.Result);

            conv = "Yes".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(true, conv.Result);

            conv = "yes".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(true, conv.Result);

            conv = "No".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(false, conv.Result);

            conv = "no".TryConvertTo<bool>();
            Assert.IsTrue(conv);
            Assert.AreEqual(false, conv.Result);
        }


        [Test]
        [TestCase("en-US")]
        [TestCase(null)]
        [TestCase("da-DK")]
        [TestCase("tr-TR")]
        public void ConvertToIntegerTest(string culture)
        {
            if (culture is not null)
            {
                CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(culture);
            }
            var conv = "-1".TryConvertTo<int>();
            Assert.IsTrue(conv);
            Assert.AreEqual(-1, conv.Result);

            conv = "100".TryConvertTo<int>();
            Assert.IsTrue(conv);
            Assert.AreEqual(100, conv.Result);

            conv = "100.000".TryConvertTo<int>();
{'fraction_non_alphanumeric': 0.13384504677380668, 'fraction_numerical': 0.008875029983209402, 'mean_word_length': 1.860082304526749, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '6037259', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1160, 'n_words': 205}