mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-01 00:08:05 -04:00
* Move all unit tests to Engine/Tests * Fix Margin.EdgeSubtract * Fix Capsule.Contains * EnvironmentVariables.Remove if it's null * Fixed ray trace never returning startedsolid * Fix HistoryList.Navigate on empty list * Fix GameObject.WorldPosition accepting NaNs * Fix flex: initial expanding to the wrong grow/shrink * Translation.TryConvert shouldn't throw on invalid enum strings * Skip sound file tests on machines with no audio device
43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
namespace EditorTests;
|
|
|
|
/// <summary>
|
|
/// A component type for <see cref="SceneEditorTest"/> to find by name in the type library.
|
|
/// Never instantiated.
|
|
/// </summary>
|
|
public class ClipboardTestComponent : Component
|
|
{
|
|
}
|
|
|
|
[TestClass]
|
|
public class SceneEditorTest
|
|
{
|
|
/// <summary>
|
|
/// Clipboard text is component json when it's a json object whose __type resolves
|
|
/// to a known component type.
|
|
/// </summary>
|
|
[TestMethod]
|
|
public void RecognisesComponentJson()
|
|
{
|
|
Assert.IsTrue( global::Editor.SceneEditor.IsComponentJson( $$"""{ "__type": "{{nameof( ClipboardTestComponent )}}" }""" ) );
|
|
}
|
|
|
|
/// <summary>
|
|
/// Anything that isn't a json object with a known component __type should be
|
|
/// rejected without throwing - the clipboard can contain absolutely anything.
|
|
/// </summary>
|
|
[TestMethod]
|
|
[DataRow( null )]
|
|
[DataRow( "" )]
|
|
[DataRow( " " )]
|
|
[DataRow( "not json at all" )]
|
|
[DataRow( "[ 1, 2, 3 ]" )]
|
|
[DataRow( "{}" )]
|
|
[DataRow( """{ "__type": 5 }""" )]
|
|
[DataRow( """{ "__type": "NotARealComponentType" }""" )]
|
|
[DataRow( """{ "sometext": "ClipboardTestComponent" }""" )]
|
|
public void RejectsEverythingElse( string text )
|
|
{
|
|
Assert.IsFalse( global::Editor.SceneEditor.IsComponentJson( text ) );
|
|
}
|
|
}
|