U:调整所有代码格式

This commit is contained in:
jimmy committed 2025-12-30 09:17:25 +08:00
1 parent d133bacf55
commit 155b67e831
342 files changed
+9431 -9868

No files matched your search

+16 -19
View File
@@ -69,17 +69,14 @@ public class StringExpandTests
var invalidUrls = new[]
{
"not a url",
"example.com", // 缺少协议
"http://", // 不完整
"", // 空字符串
"://invalid" // 无效格式
"example.com", // 缺少协议
"http://", // 不完整
"", // 空字符串
"://invalid" // 无效格式
};
// Act & Assert
foreach (var url in invalidUrls)
{
Assert.IsFalse(url.IsValidUrl(), $"'{url}' should be invalid");
}
foreach (var url in invalidUrls) Assert.IsFalse(url.IsValidUrl(), $"'{url}' should be invalid");
}
#endregion
@@ -281,22 +278,22 @@ public class StringExpandTests
{
["Port"] = "8080",
["Timeout"] = "30",
["MaxRetries"] = "invalid", // 无效值
["MaxRetries"] = "invalid", // 无效值
["Price"] = "99.99",
["Discount"] = "0.15"
};
// Act: 解析配置值
var port = config["Port"].ToInt(80); // 默认 80
var timeout = config["Timeout"].ToInt(60); // 默认 60
var maxRetries = config["MaxRetries"].ToInt(3); // 无效值,使用默认 3
var port = config["Port"].ToInt(80); // 默认 80
var timeout = config["Timeout"].ToInt(60); // 默认 60
var maxRetries = config["MaxRetries"].ToInt(3); // 无效值,使用默认 3
var price = config["Price"].ToDouble(0.0);
var discount = config["Discount"].ToDouble(0.0);
// Assert
Assert.AreEqual(8080, port);
Assert.AreEqual(30, timeout);
Assert.AreEqual(3, maxRetries); // 使用了默认值
Assert.AreEqual(3, maxRetries); // 使用了默认值
Assert.AreEqual(99.99, price);
Assert.AreEqual(0.15, discount);
}
@@ -332,8 +329,8 @@ public class StringExpandTests
public void Scenario_SafelyParseUserInput()
{
// Arrange: 模拟用户输入(可能无效)
string? userAgeInput = "25";
string? userWeightInput = "invalid";
var userAgeInput = "25";
var userWeightInput = "invalid";
string? userHeightInput = null;
// Act: 安全解析
@@ -344,8 +341,8 @@ public class StringExpandTests
// Assert
Assert.IsNotNull(age);
Assert.AreEqual(25, age.Value);
Assert.IsNull(weight); // 无效输入
Assert.IsNull(height); // null 输入
Assert.IsNull(weight); // 无效输入
Assert.IsNull(height); // null 输入
// 使用默认值的版本
var ageWithDefault = userAgeInput.ToInt(18);
@@ -353,7 +350,7 @@ public class StringExpandTests
var heightWithDefault = userHeightInput.ToDouble(170.0);
Assert.AreEqual(25, ageWithDefault);
Assert.AreEqual(70.0, weightWithDefault); // 使用默认值
Assert.AreEqual(70.0, weightWithDefault); // 使用默认值
Assert.AreEqual(170.0, heightWithDefault); // 使用默认值
}
@@ -389,4 +386,4 @@ public class StringExpandTests
}
#endregion
}
}