<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Strings;

namespace Umbraco.Tests.CoreStrings
{
    [TestFixture]
    public class LegacyShortStringHelperTests
    {
        private LegacyShortStringHelper _helper;

        [SetUp]
        public void Setup()
        {
            _helper = new LegacyShortStringHelper();
        }

        #region Cases
        [TestCase("foo", "foo")]
        [TestCase("    foo    ", "Foo")]
        [TestCase("Foo", "Foo")]
        [TestCase("FoO", "FoO")]
        [TestCase("FoO bar", "FoOBar")]
        [TestCase("FoO bar NIL", "FoOBarNIL")]
        [TestCase("FoO 33bar 22NIL", "FoO33bar22NIL")]
        [TestCase("FoO 33bar 22NI", "FoO33bar22NI")]
        [TestCase("0foo", "foo")]
        [TestCase("2foo bar", "fooBar")]
        [TestCase("9FOO", "FOO")]
        [TestCase("foo-BAR", "foo-BAR")]
        [TestCase("foo-BA-dang", "foo-BA-dang")]
        [TestCase("foo_BAR", "foo_BAR")]
        [TestCase("foo'BAR", "fooBAR")]
        [TestCase("sauté dans l'espace", "sauteDansLespace", IgnoreReason = "non-supported non-ascii chars")]
        [TestCase("foo\"\"bar", "foobar")]
        [TestCase("-foo-", "-foo-")]
        [TestCase("_foo_", "_foo_")]
        [TestCase("spécial", "special", IgnoreReason = "non-supported non-ascii chars")]
        [TestCase("brô dëk ", "broDek", IgnoreReason = "non-supported non-ascii chars")]
        [TestCase("1235brô dëk ", "broDek", IgnoreReason = "non-supported non-ascii chars")]
        [TestCase("汉#字*/漢?字", "")]
        [TestCase("aa DB cd EFG X KLMN OP qrst", "aaDBCdEFGXKLMNOPQrst")]
        [TestCase("AA db cd EFG X KLMN OP qrst", "AADbCdEFGXKLMNOPQrst")]
        [TestCase("AAA db cd EFG X KLMN OP qrst", "AAADbCdEFGXKLMNOPQrst")]
        #endregion
        public void CleanStringForSafeAlias(string input, string expected)
        {
            // NOTE legacy CleanStringForSafeAlias has issues w/some cases
            // -> ignore test cases
            // also, some aliases are strange... how can "-foo-" be a valid alias?
            var output = _helper.CleanStringForSafeAlias(input);
            Assert.AreEqual(expected, output);
        }

        #region Cases
        [TestCase("Tab 1", "tab1")]
        [TestCase("Home - Page", "homePage")]
        [TestCase("Home.Page", "homePage")]
        [TestCase("Shannon's Document Type", "shannonsDocumentType")] // look, lowercase s and the end of shannons
        [TestCase("!BADDLY nam-ed Document Type", "baddlyNamEdDocumentType")]
        [TestCase("i %Want!thisTo end up In Proper@case", "iWantThisToEndUpInProperCase")]
        [TestCase("Räksmörgås %%$£¤¤¤§ kéKé", "raksmorgasKeKe", IgnoreReason = "non-supported non-ascii chars")]
        [TestCase("TRii", "tRii")]
        [TestCase("**TRii", "tRii")]
        [TestCase("trII", "trII")]
        [TestCase("**trII", "trII")]
        [TestCase("trIIX", "trIIX")]
        [TestCase("**trIIX", "trIIX")]
        #endregion
        public void LegacyCleanStringForUmbracoAlias(string input, string expected)
        {
            // NOTE ToUmbracoAlias has issues w/non-ascii, and a few other things
            // -> ignore test cases
            // also all those tests should, in theory, fail because removeSpaces is false by default
            var output = _helper.LegacyCleanStringForUmbracoAlias(input);
            Assert.AreEqual(expected, output);
        }

        #region Cases
        [TestCase("Home Page", "Home-Page")]
        [TestCase("Shannon's Home Page!", "Shannons-Home-Page!")]
        [TestCase("#Someones's Twitter $h1z%n", "Someoness-Twitter-$h1zn")]
        [TestCase("Räksmörgås", "Raeksmoergaas")]
        [TestCase("'em guys-over there, are#goin' a \"little\"bit crazy eh!! :)", "em-guys-over-there,-aregoin-a-littlebit-crazy-eh!!-)")]
        [TestCase("汉#字*/漢?字", "汉字star漢字")]
        [TestCase("Réalösk fix bran#lo'sk", "realosk-fix-bran-lo-sk", IgnoreReason = "cannot handle it")]
        #endregion
        public void LegacyFormatUrl(string input, string expected)
        {
            // NOTE CleanStringForUrlSegment has issues with a few cases
            // -> ignore test cases
            // also some results are a bit strange...
            var output = _helper.LegacyFormatUrl(input);
            Assert.AreEqual(expected, output);

            // NOTE: not testing the overload with culture
            // in legacy, they are the same
        }

        #region Cases
        [TestCase("Home Page", "home-page", true, true, false)]
        [TestCase("Shannon's Home Page!", "shannons-home-page", true, true, false)]
        [TestCase("#Someones's Twitter $h1z%n", "someoness-twitter-h1zn", true, true, false)]
        [TestCase("Räksmörgås", "rksmrgs", true, true, false)]
        [TestCase("'em guys-over there, are#goin' a \"little\"bit crazy eh!! :)", "em-guys-over-there-aregoin-a-littlebit-crazy-eh", true, true, false)]<commit_msg>U4-2033 - fix the tests, now we're returning lower case<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Strings;

namespace Umbraco.Tests.CoreStrings
{
    [TestFixture]
    public class LegacyShortStringHelperTests
    {
        private LegacyShortStringHelper _helper;

