mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-06 04:31:36 +00:00
Added whole documents to the Translation, Grammar & Spelling, and Rewrite & Improve assistants (#1179)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
f7666861f1
commit
918572c158
150 files changed
+12850
-302
No files matched your search
@@ -0,0 +1,42 @@
|
||||
using AIStudio.Tools.OpenXml;
|
||||
|
||||
namespace AIStudio.Tests.Tools.OpenXml;
|
||||
|
||||
/// <summary>
|
||||
/// Checks that a text from a model can always go into an Office document.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public sealed class OpenXmlTextTests
|
||||
{
|
||||
[Test]
|
||||
public void ATextXmlCanCarryStaysAsItIs()
|
||||
{
|
||||
const string TEXT = "Mars, 2026 – erreichbar? Ja, mit Geduld.";
|
||||
|
||||
Assert.That(OpenXmlText.XmlSafe(TEXT), Is.SameAs(TEXT));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AControlCharacterIsLeftOut()
|
||||
{
|
||||
Assert.That(OpenXmlText.XmlSafe("Mars\u0001 und\u0008 Venus"), Is.EqualTo("Mars und Venus"), "Control characters a model produces now and then would keep the file from being saved.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnEmojiStaysWhereasHalfOfItGoes()
|
||||
{
|
||||
//
|
||||
// The halves are put together in code: an attribute stores its strings as UTF-8, which
|
||||
// cannot hold half of an emoji, so a test case would not test what it says.
|
||||
//
|
||||
const char HIGH = '\ud83d';
|
||||
const char LOW = '\ude80';
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(OpenXmlText.XmlSafe($"Rakete {HIGH}{LOW}"), Is.EqualTo($"Rakete {HIGH}{LOW}"), "An emoji takes two chars, and the pair stays.");
|
||||
Assert.That(OpenXmlText.XmlSafe($"Rakete {HIGH}!"), Is.EqualTo("Rakete !"), "Half of a pair alone cannot go into XML.");
|
||||
Assert.That(OpenXmlText.XmlSafe($"{LOW}Rakete"), Is.EqualTo("Rakete"), "Neither can the other half.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using AIStudio.Tools.OpenXml;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace AIStudio.Tests.Tools.OpenXml;
|
||||
|
||||
/// <summary>
|
||||
/// Checks that a copy of a template leaves nothing behind in the temporary folder.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Writing a document into the copy and the copy into the chosen file is checked by the tests of the
|
||||
/// documents themselves, e.g., PresentationFileTests.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class TemplateCopyTests
|
||||
{
|
||||
private static readonly byte[] TEMPLATE_CONTENT = [1, 2, 3];
|
||||
|
||||
private string testFolder = string.Empty;
|
||||
private string temporaryDirectory = string.Empty;
|
||||
|
||||
[SetUp]
|
||||
public void CreateFolders()
|
||||
{
|
||||
this.testFolder = Directory.CreateDirectory(Path.Join(Path.GetTempPath(), "mindwork-ai-studio-tests", Guid.NewGuid().ToString("N"))).FullName;
|
||||
this.temporaryDirectory = $"mindwork-ai-studio-tests-{Guid.NewGuid():N}";
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void RemoveFolders()
|
||||
{
|
||||
Directory.Delete(this.testFolder, true);
|
||||
var copies = Path.Join(Path.GetTempPath(), this.temporaryDirectory);
|
||||
if (Directory.Exists(copies))
|
||||
Directory.Delete(copies, true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheCopyHoldsTheTemplateUntilItIsDisposed()
|
||||
{
|
||||
var templatePath = Path.Join(this.testFolder, "template.docx");
|
||||
await File.WriteAllBytesAsync(templatePath, TEMPLATE_CONTENT);
|
||||
|
||||
string copyPath;
|
||||
using (var copy = await TemplateCopy.CreateAsync(templatePath, this.temporaryDirectory, ".docx", NullLogger.Instance, CancellationToken.None))
|
||||
{
|
||||
copyPath = copy.FilePath;
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(Path.GetDirectoryName(copyPath), Is.EqualTo(Path.Join(Path.GetTempPath(), this.temporaryDirectory)), "The copy comes about in the temporary folder, never next to the chosen file.");
|
||||
Assert.That(Path.GetExtension(copyPath), Is.EqualTo(".docx"));
|
||||
Assert.That(File.ReadAllBytes(copyPath), Is.EqualTo(TEMPLATE_CONTENT));
|
||||
}
|
||||
}
|
||||
|
||||
Assert.That(File.Exists(copyPath), Is.False, "Disposing the copy removes it.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AMissingTemplateLeavesNoCopyBehind()
|
||||
{
|
||||
var templatePath = Path.Join(this.testFolder, "missing.docx");
|
||||
|
||||
await Assert.ThrowsAsync<FileNotFoundException>(() => TemplateCopy.CreateAsync(templatePath, this.temporaryDirectory, ".docx", NullLogger.Instance, CancellationToken.None));
|
||||
Assert.That(Directory.GetFiles(Path.Join(Path.GetTempPath(), this.temporaryDirectory)), Is.Empty);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user