-
Notifications
You must be signed in to change notification settings - Fork 113
refactor(mod-base): 重构 ModBase.cs #3294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Chiloven945
wants to merge
18
commits into
dev
Choose a base branch
from
refactor/mod-base
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ac535c7
拆分
Chiloven945 8565db7
替换已有实现
Chiloven945 9167021
专属服务
Chiloven945 81b8661
Core
Chiloven945 9fcbe7f
调用点
Chiloven945 e7a7c8c
移除兼容exts
Chiloven945 9ae418a
types
Chiloven945 741d57f
NColor
Chiloven945 62d2b4c
删除 wrapper
Chiloven945 23895e5
删除、重命名
Chiloven945 2a5d402
移动、修复问题
Chiloven945 2d7a963
Merge branch 'dev' into refactor/mod-base
Chiloven945 400e7fe
退回 NColor 迁移
Chiloven945 4ce2ca3
Merge branch 'dev' into refactor/mod-base
Chiloven945 788cd35
替换为 UiThread
Chiloven945 ded0316
修复
Chiloven945 7b46b90
修复死锁
Chiloven945 bbb06ba
后缀
Chiloven945 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using PCL.Core.IO; | ||
|
|
||
| namespace PCL.Core.Test.IO; | ||
|
|
||
| [TestClass] | ||
| public class DirectoriesTest | ||
| { | ||
| private string _tempDir = null!; | ||
|
|
||
| [TestInitialize] | ||
| public void SetUp() | ||
| { | ||
| _tempDir = Path.Combine(Path.GetTempPath(), "PCLCoreDirectoriesTest", Guid.NewGuid().ToString("N")); | ||
| Directory.CreateDirectory(_tempDir); | ||
| } | ||
|
|
||
| [TestCleanup] | ||
| public void TearDown() | ||
| { | ||
| if (Directory.Exists(_tempDir)) | ||
| Directory.Delete(_tempDir, true); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task CheckPermissionAsyncUsesRealProbeFile() | ||
| { | ||
| Assert.IsTrue(await Directories.CheckPermissionAsync(_tempDir)); | ||
| Assert.AreEqual(0, Directory.EnumerateFiles(_tempDir, ".pcl-permission-*.tmp").Count()); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task CheckPermissionAsyncReturnsFalseForMissingDirectory() | ||
| { | ||
| var missing = Path.Combine(_tempDir, "missing"); | ||
| Assert.IsFalse(await Directories.CheckPermissionAsync(missing)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using PCL.Core.Utils; | ||
|
|
||
| namespace PCL.Core.Test.Utils; | ||
|
|
||
| [TestClass] | ||
| public class Base64UtilsTest | ||
| { | ||
| [TestMethod] | ||
| public void EncodesAndDecodesUtf8Text() | ||
| { | ||
| const string text = "Plain Craft Launcher 测试"; | ||
| var encoded = Base64Utils.EncodeString(text); | ||
| Assert.AreEqual(text, Base64Utils.DecodeToString(encoded)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using PCL.Core.Utils; | ||
|
|
||
| namespace PCL.Core.Test.Utils; | ||
|
|
||
| [TestClass] | ||
| public class ConcurrentListTest | ||
| { | ||
| [TestMethod] | ||
| public void EnumerationUsesSnapshot() | ||
| { | ||
| var list = new ConcurrentList<int>([1, 2]); | ||
| var snapshot = list.ToList(); | ||
|
|
||
| list.Add(3); | ||
|
|
||
| CollectionAssert.AreEqual(new[] { 1, 2 }, snapshot); | ||
| CollectionAssert.AreEqual(new[] { 1, 2, 3 }, list.ToList()); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void RemoveAtUpdatesList() | ||
| { | ||
| var list = new ConcurrentList<string>(["a", "b", "c"]); | ||
|
|
||
| list.RemoveAt(1); | ||
|
|
||
| CollectionAssert.AreEqual(new[] { "a", "c" }, list.ToList()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using System.Collections; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using PCL.Core.Utils.Exts; | ||
|
|
||
| namespace PCL.Core.Test.Utils; | ||
|
|
||
| [TestClass] | ||
| public class EnumerableTextExtensionsTest | ||
| { | ||
| [TestMethod] | ||
| public void JoinSkipsNullElementsAndKeepsSeparators() | ||
| { | ||
| IEnumerable values = new object?[] { "a", null, "b" }; | ||
|
|
||
| Assert.AreEqual("a||b", values.Join("|")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using PCL.Core.Utils; | ||
|
|
||
| namespace PCL.Core.Test.Utils; | ||
|
|
||
| [TestClass] | ||
| public class NumberUtilsTest | ||
| { | ||
| [TestMethod] | ||
| [DataRow(-1d, 0)] | ||
| [DataRow(0d, 0)] | ||
| [DataRow(12.4d, 12)] | ||
| [DataRow(12.6d, 13)] | ||
| [DataRow(300d, 255)] | ||
| public void ClampToByte(double value, int expected) | ||
| { | ||
| Assert.AreEqual((byte)expected, NumberUtils.ClampToByte(value)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void LerpRoundsToSixDigits() | ||
| { | ||
| Assert.AreEqual(0.333333d, NumberUtils.Lerp(0d, 1d, 1d / 3d)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow("12.5", 12.5d)] | ||
| [DataRow("123abc", 123d)] | ||
| [DataRow("1.20.4", 1.2d)] | ||
| [DataRow("1e3xxx", 1000d)] | ||
| [DataRow("not-a-number", 0d)] | ||
| [DataRow("&", 0d)] | ||
| [DataRow(null, 0d)] | ||
| public void ParseDoubleOrZeroKeepsLeadingNumberParsing(string? value, double expected) | ||
| { | ||
| Assert.AreEqual(expected, NumberUtils.ParseDoubleOrZero(value)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow(".5", 0.5d)] | ||
| [DataRow("-.5abc", -0.5d)] | ||
| [DataRow("+42px", 42d)] | ||
| [DataRow("1e", 1d)] | ||
| public void ParseLeadingDoubleOrZeroHandlesPartialLiterals(string value, double expected) | ||
| { | ||
| Assert.AreEqual(expected, NumberUtils.ParseLeadingDoubleOrZero(value)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using PCL.Core.IO; | ||
|
|
||
| namespace PCL.Core.Test.Utils; | ||
|
|
||
| [TestClass] | ||
| public class PathUtilsTest | ||
| { | ||
| [TestMethod] | ||
| [DataRow("https://example.com/files/core.jar?download=1", "core.jar")] | ||
| [DataRow(@"C:\\Games\\Minecraft\\core.jar", "core.jar")] | ||
| [DataRow("/tmp/a/b/core.jar", "core.jar")] | ||
| public void GetsFileNameFromUrlOrPath(string path, string expected) | ||
| { | ||
| Assert.AreEqual(expected, PathUtils.GetFileNameFromUrlOrPath(path)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow(@"C:\\Games\\Minecraft\\", "Minecraft")] | ||
| [DataRow(@"D:\\", "D")] | ||
| public void GetsDirectoryLeaf(string path, string expected) | ||
| { | ||
| Assert.AreEqual(expected, PathUtils.GetDirectoryNameLeaf(path)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using PCL.Core.Utils.OS; | ||
|
|
||
| namespace PCL.Core.Test.Utils; | ||
|
|
||
| [TestClass] | ||
| public class ProcessRunnerTest | ||
| { | ||
| public TestContext TestContext { get; set; } | ||
|
|
||
| [TestMethod] | ||
| [OSCondition(OperatingSystems.Windows)] | ||
| public void CapturesProcessOutput() | ||
| { | ||
| var result = ProcessRunner | ||
| .CaptureAsync( | ||
| "cmd.exe", | ||
| "/c echo hello", | ||
| 5000, | ||
| cancellationToken: TestContext.CancellationToken) | ||
| .GetAwaiter() | ||
| .GetResult(); | ||
|
|
||
| Assert.IsFalse(result.TimedOut); | ||
| Assert.AreEqual(0, result.ExitCode); | ||
| Assert.Contains("hello", result.CombinedOutput); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using PCL.Core.Utils; | ||
|
|
||
| namespace PCL.Core.Test.Utils; | ||
|
|
||
| [TestClass] | ||
| public class RadixUtilsTest | ||
| { | ||
| [TestMethod] | ||
| public void ConvertsLargeNumbersWithBigInteger() | ||
| { | ||
| const string input = "999999999999999999999999999999"; | ||
| var encoded = RadixUtils.Convert(input, 10, 65); | ||
| var decoded = RadixUtils.Convert(encoded, 65, 10); | ||
| Assert.AreEqual(input, decoded); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ConvertsNegativeNumbers() | ||
| { | ||
| Assert.AreEqual("-11111111", RadixUtils.Convert("-255", 10, 2)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using PCL.Core.Utils.Exts; | ||
|
|
||
| namespace PCL.Core.Test.Utils; | ||
|
|
||
| [TestClass] | ||
| public class RegexExtensionsTest | ||
| { | ||
| private static readonly string[] Expected = ["12", "34"]; | ||
|
|
||
| [TestMethod] | ||
| public void FindsAndChecksMatches() | ||
| { | ||
| CollectionAssert.AreEqual(Expected, "a12b34".RegexSearch(@"\\d+")); | ||
| Assert.AreEqual("12", "a12b34".RegexSeek(@"\\d+")); | ||
| Assert.IsTrue("a12".RegexCheck(@"\\d+")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ReplacesEachMatch() | ||
| { | ||
| var replaced = "a12b34".RegexReplaceEach(@"\\d+", match => $"[{match.Value}]"); | ||
| Assert.AreEqual("a[12]b[34]", replaced); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using PCL.Core.Utils; | ||
| using PCL.Core.Utils.Exts; | ||
|
|
||
| namespace PCL.Core.Test.Utils; | ||
|
|
||
| [TestClass] | ||
| public class TextUtilsTest | ||
| { | ||
| [TestMethod] | ||
| public void LeftPadOrTrimKeepsLegacyBehavior() | ||
| { | ||
| Assert.AreEqual("00abc", TextUtils.LeftPadOrTrim("abc", "0", 5)); | ||
| Assert.AreEqual("abc", TextUtils.LeftPadOrTrim("abcdef", "0", 3)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void EscapesLikePattern() | ||
| { | ||
| Assert.AreEqual("a[*][?][#][[]b[]]", TextUtils.EscapeLikePattern("a*?#[b]")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void EscapesXamlAttributeTextWithMarkupExtensionPrefix() | ||
| { | ||
| Assert.AreEqual("{}{Binding Name}", TextUtils.EscapeXamlAttributeText("{Binding Name}")); | ||
| Assert.AreEqual("a&b"c", TextUtils.EscapeXamlAttributeText("a&b\"c")); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void StringSliceExtensionsKeepUnmatchedText() | ||
| { | ||
| Assert.AreEqual("2026", "2026/06/30".BeforeFirst("/")); | ||
| Assert.AreEqual("06/30", "2026/06/30".AfterFirst("/")); | ||
| Assert.AreEqual("30", "2026/06/30".Between("/", "/")); | ||
| Assert.AreEqual("2026/06/30", "2026/06/30".BeforeFirst("#")); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new regex tests double-escape
\dinside a verbatim string, so the pattern searches for a literal\dinstead of digits. With inputs like"a12b34",RegexSearch,RegexSeek, andRegexChecktherefore return no matches and the added test fails before validating the extension behavior; use@"\d+"here and in the replacement test below.Useful? React with 👍 / 👎.