        [SetUp]
        public void Setup()
        {
            _helper = new LegacyShortStringHelper();
        }

        #region Cases
        [TestCase("foo", "foo")]
        [TestCase("    foo    ", "Foo")]
        [TestCase("Foo", "Foo")]
        [TestCase("FoO", "FoO")]
        [TestCase("FoO bar", "FoOBar")]
        [TestCase("FoO bar NIL", "FoOBarNIL")]
        [TestCase("FoO 33bar 22NIL", "FoO33bar22NIL")]
        [TestCase("FoO 33bar 22NI", "FoO33bar22NI")]
        [TestCase("0foo", "foo")]
        [TestCase("2foo bar", "fooBar")]
        [TestCase("9FOO", "FOO")]
        [TestCase("foo-BAR", "foo-BAR")]
        [TestCase("foo-BA-dang", "foo-BA-dang")]
        [TestCase("foo_BAR", "foo_BAR")]
        [TestCase("foo'BAR", "fooBAR")]
        [TestCase("sauté dans l'espace", "sauteDansLespace", IgnoreReason = "non-supported non-ascii chars")]
        [TestCase("foo\"\"bar", "foobar")]
        [TestCase("-foo-", "-foo-")]
        [TestCase("_foo_", "_foo_")]
        [TestCase("spécial", "special", IgnoreReason = "non-supported non-ascii chars")]
        [TestCase("brô dëk ", "broDek", IgnoreReason = "non-supported non-ascii chars")]
        [TestCase("1235brô dëk ", "broDek", IgnoreReason = "non-supported non-ascii chars")]
        [TestCase("汉#字*/漢?字", "")]
        [TestCase("aa DB cd EFG X KLMN OP qrst", "aaDBCdEFGXKLMNOPQrst")]
        [TestCase("AA db cd EFG X KLMN OP qrst", "AADbCdEFGXKLMNOPQrst")]
        [TestCase("AAA db cd EFG X KLMN OP qrst", "AAADbCdEFGXKLMNOPQrst")]
        #endregion
        public void CleanStringForSafeAlias(string input, string expected)
        {
            // NOTE legacy CleanStringForSafeAlias has issues w/some cases
            // -> ignore test cases
            // also, some aliases are strange... how can "-foo-" be a valid alias?
            var output = _helper.CleanStringForSafeAlias(input);
            Assert.AreEqual(expected, output);
        }

        #region Cases
        [TestCase("Tab 1", "tab1")]
        [TestCase("Home - Page", "homePage")]
        [TestCase("Home.Page", "homePage")]
        [TestCase("Shannon's Document Type", "shannonsDocumentType")] // look, lowercase s and the end of shannons
        [TestCase("!BADDLY nam-ed Document Type", "baddlyNamEdDocumentType")]
        [TestCase("i %Want!thisTo end up In Proper@case", "iWantThisToEndUpInProperCase")]
        [TestCase("Räksmörgås %%$£¤¤¤§ kéKé", "raksmorgasKeKe", IgnoreReason = "non-supported non-ascii chars")]
        [TestCase("TRii", "tRii")]
        [TestCase("**TRii", "tRii")]
        [TestCase("trII", "trII")]
        [TestCase("**trII", "trII")]
        [TestCase("trIIX", "trIIX")]
        [TestCase("**trIIX", "trIIX")]
        #endregion
        public void LegacyCleanStringForUmbracoAlias(string input, string expected)
        {
            // NOTE ToUmbracoAlias has issues w/non-ascii, and a few other things
            // -> ignore test cases
            // also all those tests should, in theory, fail because removeSpaces is false by default
            var output = _helper.LegacyCleanStringForUmbracoAlias(input);
            Assert.AreEqual(expected, output);
        }

        #region Cases
        [TestCase("Home Page", "home-page")]
        [TestCase("Shannon's Home Page!", "shannons-home-page!")]
        [TestCase("#Someones's Twitter $h1z%n", "someoness-twitter-$h1zn")]
        [TestCase("Räksmörgås", "raeksmoergaas")]
        [TestCase("'em guys-over there, are#goin' a \"little\"bit crazy eh!! :)", "em-guys-over-there,-aregoin-a-littlebit-crazy-eh!!-)")]
        [TestCase("汉#字*/漢?字", "汉字star漢字")]
        [TestCase("Réalösk fix bran#lo'sk", "realosk-fix-bran-lo-sk", IgnoreReason = "cannot handle it")]
        #endregion
        public void LegacyFormatUrl(string input, string expected)
        {
            // NOTE CleanStringForUrlSegment has issues with a few cases
            // -> ignore test cases
            // also some results are a bit strange...
            var output = _helper.LegacyFormatUrl(input);
            Assert.AreEqual(expected, output);

            // NOTE: not testing the overload with culture
            // in legacy, they are the same
        }

        #region Cases
        [TestCase("Home Page", "home-page", true, true, false)]
        [TestCase("Shannon's Home Page!", "shannons-home-page", true, true, false)]
        [TestCase("#Someones's Twitter $h1z%n", "someoness-twitter-h1zn", true, true, false)]
        [TestCase("Räksmörgås", "rksmrgs", true, true, false)]
        [TestCase("'em guys-over there, are#goin' a \"little\"bit crazy eh!! :)", "em-guys-over-there-aregoin-a-littlebit-crazy-eh", true, true, false)]
{'fraction_non_alphanumeric': 0.15344861856489764, 'fraction_numerical': 0.006261180679785331, 'mean_word_length': 2.705081001472754, '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': '2368280', 'n_tokens_mistral': 3333, 'n_tokens_neox': 3159, 'n_words': 761}