Files
space-station-14/Content.IntegrationTests/Tests/Guidebook/DocumentParsingTest.cs
T
Moony d42adbf05d Gametest Part 2: Preliminary refactor every test to use GameTest as the framework. (#43207)
* Pass 1.

* i'm FREE

* Prevent hangups.

* okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing.

* sigh.

* fix singular trigger bug so LatheTest doesn't flake.

* Remove SystemAttribute usage.

* Poke

* I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls.

* Change the faulty store test into two tests, one of which is ignored for failing.
2026-04-01 16:06:26 +00:00

151 lines
4.8 KiB
C#

#nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Client.Guidebook;
using Content.Client.Guidebook.Richtext;
using Content.IntegrationTests.Fixtures;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
namespace Content.IntegrationTests.Tests.Guidebook;
/// <summary>
/// This test checks that an example document string properly gets parsed by the <see cref="DocumentParsingManager"/>.
/// </summary>
[TestFixture]
[TestOf(typeof(DocumentParsingManager))]
public sealed class DocumentParsingTest : GameTest
{
public string TestDocument = @"multiple
lines
separated by
only single newlines
make a single rich text control
unless there is a double newline. Also
whitespace before newlines are ignored.
<TestControl/>
< TestControl />
<TestControl>
some text with a nested control
<TestControl/>
</TestControl>
<TestControl key1=""value1"" key2=""value2 with spaces"" key3=""value3 with a
newline""/>
<TestControl >
<TestControl k=""<\>\\>=\""=<-_?*3.0//"">
</TestControl>
</TestControl>";
[Test]
public async Task ParseTestDocument()
{
var pair = Pair;
var client = pair.Client;
await client.WaitIdleAsync();
var parser = client.ResolveDependency<DocumentParsingManager>();
Control ctrl = default!;
await client.WaitPost(() =>
{
ctrl = new Control();
Assert.That(parser.TryAddMarkup(ctrl, TestDocument));
});
Assert.That(ctrl.ChildCount, Is.EqualTo(7));
var richText1 = ctrl.GetChild(0) as RichTextLabel;
var richText2 = ctrl.GetChild(1) as RichTextLabel;
Assert.Multiple(() =>
{
Assert.That(richText1, Is.Not.Null);
Assert.That(richText2, Is.Not.Null);
});
// uhh.. WTF. rich text has no means of getting the contents!?!?
// TODO assert text content is correct after fixing that bullshit.
// Assert.That(richText1?.Text, Is.EqualTo("multiple lines separated by only single newlines make a single rich text control"));
// Assert.That(richText2?.Text, Is.EqualTo("unless there is a double newline. Also whitespace before newlines are ignored."));
var test1 = ctrl.GetChild(2) as TestControl;
var test2 = ctrl.GetChild(3) as TestControl;
var test3 = ctrl.GetChild(4) as TestControl;
var test4 = ctrl.GetChild(5) as TestControl;
var test5 = ctrl.GetChild(6) as TestControl;
Assert.Multiple(() =>
{
Assert.That(test1, Is.Not.Null);
Assert.That(test2, Is.Not.Null);
Assert.That(test3, Is.Not.Null);
Assert.That(test4, Is.Not.Null);
Assert.That(test5, Is.Not.Null);
});
Assert.Multiple(() =>
{
Assert.That(test1!.ChildCount, Is.EqualTo(0));
Assert.That(test2!.ChildCount, Is.EqualTo(0));
Assert.That(test3!.ChildCount, Is.EqualTo(2));
Assert.That(test4!.ChildCount, Is.EqualTo(0));
Assert.That(test5!.ChildCount, Is.EqualTo(1));
});
var subText = test3!.GetChild(0) as RichTextLabel;
var subTest = test3.GetChild(1) as TestControl;
#pragma warning disable NUnit2045
Assert.That(subText, Is.Not.Null);
//Assert.That(subText?.Text, Is.EqualTo("some text with a nested control"));
Assert.That(subTest, Is.Not.Null);
Assert.That(subTest?.ChildCount, Is.EqualTo(0));
#pragma warning restore NUnit2045
var subTest2 = test5!.GetChild(0) as TestControl;
Assert.That(subTest2, Is.Not.Null);
Assert.That(subTest2!.ChildCount, Is.EqualTo(0));
Assert.Multiple(() =>
{
Assert.That(test1!.Params, Has.Count.EqualTo(0));
Assert.That(test2!.Params, Has.Count.EqualTo(0));
Assert.That(test3.Params, Has.Count.EqualTo(0));
Assert.That(test4!.Params, Has.Count.EqualTo(3));
Assert.That(test5.Params, Has.Count.EqualTo(0));
Assert.That(subTest2.Params, Has.Count.EqualTo(1));
});
test4!.Params.TryGetValue("key1", out var val);
Assert.That(val, Is.EqualTo("value1"));
test4.Params.TryGetValue("key2", out val);
Assert.That(val, Is.EqualTo("value2 with spaces"));
test4.Params.TryGetValue("key3", out val);
Assert.That(val, Is.EqualTo(@"value3 with a
newline"));
subTest2.Params.TryGetValue("k", out val);
Assert.That(val, Is.EqualTo(@"<>\>=""=<-_?*3.0//"));
}
public sealed class TestControl : Control, IDocumentTag
{
public Dictionary<string, string> Params = default!;
public bool TryParseTag(Dictionary<string, string> param, [NotNullWhen(true)] out Control control)
{
Params = param;
control = this;
return true;
}
}
}