using Clave; using System; using UnitTestSharp; namespace Glass.UnitTests { public class EntryListBehaviorTests : TestFixture { public static ChordSet Pressing(KeyCode key) { return ChordSet.Of(Chord.PressOrRepeat(key)); } public class DefaultTests : TestFixture { public void IsSharedAcrossReads() { CheckTrue(ReferenceEquals(EntryListBehavior.Default, EntryListBehavior.Default)); } public void MovingKeysEachHaveOneChord() { CheckEqual(1, EntryListBehavior.Default.PreviousChords.Count); CheckEqual(1, EntryListBehavior.Default.NextChords.Count); CheckEqual(1, EntryListBehavior.Default.PagePreviousChords.Count); CheckEqual(1, EntryListBehavior.Default.PageNextChords.Count); CheckEqual(1, EntryListBehavior.Default.FirstChords.Count); CheckEqual(1, EntryListBehavior.Default.LastChords.Count); } public void BothEnterKeysOpen() { CheckEqual(2, EntryListBehavior.Default.OpenChords.Count); } public void BackspaceGoesUp() { CheckEqual(1, EntryListBehavior.Default.ParentChords.Count); } public void KeyChordsHoldEveryChord() { CheckEqual(13, EntryListBehavior.Default.KeyChords.Count); } public void F2Renames() { CheckEqual(1, EntryListBehavior.Default.RenameChords.Count); } public void DeleteDeletes() { CheckEqual(1, EntryListBehavior.Default.DeleteChords.Count); } public void ControlZUndoes() { CheckEqual(1, EntryListBehavior.Default.UndoChords.Count); } public void ControlYRedoes() { CheckEqual(1, EntryListBehavior.Default.RedoChords.Count); } } public class ChordSetTests : TestFixture { public void EachSetGivenIsKept() { ChordSet previous = Pressing(KeyCode.Q); ChordSet next = Pressing(KeyCode.E); ChordSet pagePrevious = Pressing(KeyCode.A); ChordSet pageNext = Pressing(KeyCode.D); ChordSet first = Pressing(KeyCode.Z); ChordSet last = Pressing(KeyCode.C); ChordSet open = Pressing(KeyCode.R); ChordSet parent = Pressing(KeyCode.F); ChordSet rename = Pressing(KeyCode.G); ChordSet delete = Pressing(KeyCode.H); ChordSet undo = Pressing(KeyCode.J); ChordSet redo = Pressing(KeyCode.K); var behavior = new EntryListBehavior { PreviousChords = previous, NextChords = next, PagePreviousChords = pagePrevious, PageNextChords = pageNext, FirstChords = first, LastChords = last, OpenChords = open, ParentChords = parent, RenameChords = rename, DeleteChords = delete, UndoChords = undo, RedoChords = redo, }; CheckTrue(ReferenceEquals(previous, behavior.PreviousChords)); CheckTrue(ReferenceEquals(next, behavior.NextChords)); CheckTrue(ReferenceEquals(pagePrevious, behavior.PagePreviousChords)); CheckTrue(ReferenceEquals(pageNext, behavior.PageNextChords)); CheckTrue(ReferenceEquals(first, behavior.FirstChords)); CheckTrue(ReferenceEquals(last, behavior.LastChords)); CheckTrue(ReferenceEquals(open, behavior.OpenChords)); CheckTrue(ReferenceEquals(parent, behavior.ParentChords)); CheckTrue(ReferenceEquals(rename, behavior.RenameChords)); CheckTrue(ReferenceEquals(delete, behavior.DeleteChords)); CheckTrue(ReferenceEquals(undo, behavior.UndoChords)); CheckTrue(ReferenceEquals(redo, behavior.RedoChords)); } public void SetsLeftOut_KeepTheDefaultKeys() { var behavior = new EntryListBehavior { PreviousChords = Pressing(KeyCode.Q) }; CheckEqual(2, behavior.OpenChords.Count); CheckEqual(1, behavior.ParentChords.Count); CheckEqual(1, behavior.LastChords.Count); CheckEqual(1, behavior.RenameChords.Count); CheckEqual(1, behavior.DeleteChords.Count); CheckEqual(1, behavior.UndoChords.Count); CheckEqual(1, behavior.RedoChords.Count); } public void Null_Throws() { CheckThrow(typeof(ArgumentNullException)); new EntryListBehavior { OpenChords = null }; } public void OneSetInTwoSlots_Throws() { ChordSet shared = Pressing(KeyCode.Q); CheckThrow(typeof(ArgumentException)); new EntryListBehavior { PreviousChords = shared, NextChords = shared }; } } public class KeyChordsTests : TestFixture { public void CoverOnlyTheChordsInPlace() { var behavior = new EntryListBehavior { PreviousChords = Pressing(KeyCode.Q), OpenChords = Pressing(KeyCode.E), }; CheckEqual(12, behavior.KeyChords.Count); } public void FollowAChordSetChangedWithWith() { EntryListBehavior changed = EntryListBehavior.Default with { FirstChords = Pressing(KeyCode.Q) }; CheckEqual(13, changed.KeyChords.Count); CheckFalse(ReferenceEquals(EntryListBehavior.Default.KeyChords, changed.KeyChords)); } public void LeaveTheOriginalAloneWhenCopiedWithWith() { EntryListBehavior original = EntryListBehavior.Default; EntryListBehavior unused = original with { FirstChords = Pressing(KeyCode.Q) }; CheckEqual(13, original.KeyChords.Count); CheckEqual(1, original.FirstChords.Count); } } } }