131 lines
4.6 KiB
C#
131 lines
4.6 KiB
C#
using NUnit.Framework;
|
|
using SepCore.InputModule;
|
|
|
|
namespace SepCore.InputModule.Tests
|
|
{
|
|
public class InputContextStackTests
|
|
{
|
|
[Test]
|
|
public void PushPopMaintainsCurrentContext()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
|
|
Assert.That(stack.Push(InputContextId.GameplayExplore), Is.True);
|
|
Assert.That(stack.Current, Is.EqualTo(InputContextId.GameplayExplore));
|
|
|
|
Assert.That(stack.Push(InputContextId.Dialog), Is.True);
|
|
Assert.That(stack.Current, Is.EqualTo(InputContextId.Dialog));
|
|
|
|
Assert.That(stack.Pop(out InputContextId poppedContext), Is.True);
|
|
Assert.That(poppedContext, Is.EqualTo(InputContextId.Dialog));
|
|
Assert.That(stack.Current, Is.EqualTo(InputContextId.GameplayExplore));
|
|
}
|
|
|
|
[Test]
|
|
public void SetClearsExistingStack()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
stack.Push(InputContextId.GameplayExplore);
|
|
stack.Push(InputContextId.Dialog);
|
|
|
|
Assert.That(stack.Set(InputContextId.UI), Is.True);
|
|
Assert.That(stack.Count, Is.EqualTo(1));
|
|
Assert.That(stack.Current, Is.EqualTo(InputContextId.UI));
|
|
}
|
|
|
|
[Test]
|
|
public void ClearRejectsNonStackableContexts()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
|
|
Assert.That(stack.Push(InputContextId.Global), Is.False);
|
|
Assert.That(stack.Push(InputContextId.None), Is.False);
|
|
Assert.That(stack.Count, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void PushDuplicateReturnsFalse()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
Assert.That(stack.Push(InputContextId.GameplayExplore), Is.True);
|
|
Assert.That(stack.Push(InputContextId.GameplayExplore), Is.False);
|
|
Assert.That(stack.Count, Is.EqualTo(1));
|
|
}
|
|
|
|
[Test]
|
|
public void PopEmptyStackReturnsFalse()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
Assert.That(stack.Pop(out InputContextId context), Is.False);
|
|
Assert.That(context, Is.EqualTo(InputContextId.None));
|
|
}
|
|
|
|
[Test]
|
|
public void ClearOnEmptyStackReturnsFalse()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
Assert.That(stack.Clear(), Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void ClearResetsCurrentToNone()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
stack.Push(InputContextId.GameplayExplore);
|
|
stack.Push(InputContextId.Dialog);
|
|
Assert.That(stack.Clear(), Is.True);
|
|
Assert.That(stack.Current, Is.EqualTo(InputContextId.None));
|
|
Assert.That(stack.Count, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void SetNonStackableCallsClear()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
stack.Push(InputContextId.GameplayExplore);
|
|
Assert.That(stack.Set(InputContextId.None), Is.True);
|
|
Assert.That(stack.Count, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void SetSameContextReturnsFalse()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
stack.Set(InputContextId.UI);
|
|
Assert.That(stack.Set(InputContextId.UI), Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void PushReorderExistingToTop()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
stack.Push(InputContextId.GameplayExplore);
|
|
stack.Push(InputContextId.Dialog);
|
|
stack.Push(InputContextId.UI);
|
|
Assert.That(stack.Push(InputContextId.GameplayExplore), Is.True);
|
|
Assert.That(stack.Current, Is.EqualTo(InputContextId.GameplayExplore));
|
|
Assert.That(stack.Count, Is.EqualTo(3));
|
|
}
|
|
|
|
[Test]
|
|
public void CurrentOnEmptyStackReturnsNone()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
Assert.That(stack.Current, Is.EqualTo(InputContextId.None));
|
|
}
|
|
|
|
[Test]
|
|
public void PopRestoresPreviousContext()
|
|
{
|
|
InputContextStack stack = new InputContextStack();
|
|
stack.Push(InputContextId.GameplayExplore);
|
|
stack.Push(InputContextId.Dialog);
|
|
Assert.That(stack.Pop(out InputContextId popped), Is.True);
|
|
Assert.That(popped, Is.EqualTo(InputContextId.Dialog));
|
|
Assert.That(stack.Current, Is.EqualTo(InputContextId.GameplayExplore));
|
|
Assert.That(stack.Count, Is.EqualTo(1));
|
|
}
|
|
}
|
|
}
|
|
|