Files
WCTDataMiner/tests/Gpulse.WCT.DataAnalyzer.Tests/Commands/PlossParserTests.cs
Scottxjw 7a8a1e9a87 test: 更新分析功能和迁移测试用例
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-25 11:30:16 +08:00

77 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace Gpulse.WCT.DataAnalyzer.Tests.Commands;
/// <summary>
/// PlossParser 直接单测:覆盖 commit eba1d20 引入的 Field1 十六进制解析
/// 0x 前缀与无前缀两种写法),该路径此前在 legacy 删除后零覆盖。
/// </summary>
[TestFixture]
public class PlossParserTests : CommandTestBase
{
private Core.Application.Parsing.PlossParser _parser = default!;
// NUnit 会先运行基类的 [SetUp](创建 Host再运行本方法
[SetUp]
public async Task InitParser()
{
await Task.CompletedTask;
_parser = Host.Services.GetRequiredService<Core.Application.Parsing.PlossParser>();
}
[Test]
public void Parse_HexField1_WithZeroPrefix_DecodesCorrectly()
{
// Field1 = "0C" → 十进制 12
var dir = NewDir();
var path = TestFixtures.WritePlossLog(dir, "hex-0C.dat",
new TestFixtures.PlossTwoLineRow(Field1AsHex: "0C"));
var lines = File.ReadAllLines(path);
var result = _parser.ParseMultiLine(lines, Guid.Empty);
Assert.Multiple(() =>
{
Assert.That(result, Is.Not.Null);
Assert.That(result!.IsSuccess, Is.True);
Assert.That(result.Record!.Field1, Is.EqualTo(12));
});
}
[Test]
public void Parse_HexField1_WithZeroXPrefix_DecodesCorrectly()
{
// Field1 = "0xFF" → 十进制 255
var dir = NewDir();
var path = TestFixtures.WritePlossLog(dir, "hex-0xFF.dat",
new TestFixtures.PlossTwoLineRow(Field1AsHex: "0xFF"));
var lines = File.ReadAllLines(path);
var result = _parser.ParseMultiLine(lines, Guid.Empty);
Assert.Multiple(() =>
{
Assert.That(result, Is.Not.Null);
Assert.That(result!.IsSuccess, Is.True);
Assert.That(result.Record!.Field1, Is.EqualTo(255));
});
}
[Test]
public void Parse_DecimalField1_DecodesCorrectly()
{
// Field1 普通十进制 → 原值
var dir = NewDir();
var path = TestFixtures.WritePlossLog(dir, "dec-42.dat",
new TestFixtures.PlossTwoLineRow(Field1: 42));
var lines = File.ReadAllLines(path);
var result = _parser.ParseMultiLine(lines, Guid.Empty);
Assert.Multiple(() =>
{
Assert.That(result, Is.Not.Null);
Assert.That(result!.IsSuccess, Is.True);
Assert.That(result.Record!.Field1, Is.EqualTo(42));
});
}
}