2022-03-22 16:53:24 +08:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
|
|
|
|
namespace Falcon.SugarApi.Test
|
|
|
|
|
{
|
2022-10-21 09:13:44 +08:00
|
|
|
|
|
2022-03-30 17:08:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字符串扩展方法测试
|
|
|
|
|
/// </summary>
|
2022-03-22 16:53:24 +08:00
|
|
|
|
[TestClass]
|
|
|
|
|
public class StringExtendTest
|
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestSplit() {
|
|
|
|
|
var str = $"a,b.c;d,e。f;g";
|
|
|
|
|
var strArr = str.SplitStr();
|
|
|
|
|
Assert.AreEqual(7, strArr.Length, "分割后长度应该为7");
|
2022-03-29 16:14:07 +08:00
|
|
|
|
str = "a,,, ,b ,c c,";
|
|
|
|
|
strArr = str.SplitStr();
|
|
|
|
|
Assert.AreEqual(3, strArr.Length, "分割后长度应该为3");
|
|
|
|
|
Assert.AreEqual("a", strArr[0]);
|
|
|
|
|
Assert.AreEqual("b", strArr[1]);
|
|
|
|
|
Assert.AreEqual("c c", strArr[2]);
|
2022-03-22 16:53:24 +08:00
|
|
|
|
str = null;
|
|
|
|
|
strArr = str.SplitStr();
|
|
|
|
|
Assert.IsNotNull(strArr);
|
|
|
|
|
Assert.AreEqual(0, strArr.Length);
|
2022-05-24 15:53:26 +08:00
|
|
|
|
|
|
|
|
|
//指定分隔符
|
|
|
|
|
str = $"a,b.c;d,e。f;g";
|
|
|
|
|
|
|
|
|
|
strArr = str.SplitStr(',');
|
|
|
|
|
Assert.AreEqual(2, strArr.Length, "分割后长度应该为7");
|
|
|
|
|
Assert.AreEqual("a", strArr[0]);
|
|
|
|
|
Assert.AreEqual("b.c;d,e。f;g", strArr[1]);
|
|
|
|
|
|
|
|
|
|
strArr = str.SplitStr(',', '.');
|
|
|
|
|
Assert.AreEqual(3, strArr.Length, "分割后长度应该为7");
|
|
|
|
|
Assert.AreEqual("a", strArr[0]);
|
|
|
|
|
Assert.AreEqual("b", strArr[1]);
|
|
|
|
|
Assert.AreEqual("c;d,e。f;g", strArr[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 测试ToDefault
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestToDefault() {
|
|
|
|
|
var str = "";
|
|
|
|
|
var r = "";
|
|
|
|
|
r = str.ToDefault("abc");
|
|
|
|
|
Assert.AreEqual("abc", r);
|
|
|
|
|
str = null;
|
|
|
|
|
r = str.ToDefault("abc");
|
|
|
|
|
Assert.AreEqual("abc", r);
|
|
|
|
|
str = "123";
|
|
|
|
|
r = str.ToDefault("abc");
|
|
|
|
|
Assert.AreEqual("123", r);
|
2022-03-22 16:53:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|