mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.5 KiB
97 lines
2.5 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
namespace Squidex.Infrastructure;
|
|
|
|
public class StringExtensionsTests
|
|
{
|
|
[Theory]
|
|
[InlineData(null, false)]
|
|
[InlineData("", false)]
|
|
[InlineData("me", false)]
|
|
[InlineData("me@@web.com", false)]
|
|
[InlineData("me@web.com", true)]
|
|
[InlineData("Me@web.com", true)]
|
|
public void Should_check_email(string email, bool isEmail)
|
|
{
|
|
Assert.Equal(isEmail, email.IsEmail());
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
public void Should_provide_fallback_if_invalid(string value)
|
|
{
|
|
Assert.Equal("fallback", value.Or("fallback"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_provide_value()
|
|
{
|
|
const string value = "value";
|
|
|
|
Assert.Equal(value, value.Or("fallback"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_join_non_empty_if_all_are_valid()
|
|
{
|
|
var actual = StringExtensions.JoinNonEmpty("_", "1", "2", "3");
|
|
|
|
Assert.Equal("1_2_3", actual);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_join_non_empty_if_first_invalid()
|
|
{
|
|
var actual = StringExtensions.JoinNonEmpty("_", null, "2", "3");
|
|
|
|
Assert.Equal("2_3", actual);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_join_non_empty_if_middle_invalid()
|
|
{
|
|
var actual = StringExtensions.JoinNonEmpty("_", "1", null, "3");
|
|
|
|
Assert.Equal("1_3", actual);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_join_non_empty_if_last_invalid()
|
|
{
|
|
var actual = StringExtensions.JoinNonEmpty("_", "1", "2", null);
|
|
|
|
Assert.Equal("1_2", actual);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_escape_json()
|
|
{
|
|
var actual = StringExtensions.JsonEscape("Hello \"World\"");
|
|
|
|
Assert.Equal("Hello \\\"World\\\"", actual);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("", "")]
|
|
[InlineData(" ", "")]
|
|
[InlineData("-", "")]
|
|
[InlineData("--", "")]
|
|
[InlineData("text1 ", "text1")]
|
|
[InlineData("texts-", "texts")]
|
|
[InlineData(" 1text", "1text")]
|
|
[InlineData("-atext", "atext")]
|
|
[InlineData("a-text", "a-text")]
|
|
public void Should_trim_non_digits_or_letters(string input, string output)
|
|
{
|
|
var result = input.TrimNonLetterOrDigit();
|
|
|
|
Assert.Equal(output, result);
|
|
}
|
|
}
|
|
|