Пример #1
0
        public void NamelessAnchor_Copy_StillHasNoName()
        {
            var fs = new StubFileSystem();

            ViewPort.Edit("<100> @100 @!put(FF) ^\"\" text");

            ViewPort.ExpandSelection(0, 0);
            ViewPort.Copy.Execute(fs);

            Assert.Contains("misc", fs.CopyText.value);
            Assert.Equal("^\"\"", ViewPort.AnchorText);
        }
Пример #2
0
        public void RedoAvailable_Copy_CanRedo()
        {
            var fs = new StubFileSystem();

            ViewPort.Edit("<020> @20 @!put(FF) ^\"\" text @180 DEADBEEF");
            ViewPort.Undo.Execute();

            ViewPort.Goto.Execute(0x20);
            ViewPort.ExpandSelection(0, 0);
            ViewPort.Copy.Execute(fs);

            Assert.True(ViewPort.Redo.CanExecute(default));
Пример #3
0
        public void TextData_DoubleClick_OpenTextTool()
        {
            SetFullModel(0xFF);
            ViewPort.Edit("^bob\"\" \"Some Text\"");
            ViewPort.Tools.SelectedIndex = -1;
            var view = new StubView(ViewPort.Tools);

            ViewPort.FollowLink(0, 0);

            Assert.Contains(nameof(ViewPort.Tools.SelectedIndex), view.PropertyNotifications);
            Assert.IsType <PCSTool>(ViewPort.Tools[ViewPort.Tools.SelectedIndex]);
        }
Пример #4
0
        public void CanUndoStringTruncate()
        {
            SetFullModel(0xFF);
            ViewPort.Edit("<008> @08 ^text\"\" \"Hello World!\" ");

            ViewPort.SelectionStart = new Point(0x0C, 0);
            ViewPort.Edit(ConsoleKey.Backspace);
            ViewPort.Undo.Execute();

            Assert.Equal(13, Model.GetNextRun(0x08).Length);
            Assert.Equal("\"Hello World!\"", ((PCS)ViewPort[0x0C, 0].Format).FullString);
        }
Пример #5
0
        public void TableCanHaveNumericLimitOnField()
        {
            ViewPort.Edit("^table[data.4]8 ");
            Assert.Empty(Errors);

            ViewPort.SelectionStart = new Point(2, 0);
            ViewPort.Edit("5 "); // you should still be able to manually enter bad values
            Assert.Equal(5, Model[0x02]);

            // a combobox is used for numeric limit fields
            ViewPort.Tools.TableTool.Children.Single(child => child is ComboBoxArrayElementViewModel);
        }
        public void EditedFilePromptsForSaveOnExit()
        {
            bool triedToSave = false;
            var  viewPort    = new ViewPort();

            viewPort.Edit("ab cd ef");
            fileSystem.TrySavePrompt = loadedFile => { triedToSave = true; return(true); };

            viewPort.Close.Execute(fileSystem);

            Assert.True(triedToSave);
        }
Пример #7
0
        public void ListWithNullEntries_AutoComplete_NoThrow()
        {
            Model.SetList("list", new[] { "zero", "one", null, "three" });
            ViewPort.Edit("^table[a:list]2 ");

            var visitor = new AutocompleteCell(Model, "e", 0);

            ViewPort[0, 0].Format.Visit(visitor, 0);
            var result = visitor.Result.Select(item => item.DisplayText.Trim()).ToArray();

            Assert.Equal(new[] { "zero", "one", "three" }, result);
        }
Пример #8
0
        public void TableGroup_LoadTable_TableToolContainsGroup()
        {
            ViewPort.Edit("@10 ^table1[data:]4 @20 ^table2[data:]table1 @30 ^table3[data:]table1 @40 ^table4[data:]table1 ");
            Model.AppendTableGroup(Token, "tables", new[] { "table1", "table2" }, null);

            ViewPort.Goto.Execute(0x10);
            var groups = ViewPort.Tools.TableTool.Groups;

            Assert.Equal(2, groups.Count);
            Assert.Equal("tables", groups[0].GroupName);
            Assert.Equal("Other", groups[1].GroupName);
        }
        public void UndoNotifiesCollectionChange()
        {
            int collectionNotifications = 0;

            ViewPort.CollectionChanged += (sender, e) => collectionNotifications++;

            ViewPort.Edit("0102030405");
            collectionNotifications = 0;
            ViewPort.Undo.Execute();

            Assert.Equal(1, collectionNotifications);
        }
Пример #10
0
        public void OneListLengthTable_EnumsUseList_AllowJumpToTable()
        {
            Model.SetList("list", new[] { "a", "b" });
            ViewPort.Edit("@00 ^table1[x:]list ");

            ViewPort.Edit("@100 ^table2[y:list]2 ");
            var tool = (ComboBoxArrayElementViewModel)ViewPort.Tools.TableTool.Children.Single(e => e is ComboBoxArrayElementViewModel cbaevm && cbaevm.Name == "y");

            tool.GotoSource.Execute();

            Assert.Equal(0, ViewPort.ConvertViewPointToAddress(ViewPort.SelectionStart));
        }
Пример #11
0
        public void TilemapTable_CheckDataFormat_IsSpriteDecorator()
        {
            ViewPort.Edit("^table[value.]tilemap ");

            var anchor = (Anchor)ViewPort[0, 0].Format;
            var format = (SpriteDecorator)anchor.OriginalFormat;

            Assert.Equal(4, format.CellWidth);
            Assert.Equal(4, format.CellHeight);
            Assert.Equal(4 * 8, format.Pixels.PixelWidth);
            Assert.Equal(4 * 8, format.Pixels.PixelHeight);
        }
Пример #12
0
        public void Tilemap_CreateTable_RunExists()
        {
            ViewPort.Edit("^table[value.]tilemap ");

            var table = Model.GetTable("table");

            Assert.IsType <TilemapTableRun>(table);
            Assert.Equal(4, table.ElementLength);
            Assert.Equal(4, table.ElementCount);
            Assert.Equal(4, table.ElementContent.Count);
            Assert.Equal("[value.]tilemap", table.FormatString);
        }
Пример #13
0
        public void RemoveBitRequiringArg_Contract()
        {
            using (run.CreateEditScope(Token)) run.HealHealth = true;
            PIERun newRun = new PIERun(Model, 0, SortedSpan <int> .None);

            Model.ObserveRunWritten(Token, newRun);

            ViewPort.Goto.Execute(4);
            ViewPort.Edit("0 ");

            Assert.Equal(6, Model.GetNextRun(0).Length);
        }
        public void BackspaceEditsSingleCellWhenNoFormats()
        {
            Model.ObserveRunWritten(new ModelDelta(), new AsciiRun(0x20, 0x10));
            Model[0] = 0xA0;
            Model[1] = 0xA1;
            Model[2] = 0xA2;

            ViewPort.SelectionStart = new Point(1, 0);
            ViewPort.Edit(ConsoleKey.Backspace);

            Assert.Equal(0xA2, Model[2]);
        }
Пример #15
0
        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]);
        }
