public void EditingMainContentUpdatesTableTool() { Model[0x42] = 3; // sat var changeToken = new ModelDelta(); var(model, viewPort) = (Model, ViewPort); // arrange: setup the anchor used for the enums WriteStrings(model.RawData, 0x00, "cat", "bat", "bat", "sat"); var error = ArrayRun.TryParse(model, "^[name\"\"4]4", 0x00, null, out var arrayRun); model.ObserveAnchorWritten(changeToken, "sample", arrayRun); // act: setup a viewmodel and show table tool ViewPort.Refresh(); viewPort.Tools.SelectedIndex = 1; // act: change the table contents viewPort.SelectionStart = new Point(1, 0); viewPort.Edit("u"); // assert: main view was updated var element = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children.Single(child => child is FieldArrayElementViewModel faevm && faevm.Name == "name"); Assert.Equal("cut", element.Content); }
public void ViewModelReturnsErrorWhenEnumIsNotValidValue() { Model[0x42] = 2; // hat var changeToken = new ModelDelta(); var(model, viewPort) = (Model, ViewPort); // arrange: setup the anchor used for the enums WriteStrings(model.RawData, 0x00, "cat", "bat", "hat", "sat"); var error = ArrayRun.TryParse(model, "^[name\"\"4]4", 0x00, null, out var arrayRun); model.ObserveAnchorWritten(changeToken, "sample", arrayRun); // arrange: setup the anchor with the data error = ArrayRun.TryParse(model, "[option.sample]4", 0x40, null, out arrayRun); model.ObserveAnchorWritten(changeToken, "data", arrayRun); // act: use a viewmodel to try to change 41 to 'pat' (invalid) ViewPort.Refresh(); viewPort.SelectionStart = new Point(1, 4); // select space 0x41 var errors = new List <string>(); viewPort.OnError += (sender, e) => errors.Add(e); viewPort.Edit("pat "); Assert.Single(errors); }
public void AnimationScript_CreateVisualTask_ArgumentsReadCorrectly() { SetFullModel(0xFF); ViewPort.Refresh(); var tool = ViewPort.Tools.CodeTool; ViewPort.Tools.CodeToolCommand.Execute(); ViewPort.SelectionStart = new Point(0, 0); tool.Mode = CodeMode.AnimationScript; var script = @" Script: createvisualtask <0BA7F9> 0x0A 0001 0000 0006 0000 0000 end "; tool.Contents[0].Content = script; // 03 createvisualtask address<> priority. [argv:] // 08 end var result = Model.Take(1 + 4 + 1 + (1 + 5 * 2) + 1).ToArray(); // op pointer prir arg 0 1 2 3 4 end Assert.Equal(new byte[] { 0x03, 0xF9, 0xA7, 0x0B, 0x08, 0x0A, 5, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 }, result); }
public ThumbRepointTests() { Model.ExpandData(ViewPort.CurrentChange, 0x400); SetFullModel(0xFF); Model.FreeSpaceBuffer = 0; Model.FreeSpaceStart = 0x100; ViewPort.Refresh(); }
public void TableWithNullPointer_LoadTableTool_CannotJumpToNull() { ViewPort.Edit("^table[ptr<>]1 "); ViewPort.Refresh(); var field = ViewPort.Tools.TableTool.Groups[0].Members.Single <FieldArrayElementViewModel>(); Assert.False(field.CanAccept()); }
public void RawBytes_WriteSameBytesAsOffsetPointer_MetadataOnlyChange() { Model.WritePointer(Token, 0, 0x104); Model.ObserveAnchorWritten(Token, "anchor", new NoInfoRun(0x100)); ViewPort.Refresh(); ViewPort.Edit("<anchor+4>"); Assert.True(ViewPort.IsMetadataOnlyChange); }
public void Run_Paste00DirectiveWithSameFormat_NoError() { Array.Copy(PCSString.Convert("Hello World").ToArray(), Model.RawData, 12); Model.ObserveRunWritten(new ModelDelta(), new PCSRun(Model, 0, 12)); ViewPort.Refresh(); ViewPort.Edit("@!00(12) ^anchor\"\" "); Assert.Empty(Errors); }
public void ListWithNullEntries_NoFilter_DoNotShowNullOptions() { Model.SetList("list", new[] { "zero", "one", null, "three" }); ViewPort.Edit("^table[a:list]2 "); ViewPort.Refresh(); var item = ViewPort.Tools.TableTool.Groups[0].Members.Single <ComboBoxArrayElementViewModel>(); Assert.Equal(new[] { "zero", "one", "three" }, item.Options.Select(option => option.Text)); }
public void ListWithNullEntries_ValueAfterNullInModel_ShowInTableTool() { Model[0] = 3; Model.SetList("list", new[] { "zero", "one", null, "three" }); ViewPort.Edit("^table[a:list]2 "); ViewPort.Refresh(); var item = ViewPort.Tools.TableTool.Groups[0].Members.Single <ComboBoxArrayElementViewModel>(); Assert.Equal("three", item.FilterText); }
public void ListWithNullEntries_SelectValueInTableTool_CorrectValueInModel() { Model.SetList("list", new[] { "zero", "one", null, "three" }); ViewPort.Edit("^table[a:list]2 "); ViewPort.Refresh(); var item = ViewPort.Tools.TableTool.Groups[0].Members.Single <ComboBoxArrayElementViewModel>(); item.SelectedIndex = 2; // "three" Assert.Equal(3, Model[0]); }
public void TableWithNullPointer_ReloadTableTool_NotifyCannotAccept() { ViewPort.Edit("^table[ptr<>]2 <100> @000 "); ViewPort.Refresh(); var field = ViewPort.Tools.TableTool.Groups[0].Members.Single <FieldArrayElementViewModel>(); var counter = 0; field.CanAcceptChanged += (sender, e) => counter += 1; ViewPort.Tools.TableTool.Next.Execute(); Assert.Equal(1, counter); }
public void Enum_Tooltip_ShowsText() { CreateTextTable("names", 0x100, "adam", "bob", "carl"); CreateEnumTable("enums", 0, "names", 0, 1, 2); ViewPort.Refresh(); var cell = ViewPort[1, 0]; var tooltipVisitor = new ToolTipContentVisitor(Model); cell.Format.Visit(tooltipVisitor, cell.Value); var content = tooltipVisitor.Content.Single().ToString(); Assert.Equal("adam", content); }
public void TupleSkip3Bits_Write23_Write184() { SetFullModel(0xFF); var stream = new TableStreamRun(Model, 0, SortedSpan <int> .None, "[index::|t|:.|i::::::.]", null, new FixedLengthStreamStrategy(2)); Model.ObserveRunWritten(ViewPort.CurrentChange, stream); ViewPort.Refresh(); ViewPort.Edit("23 "); Assert.Equal(23 * 8, Model[0]); Assert.Equal(0, Model[1]); Assert.Equal(0, Model[2]); Assert.Equal(0, Model[3]); }
public void Show(ViewPort viewPort) { viewPort.Clear(); viewPort.Console.ForegroundColor = ConsoleColor.Gray; for (int i = 0; i < width; ++i) { for (int j = 0; j < height; ++j) { if (plan[i, j] != Map.UNKNOWN) { viewPort.Write(plan[i, j], i, j); } } } viewPort.Refresh(); viewPort.Console.ReadKey(); }
public void EventScript_SingleSpaceOnLine_NoIssue() { SetFullModel(0xFF); ViewPort.Refresh(); var tool = ViewPort.Tools.CodeTool; ViewPort.Tools.CodeToolCommand.Execute(); ViewPort.SelectionStart = new Point(); tool.Mode = CodeMode.Script; var script = "Script:\n "; tool.Contents[0].Content = script; tool.Contents[0].CaretPosition = script.Length; // if it doesn't crash, we're good }
public void ArrayLengthRightClickOptionWhenClickingInLastRow() { // Arrange var(model, viewPort) = (Model, ViewPort); ArrayRun.TryParse(model, "[a: b:]8", 0, null, out var table); model.ObserveAnchorWritten(new ModelDelta(), "table", table); ViewPort.Refresh(); // Act viewPort.SelectionStart = new Point(0xD, 1); var items = viewPort.GetContextMenuItems(viewPort.SelectionStart); var extendItem = items.Single(item => item.Text.Contains("Extend Table")); extendItem.Command.Execute(); // Assert Assert.Equal(9, ((ArrayRun)model.GetNextRun(0)).ElementCount); }
public void CanCreateXseScriptFromContextMenu() { Model[0x22] = 0xFF; ViewPort.Refresh(); ViewPort.SelectionStart = new Point(2, 2); var group = (ContextItemGroup)ViewPort.GetContextMenuItems(new Point(2, 2)).Single(cmi => cmi.Text == "Create New..."); var item = group.Single(cmi => cmi.Text == "Event Script"); item.Command.Execute(); Assert.Equal(ViewPort.Tools.CodeTool, ViewPort.Tools.SelectedTool); Assert.Equal(CodeMode.Script, ViewPort.Tools.CodeTool.Mode); Assert.EndsWith("end", ViewPort.Tools.CodeTool.Contents.Single().Content.Trim()); Assert.IsType <XSERun>(Model.GetNextRun(0x22)); var anchorName = Model.GetAnchorFromAddress(-1, 0x22); Assert.NotEmpty(anchorName); Assert.Equal(anchorName, ViewPort.AnchorText.Substring(ViewPort.AnchorTextSelectionStart, ViewPort.AnchorTextSelectionLength)); }
public void CopyAnUnnamedStringInsertsAName() { var text = "This is the song that never ends."; var bytes = PCSString.Convert(text).ToArray(); SetFullModel(0xFF); var(model, viewPort) = (Model, ViewPort); Array.Copy(bytes, 0, model.RawData, 0x30, bytes.Length); Array.Copy(new byte[] { 0x30, 0, 0, 0x08 }, 0, model.RawData, 0x10, 4); // the pointer to the data. Pointer is aligned, but data is not. var fileSystem = new StubFileSystem(); model.Load(model.RawData, null); ViewPort.Refresh(); viewPort.SelectionStart = new Point(0, 3); viewPort.ExpandSelection(0, 3); viewPort.Copy.Execute(fileSystem); Assert.Contains(".This", fileSystem.CopyText); Assert.Contains("\"\" \"This", fileSystem.CopyText); // format, then space, then start of text }
public void CustomHeadersWork() { var changeToken = new ModelDelta(); var(model, viewPort) = (Model, ViewPort); // arrange: setup the anchor used for the enums WriteStrings(model.RawData, 0x00, "cat", "bat", "bat", "sat"); ArrayRun.TryParse(model, "^[name\"\"4]4", 0x00, null, out var parentArray); model.ObserveAnchorWritten(changeToken, "parent", parentArray); ArrayRun.TryParse(model, "[a:: b:: c:: d::]parent", 0x20, null, out var childArray); model.ObserveAnchorWritten(changeToken, "child", childArray); ViewPort.Refresh(); // act/assert: check that the headers are the names when custom headers are turned on viewPort.UseCustomHeaders = true; Assert.Equal("cat", viewPort.Headers[2]); // act/assert: check that the headers are normal when custom headers are turned off viewPort.UseCustomHeaders = false; Assert.Equal("000020", viewPort.Headers[2]); }
public void CanAddTextFormatToAnchorUsedOnlyByAnArray() { var changeToken = new ModelDelta(); var(model, viewPort) = (Model, ViewPort); WriteStrings(model.RawData, 0x10, "This is a song!"); ArrayRun.TryParse(model, "^[content<>]4", 0x00, null, out var array); model.WritePointer(changeToken, 0x04, 0x10); model.ObserveAnchorWritten(changeToken, "array", array); // there is a pointer at 0x00 that points to 0x10 // but we know about it via an array // at 0x10 is text // but we don't know that it's text ViewPort.Refresh(); viewPort.SelectionStart = new Point(0, 1); viewPort.Edit("^\"\" "); // adding the format should've stuck Assert.Empty(Errors); Assert.IsType <PCS>(viewPort[1, 1].Format); }
public void ArraysSupportEditingEnums() { Model[0x42] = 2; // hat var changeToken = new ModelDelta(); var(model, viewPort) = (Model, ViewPort); // arrange: setup the anchor used for the enums WriteStrings(model.RawData, 0x00, "cat", "bat", "hat", "sat"); ArrayRun.TryParse(model, "^[name\"\"4]4", 0x00, null, out var arrayRun); model.ObserveAnchorWritten(changeToken, "sample", arrayRun); // arrange: setup the anchor with the data ArrayRun.TryParse(model, "[option.sample]4", 0x40, null, out arrayRun); model.ObserveAnchorWritten(changeToken, "data", arrayRun); // act: use a viewmodel to change 0x41 to 'bat' ViewPort.Refresh(); viewPort.SelectionStart = new Point(1, 4); // select space 0x41 viewPort.Edit("bat "); Assert.Equal(1, Model[0x41]); }
public void AnimationScript_Write_Written() { SetFullModel(0xFF); ViewPort.Refresh(); var tool = ViewPort.Tools.CodeTool; ViewPort.Tools.CodeToolCommand.Execute(); ViewPort.SelectionStart = new Point(0, 0); tool.Mode = CodeMode.AnimationScript; var script = @" Script: delay 0x10 end"; tool.Contents[0].Content = script; // 04 delay time. // 08 end var result = Model.Take(3).ToArray(); Assert.Equal(new byte[] { 0x04, 0x10, 0x08 }, result); }
public void ParentTableAutoMoveNotifies() { // Arrange SetFullModel(0x42); var(model, viewPort) = (Model, ViewPort); ArrayRun.TryParse(model, "[a: b:]8", 0x20, null, out var table); // parent table starts directly after child table model.ObserveAnchorWritten(new ModelDelta(), "parent", table); ArrayRun.TryParse(model, "[a: b:]parent", 0x00, null, out table); model.ObserveAnchorWritten(new ModelDelta(), "child", table); ViewPort.Refresh(); // Act viewPort.SelectionStart = new Point(0xD, 1); viewPort.Tools.SelectedIndex = viewPort.Tools.IndexOf(viewPort.Tools.TableTool); viewPort.Tools.TableTool.Append.Execute(); // Assert Assert.Equal(0, model.GetNextRun(0).Start); // the run being edit did not move Assert.Single(Messages); // user was notified about the other move }
public void MultipleEnumValuesWithSameContentAreDistinguishable() { Model[0x42] = 2; // bat~2 var changeToken = new ModelDelta(); var(model, viewPort) = (Model, ViewPort); // arrange: setup the anchor used for the enums WriteStrings(model.RawData, 0x00, "cat", "bat", "bat", "sat"); ArrayRun.TryParse(model, "^[name\"\"4]4", 0x00, null, out var arrayRun); model.ObserveAnchorWritten(changeToken, "sample", arrayRun); // arrange: setup the anchor with the data ArrayRun.TryParse(model, "[option.sample]4", 0x40, null, out arrayRun); model.ObserveAnchorWritten(changeToken, "data", arrayRun); // act: setup a viewmodel ViewPort.Refresh(); // assert: viewmodel should render bat~2 at 0x42 var format = (IntegerEnum)viewPort[2, 4].Format; Assert.Equal("bat~2", format.Value); }
public void CanEditToSecondEnumWithSameContent() { Model[0x42] = 3; // sat var changeToken = new ModelDelta(); var(model, viewPort) = (Model, ViewPort); // arrange: setup the anchor used for the enums WriteStrings(model.RawData, 0x00, "cat", "bat", "bat", "sat"); ArrayRun.TryParse(model, "^[name\"\"4]4", 0x00, null, out var arrayRun); model.ObserveAnchorWritten(changeToken, "sample", arrayRun); // arrange: setup the anchor with the data ArrayRun.TryParse(model, "[option.sample]4", 0x40, null, out arrayRun); model.ObserveAnchorWritten(changeToken, "data", arrayRun); // act: setup a viewmodel and change 0x41 to bat~2 ViewPort.Refresh(); viewPort.SelectionStart = new Point(1, 4); // select space 0x41 viewPort.Edit("bat~2 "); // assert: viewmodel should render bat~2 at 0x42 Assert.Equal(2, model.RawData[0x41]); }
public void TrainerWithTwoPokemon_ChangePokemonCountToThree_PokemonTeamRepoints() { // write data for two trainers Model[TrainerTablePokemonCountOffset] = 2; Model.WritePointer(new ModelDelta(), TrainerTablePokemonPointerOffset, 0x80); WriteBasicTrainerPokmeon(0x80, 0, 5, 0); WriteBasicTrainerPokmeon(0x88, 0, 5, 0); Model[TrainerTableElementLength + TrainerTablePokemonCountOffset] = 2; Model.WritePointer(new ModelDelta(), TrainerTableElementLength + TrainerTablePokemonPointerOffset, 0x88); WriteBasicTrainerPokmeon(0x90, 0, 5, 0); WriteBasicTrainerPokmeon(0x98, 0, 5, 0); SetupTrainerTable(0, 2); // set the trainer to have 3 pokemon ViewPort.Refresh(); var tool = (FieldArrayElementViewModel)ViewPort.Tools.TableTool.Children.Single(child => child is FieldArrayElementViewModel faevm && faevm.Name == "pokemonCount"); tool.Content = "3"; Assert.Single(Messages); Assert.NotEqual(0x80, Model.GetNextRun(0x80).Start); // run should've repointed Assert.NotEqual(0x80, Model.ReadPointer(TrainerTablePokemonPointerOffset)); }