2026-09-15 17:11:39 +00:00
using AIStudio.Tools ;
namespace AIStudio.Tests.Tools ;
/// <summary>
/// Checks what AI Studio assumes about the readers of the formats it writes.
/// </summary>
[TestFixture]
public sealed class FileExportFormatTests
{
[Test]
public void OnlyTheTwoOfficeFormatsRefuseAPageInALocalLink ( )
{
Assert . Multiple ( ( ) = >
{
Assert . That ( FileExportFormat . MICROSOFT_WORD . FollowsPageAnchors ( ) , Is . False , "Word looks for a file whose name ends in the fragment, finds none, and refuses the link." ) ;
Assert . That ( FileExportFormat . OPEN_DOCUMENT_TEXT . FollowsPageAnchors ( ) , Is . False , "LibreOffice does the same, verified on 2026-09-15 with an exported .odt." ) ;
Assert . That ( FileExportFormat . HTML . FollowsPageAnchors ( ) , Is . True , "A browser opens the document on the page the fragment names." ) ;
Assert . That ( FileExportFormat . MARKDOWN . FollowsPageAnchors ( ) , Is . True ) ;
Assert . That ( FileExportFormat . LATEX . FollowsPageAnchors ( ) , Is . True ) ;
} ) ;
}
[Test]
public void EveryFormatAnAnswerIsWrittenAsHasAnAnswerHere ( )
{
// Whoever adds a format decides what its reader can follow, rather than inheriting an
// assumption. This fails for a format which nobody thought about, because the list below
// has to name it:
Assert . That ( FileExportFormatExtensions . ANSWER_FORMATS , Is . EquivalentTo ( new [ ]
{
FileExportFormat . MICROSOFT_WORD ,
FileExportFormat . OPEN_DOCUMENT_TEXT ,
FileExportFormat . LATEX ,
FileExportFormat . MARKDOWN ,
FileExportFormat . HTML ,
} ) , "A format was added to or removed from the export menu: say in FollowsPageAnchors whether its reader follows a page in a local link, then name it here." ) ;
}
2026-09-23 11:11:53 +00:00
[TestCase("html", FileExportFormat.HTML)]
[TestCase("latex", FileExportFormat.LATEX)]
[TestCase("tex", FileExportFormat.LATEX)]
[TestCase("markdown", FileExportFormat.MARKDOWN)]
[TestCase("md", FileExportFormat.MARKDOWN)]
[TestCase("csv", FileExportFormat.CSV)]
[TestCase("tsv", FileExportFormat.TSV)]
[TestCase("HTML", FileExportFormat.HTML, Description = "Models do not agree on the case.")]
[TestCase("LaTeX", FileExportFormat.LATEX)]
[TestCase("CSV", FileExportFormat.CSV)]
[TestCase(" md ", FileExportFormat.MARKDOWN, Description = "Space around the name is no part of it.")]
public void AFenceLanguageNamesItsFormat ( string language , FileExportFormat expectedFormat )
{
Assert . Multiple ( ( ) = >
{
Assert . That ( FileExportFormatExtensions . TryFromCodeFenceLanguage ( language , out var format ) , Is . True ) ;
Assert . That ( format , Is . EqualTo ( expectedFormat ) ) ;
} ) ;
}
[TestCase("css", TestName = "A language AI Studio writes no file for")]
[TestCase("docx", TestName = "A format no code block can hold")]
[TestCase("", TestName = "A fence without a language")]
[TestCase(null, TestName = "A fence Markdig read no language for")]
public void AnyOtherFenceLanguageNamesNoFormat ( string? language )
{
Assert . Multiple ( ( ) = >
{
Assert . That ( FileExportFormatExtensions . TryFromCodeFenceLanguage ( language , out var format ) , Is . False ) ;
Assert . That ( format , Is . EqualTo ( FileExportFormat . NONE ) ) ;
} ) ;
}
2026-09-15 17:11:39 +00:00
}