Пример #16
0
        public void TupleTable_SelectNextElement_SameElement()
        {
            ViewPort.Edit("^table[value:|t|a:|b:]2 ");
            var tool        = ViewPort.Tools.TableTool;
            var tupleChild1 = TupleTable.Children[0];

            tool.Next.Execute();

            var tupleChild2 = TupleTable.Children[0];

            Assert.True(ReferenceEquals(tupleChild1, tupleChild2));
        }
Пример #17
0
        public void CanWriteString()
        {
            var buffer   = Enumerable.Repeat((byte)0xFF, 0x100).ToArray();
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("test.txt", model);

            viewPort.Edit("^bob\"\" \"Hello World!\"");

            var run = (PCSRun)model.GetNextRun(0);

            Assert.Equal(13, run.Length);
        }
Пример #18
0
        public void ScriptWithShop_EditShopItems_DataUpdates()
        {
            SetFullModel(0xFF);
            CreateTextTable("data.items.stats", 0x100, "adam", "bob", "carl", "dave", "eric", "fred");
            ViewPort.Edit("@00 ^script`xse` ");
            Assert.Equal(ViewPort.Tools.SelectedTool, ViewPort.Tools.CodeTool);

            ViewPort.Tools.CodeTool.Contents[0].Content = "pokemart <000080>";
            ViewPort.Tools.CodeTool.Contents[0].Content = Script("pokemart <000080>", "{", "carl", "}");

            Assert.Equal(2, Model.ReadMultiByteValue(0x80, 2));
        }
Пример #19
0
        public void TryingToWriteStringFormatToNonStringFormatDataFails()
        {
            var buffer   = new byte[0x100];
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("test.txt", model);
            var editor   = new EditorViewModel(new StubFileSystem());

            editor.Add(viewPort);

            viewPort.Edit("^\"\" ");
            Assert.False(string.IsNullOrEmpty(editor.ErrorMessage)); // should get an error, because the data located at the cursor could not convert to a string.
        }
        public void SaveCanExecuteChangesOnUndo()
        {
            int canExecuteChangedCount = 0;
            var viewPort = new ViewPort(new LoadedFile("input.txt", new byte[20]));

            viewPort.Save.CanExecuteChanged += (sender, e) => canExecuteChangedCount++;

            viewPort.Edit("aa bb cc");
            viewPort.Undo.Execute();

            Assert.Equal(2, canExecuteChangedCount);
        }
Пример #21
0
        public void TwoByteRuns_ChangeOne_ChangesTheOther()
        {
            ViewPort.Edit(".some.counter @02 .some.counter ");
            var run1 = (WordRun)Model.GetNextRun(0);
            var run2 = (WordRun)Model.GetNextRun(2);

            ViewPort.Edit("3 ");

            Assert.Equal(0, run1.Start);
            Assert.Equal(2, run2.Start);
            Assert.Equal(Model[run1.Start], Model[run2.Start]);
        }
