AI-Studio/app/Tests/Settings/EnumNamesTests.cs
Thorsten Sommer 1eaca9b12f
Some checks are pending
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Added a semantic search tool (#1005)
2026-09-27 16:26:52 +02:00

61 lines
2.2 KiB
C#

using AIStudio.Provider;
using AIStudio.Settings;
using AIStudio.Settings.DataModel;
namespace AIStudio.Tests.Settings;
/// <summary>
/// Checks that a value written by hand counts only when it names one member of its enum.
/// </summary>
/// <remarks>
/// Enum.TryParse reads a number and several names at once as well. Neither is a mistake it
/// reports: both come back as some value, often one which a member has, so a configuration which
/// meant nothing of the sort gets a choice nobody wrote.
/// </remarks>
[TestFixture]
public sealed class EnumNamesTests
{
[TestCase("EVERY_MESSAGE")]
[TestCase("every_message")]
[TestCase(" Every_Message ")]
public void ANameCountsWhateverItsCase(string text)
{
Assert.That(EnumNames.TryParse<DataSourceRetrievalMode>(text, out var mode), Is.True);
Assert.That(mode, Is.EqualTo(DataSourceRetrievalMode.EVERY_MESSAGE));
}
[TestCase("1")]
[TestCase("-1")]
[TestCase("0x1")]
public void ANumberDoesNotCountEvenWhenAMemberHasIt(string text)
{
Assert.That(EnumNames.TryParse<DataSourceRetrievalMode>(text, out _), Is.False, "Enum.TryParse would read 1 as EVERY_MESSAGE.");
}
[Test]
public void SeveralNamesDoNotCount()
{
Assert.Multiple(() =>
{
Assert.That(EnumNames.TryParse<DataSourceRetrievalMode>("SEMANTIC_SEARCH, EVERY_MESSAGE", out _), Is.False, "Enum.TryParse would combine them to EVERY_MESSAGE.");
Assert.That(EnumNames.TryParse<ConfidenceLevel>("HIGH, MEDIUM", out _), Is.False, "Enum.TryParse would combine them to a confidence level above HIGH.");
});
}
[TestCase(null)]
[TestCase("")]
[TestCase(" ")]
[TestCase("EVERY MESSAGE")]
public void NoNameDoesNotCount(string? text)
{
Assert.That(EnumNames.TryParse<DataSourceRetrievalMode>(text, out var mode), Is.False);
Assert.That(mode, Is.EqualTo(default(DataSourceRetrievalMode)));
}
[Test]
public void TheEnumMayBeGivenAsAType()
{
Assert.That(EnumNames.TryParse(typeof(ConfidenceLevel), "moderate", out var level), Is.True);
Assert.That(level, Is.EqualTo(ConfidenceLevel.MODERATE));
}
}