Exemplo n.º 1
0
        private void ShouldTruncateTrailingSeparator()
        {
            var configuration = new SlugityConfig
            {
                MaxLength = 34
            };

            var slugity = new Slugity(configuration);

            string before = "Test to see if the next separator gets truncated";
            string after  = "test-to-see-if-the-next-separator";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 2
0
        private void ShouldNotTruncateWord()
        {
            var configuration = new SlugityConfig
            {
                MaxLength = 10
            };

            var slugity = new Slugity(configuration);

            string before = "The word hippo should not be truncated";
            string after  = "the-word-hippo";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 3
0
        private void ShouldNotTrimSlugIfMaxLengthIsNull()
        {
            var configuration = new SlugityConfig
            {
                MaxLength = null
            };

            var slugity = new Slugity(configuration);

            string before = "This should not be trimmed";
            string after  = "this-should-not-be-trimmed";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 4
0
        private void ShouldSeparateStrings()
        {
            var configuration = new SlugityConfig
            {
                TextCase        = TextCase.LowerCase,
                StringSeparator = '-'
            };

            var slugity = new Slugity(configuration);

            string before = "Spaces should be replaced with chosen string separator";
            string after  = "spaces-should-be-replaced-with-chosen-string-separator";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 5
0
        private void ShouldBeUpperCase()
        {
            var configuration = new SlugityConfig
            {
                TextCase        = TextCase.UpperCase,
                StringSeparator = '-'
            };

            var slugity = new Slugity(configuration);

            string before = "this should BE UPPERCASE";
            string after  = "THIS-SHOULD-BE-UPPERCASE";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 6
0
        private void ShouldTrimAdditionalSpaces()
        {
            var configuration = new SlugityConfig
            {
                TextCase        = TextCase.LowerCase,
                StringSeparator = ' '
            };

            var slugity = new Slugity(configuration);

            string before = "Additional      spaces should                  be                                  trimmed";
            string after  = "additional spaces should be trimmed";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 7
0
        private void ShouldBeLowerCase()
        {
            var configuration = new SlugityConfig
            {
                TextCase        = TextCase.LowerCase,
                StringSeparator = '-'
            };

            var slugity = new Slugity(configuration);

            string before = "THIS SHOULD BE LOWERCASE";
            string after  = "this-should-be-lowercase";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 8
0
        private void ShouldBeCamalCase()
        {
            var configuration = new SlugityConfig
            {
                TextCase        = TextCase.CamalCase,
                StringSeparator = '-'
            };

            var slugity = new Slugity(configuration);

            string before = "this should BE CAMAL CASE";
            string after  = "This-Should-Be-Camal-Case";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 9
0
        private void ShouldStripStopWords()
        {
            var configuration = new SlugityConfig
            {
                TextCase = TextCase.LowerCase,
                StringSeparator = '-',
                StripStopWords = true
            };

            var slugity = new Slugity(configuration);

            string before = "This then that should be stripped";
            string after = "this-should-be-stripped";

            string result = slugity.GenerateSlug(before);
            result.ShouldBe(after);
        }
Exemplo n.º 10
0
        private void ShouldCleanString()
        {
            var configuration = new SlugityConfig
            {
                TextCase        = TextCase.LowerCase,
                StringSeparator = '-'
            };

            var slugity = new Slugity(configuration);

            string before = "This should clear the text, ok?";
            string after  = "this-should-clear-the-text-ok";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 11
0
        private void ShouldCleanString2()
        {
            var configuration = new SlugityConfig
            {
                TextCase        = TextCase.LowerCase,
                StringSeparator = '-'
            };

            var slugity = new Slugity(configuration);

            string before = "Clean & tidy strings, this***.";
            string after  = "clean-tidy-strings-this";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 12
0
        private void ShouldBeSeparatedByUnderscores()
        {
            var configuration = new SlugityConfig
            {
                TextCase        = TextCase.LowerCase,
                StringSeparator = '_'
            };

            var slugity = new Slugity(configuration);

            string before = "this should be lowercase";
            string after  = "this_should_be_lowercase";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 13
0
        private void ShouldLeaveStopWords()
        {
            var configuration = new SlugityConfig
            {
                TextCase = TextCase.LowerCase,
                StringSeparator = '-',
                StripStopWords = false,
            };

            var slugity = new Slugity(configuration);

            // Broken
            string before = "This then that should not be stripped";
            string after = "this-then-that-should-not-be-stripped";

            string result = slugity.GenerateSlug(before);
            result.ShouldBe(after);
        }
Exemplo n.º 14
0
        private void ShouldCleanStrings3()
        {
            var configuration = new SlugityConfig
            {
                TextCase        = TextCase.LowerCase,
                StringSeparator = '-'
            };

            configuration.ReplacementCharacters.Add("remain", "be left behind");

            var slugity = new Slugity(configuration);

            string before = "text !\"£$%^&*(),>/#'; should remain";
            string after  = "text-should-be-left-behind";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
Exemplo n.º 15
0
        private void ShouldReplaceCharacters()
        {
            var configuration = new SlugityConfig
            {
                TextCase        = TextCase.Ignore,
                StringSeparator = ' '
            };

            configuration.ReplacementCharacters.Add("Hello", "Goodbye");

            var slugity = new Slugity(configuration);

            string before = "Hello World";
            string after  = "Goodbye World";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
        private void ShouldReplaceMultipleWords()
        {
            var characters = new CharacterReplacement();

            characters.Add("Hello World", "Goodbye Planet");

            var configuration = new SlugityConfig
            {
                TextCase              = TextCase.LowerCase,
                StringSeparator       = '-',
                ReplacementCharacters = characters
            };

            var slugity = new Slugity(configuration);

            string before = "Hello World";
            string after  = "goodbye-planet";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
        private void ShouldReplaceSeparatorIfSameChar()
        {
            var characters = new CharacterReplacement();

            characters.Add("_", "");

            var configuration = new SlugityConfig
            {
                TextCase              = TextCase.LowerCase,
                StringSeparator       = '_',
                ReplacementCharacters = characters
            };

            var slugity = new Slugity(configuration);

            string before = "Hello_World";
            string after  = "helloworld";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }
        private void ShouldBeAbleToAddThenReplaceWords()
        {
            var characters = new CharacterReplacement();

            characters.Add("Hello", "Goodbye");

            var configuration = new SlugityConfig
            {
                TextCase              = TextCase.LowerCase,
                StringSeparator       = '_',
                ReplacementCharacters = characters
            };

            characters.AddOrReplace("Goodbye", "Hello");

            var slugity = new Slugity(configuration);

            string before = "Hello World";
            string after  = "hello_world";

            string result = slugity.GenerateSlug(before);

            result.ShouldBe(after);
        }