Пример #22
0
        public void CanShortenPlmStream()
        {
            var fileSystem = new StubFileSystem();

            CreateTextTable(HardcodeTablesModel.MoveNamesTable, 0x100, "Punch", "Kick", "Bite", "Snarl", "Smile", "Cry");
            ViewPort.Edit("@00 FFFF @00 ^someMoves`plm` 3 Punch 5 Kick 7 Bite 11 Snarl ");

            ViewPort.Edit("@04 []");

            Assert.Equal(6, Model.GetNextRun(0).Length);
            Assert.Equal(new Point(6, 0), ViewPort.SelectionStart);
        }
Пример #23
0
        public void ListWithSpaceAndComma_WriteInEnum_EditWorks()
        {
            Model.SetList("list", new List <string> {
                "some|text", "other, text", "content"
            });
            ViewPort.Edit("^table[a:list]2 ");

            ViewPort.Edit("\"other, text\" ");

            Assert.Equal(1, Model.ReadMultiByteValue(0, 2));
            Assert.Equal(2, ViewPort.ConvertViewPointToAddress(ViewPort.SelectionStart));
        }
        public void FocusTable_ClearFormat_SelectionDoesNotMoveSeeRawBytes()
        {
            ViewPort.Edit("@40 ^table[a:: b:: c:: d::]20 ");

            var menuItem = ViewPort.GetContextMenuItems(new Point(0, 0)).Single(item => item.Text == "Clear Format");

            menuItem.Command.Execute();

            Assert.Equal(0, ViewPort.MinimumScroll);
            Assert.Equal(4, ViewPort.ScrollValue);
            Assert.Equal(0x20 - 1, ViewPort.MaximumScroll);
        }
Пример #25
0
        public void CanUndoDataMove()
        {
            var buffer   = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };

            viewPort.SelectionStart = new Point(8, 0);
            viewPort.Edit("<000030>");

            viewPort.SelectionStart = new Point(0, 0);
            viewPort.Edit("^bob\"\" \"Hello World!\"");

            viewPort.Undo.Execute(); // should undo the entire last edit transaction

            Assert.Equal(0xFF, model[0]);
            Assert.Equal(8, model.GetNextRun(0).Start);
            Assert.Equal(0x30, model.GetNextRun(0x10).Start);
            Assert.Equal(int.MaxValue, model.GetNextRun(0x31).Start);
        }
Пример #26
0
        public void CallingSaveMultipleTimesOnlySavesOnce()
        {
            int count    = 0;
            var viewPort = new ViewPort();

            fileSystem.Save = loadedFile => { count++; return(true); };

            viewPort.Edit("00 01 02");
            viewPort.Save.Execute(fileSystem);
            viewPort.Save.Execute(fileSystem);

            Assert.Equal(1, count);
        }
Пример #27
0
        public void FileDoesNotRaiseCloseEventIfSaveCanceled()
        {
            int closed   = 0;
            var viewPort = new ViewPort();

            viewPort.Closed         += (sender, e) => closed++;
            fileSystem.TrySavePrompt = loadedFile => null;

            viewPort.Edit("12");
            viewPort.Close.Execute(fileSystem);

            Assert.Equal(0, closed);
        }
Пример #28
0
        public void FileRaisesCloseEventIfNotSavedAfterEdit()
        {
            int closed   = 0;
            var viewPort = new ViewPort();

            viewPort.Closed         += (sender, e) => closed++;
            fileSystem.TrySavePrompt = loadedFile => false;

            viewPort.Edit("12");
            viewPort.Close.Execute(fileSystem);

            Assert.Equal(1, closed);
        }
Пример #29
0
        public void UndoFixesCorrectDataAfterScroll()
        {
            ViewPort.SelectionStart = new Point(2, 2);
            ViewPort.Edit("FF");

            ViewPort.SelectionStart = new Point(2, 2);
            ViewPort.Edit("EE");
            ViewPort.Scroll.Execute(Direction.Down);
            ViewPort.Undo.Execute();

            Assert.Equal(1, ViewPort.ScrollValue);
            Assert.Equal(0xFF, ViewPort[2, 1].Value);
        }
Пример #30
0
        public void SelectionChangeDuringEditNotifiesCollectionChange()
        {
            int collectionNotifications = 0;

            ViewPort.CollectionChanged += (sender, e) => collectionNotifications++;

            ViewPort.SelectionStart = new Point(4, 4);
            ViewPort.Edit("F");
            Assert.Equal(1, collectionNotifications);

            ViewPort.MoveSelectionStart.Execute(Direction.Up);
            Assert.Equal(3, collectionNotifications); // should have been notified since the visual data changed.
        }