Beispiel #1
0
        public void NonViewPortTab_TryDiffFromNonViewPort_NoDiff()
        {
            editor.Add(new StubTabContent());

            editor.DiffLeft.Execute(editor[2]);

            Assert.False(editor.DiffLeft.CanExecute(editor[2]));
            Assert.Equal(3, editor.Count);
        }
Beispiel #2
0
        public void Goto_ByteNamePartialText_ReturnsByteRunName()
        {
            var editor = new EditorViewModel(new StubFileSystem());

            editor.Add(ViewPort);
            ViewPort.Edit(".some.counter ");

            editor.GotoViewModel.Text = "some.count";

            Assert.Contains("some.counter", editor.GotoViewModel.PrefixSelections[0].Tokens.Select(token => token.Content));
        }
Beispiel #3
0
        public void ByteName_Goto_CreatesNewTab()
        {
            var editor = new EditorViewModel(new StubFileSystem());

            editor.Add(ViewPort);
            ViewPort.Edit(".some.counter @02 .some.counter ");

            ViewPort.Goto.Execute("some.counter");

            Assert.Equal(2, editor.Count);
        }
Beispiel #4
0
        public void CanPrefixAddressWith0xDuringGoto()
        {
            var editor = new EditorViewModel(new StubFileSystem());
            var test   = new BaseViewModelTestClass();

            editor.Add(test.ViewPort);

            editor.GotoViewModel.Goto.Execute("0x0030");

            Assert.Equal(0x30, test.ViewPort.DataOffset);
        }
        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.
        }
Beispiel #6
0
        public void FindAllSourcesWorks()
        {
            var viewPort = ViewPort;
            var editor   = new EditorViewModel(new StubFileSystem());

            editor.Add(viewPort);

            viewPort.SelectionStart = new Point(4, 1);
            viewPort.Edit("<000120>");
            viewPort.FollowLink(4, 1);

            viewPort.FindAllSources(0, 0);

            Assert.Equal(1, editor.SelectedIndex);
        }
Beispiel #7
0
        public void CanGotoSingleOptionEvenWithoutPerfectMatch()
        {
            var test = new BaseViewModelTestClass();

            test.ViewPort.Edit("^pizza @piza ");
            Assert.Empty(test.Errors);

            test.ViewPort.Edit("@20 ^candy ");
            var editor = new EditorViewModel(new StubFileSystem());

            editor.Add(test.ViewPort);
            editor.GotoViewModel.Text = "cady";
            editor.GotoViewModel.Goto.Execute();

            Assert.Empty(test.Errors);
        }
        public void EditorForwardsTabDelayedWork()
        {
            void SomeAction()
            {
            }

            Action work   = null;
            var    editor = new EditorViewModel(new StubFileSystem());
            var    tab    = new StubTabContent();

            editor.Add(tab);

            editor.RequestDelayedWork += (sender, e) => work = e;
            tab.RequestDelayedWork.Invoke(tab, SomeAction);

            Assert.Equal(SomeAction, work);
        }
        public void CanResetAlignment()
        {
            var fileSystem = new StubFileSystem();

            StandardSetup(out var data, out var model, out var viewPort);
            var editor = new EditorViewModel(fileSystem);

            editor.Add(viewPort);

            viewPort.Goto.Execute("10");
            viewPort.Edit("^moves[name\"\"8]8 Adam\" Bob\" Carl\" Dave\" Elen\" Fred\" Gary\" Horton\"");
            viewPort.Width = 25;
            Assert.Equal(24, viewPort.Width); // closest smaller multiple of 8

            editor.ResetAlignment.Execute();
            Assert.Equal(16, viewPort.Width); // closest smaller multiple of 16
        }
Beispiel #10
0
        public void FindAllSourcesWorks()
        {
            var buffer   = new byte[0x200];
            var model    = new PokemonModel(buffer);
            var viewPort = new ViewPort("file.txt", model)
            {
                Width = 0x10, Height = 0x10
            };
            var editor = new EditorViewModel(new StubFileSystem());

            editor.Add(viewPort);

            viewPort.SelectionStart = new Point(4, 1);
            viewPort.Edit("<000120>");
            viewPort.FollowLink(4, 1);

            viewPort.FindAllSources(0, 0);

            Assert.Equal(1, editor.SelectedIndex);
        }
Beispiel #11
0
        public void ExpandableTutorsWorks(string game)
        {
            var fileSystem = new StubFileSystem();
            var model      = LoadModelNoCache(game);
            var editor     = new EditorViewModel(fileSystem, false);
            var viewPort   = new ViewPort(game, model);

            editor.Add(viewPort);
            var expandTutors = editor.QuickEdits.Single(edit => edit.Name == "Make Tutors Expandable");

            // ruby/sapphire/gaia do not support this quick-edit
            var canRun = expandTutors.CanRun(viewPort);

            if (game.Contains("Ruby") || game.Contains("Sapphire") || game.Contains("Gaia"))
            {
                Assert.False(canRun);
                return;
            }
            else
            {
                Assert.True(canRun);
            }

            // run the actual quick-edit
            expandTutors.Run(viewPort);

            // extend the table
            var table = (ArrayRun)model.GetNextRun(model.GetAddressFromAnchor(new ModelDelta(), -1, AutoSearchModel.MoveTutors));

            viewPort.Goto.Execute((table.Start + table.Length).ToString("X6"));
            viewPort.Edit("+");

            // the 4 bytes after the last pointer to tutor-compatibility should store the length of tutormoves
            table = (ArrayRun)model.GetNextRun(model.GetAddressFromAnchor(new ModelDelta(), -1, AutoSearchModel.MoveTutors));
            var tutorCompatibilityPointerSources = model.GetNextRun(model.GetAddressFromAnchor(new ModelDelta(), -1, AutoSearchModel.TutorCompatibility)).PointerSources;
            var word = (WordRun)model.GetNextRun(tutorCompatibilityPointerSources.Last() + 4);

            Assert.Equal(table.ElementCount, model.ReadValue(word.Start));
        }
Beispiel #12
0
        public void EditorUpdatesFileSystemWatchesWhenViewPortFileNameChanges()
        {
            var fileSystem = new StubFileSystem();
            int addCalls = 0, removeCalls = 0;

            fileSystem.AddListenerToFile     = (fileName, action) => addCalls++;
            fileSystem.RemoveListenerForFile = (fileName, action) => removeCalls++;
            var editor = new EditorViewModel(fileSystem);
            var tab    = new StubViewPort();

            editor.Add(tab);
            Assert.Equal(0, addCalls);
            Assert.Equal(0, removeCalls);

            tab.FileName = "file.txt";
            tab.PropertyChanged.Invoke(tab, new ExtendedPropertyChangedEventArgs(null, nameof(tab.FileName)));
            Assert.Equal(1, addCalls);
            Assert.Equal(0, removeCalls);

            tab.FileName = "file2.txt";
            tab.PropertyChanged.Invoke(tab, new ExtendedPropertyChangedEventArgs("file.txt", nameof(tab.FileName)));
            Assert.Equal(2, addCalls);
            Assert.Equal(1, removeCalls);
        }
        public void CanAddTabs()
        {
            var viewPort = new ViewPort();

            editor.Add(viewPort);
            Assert.Equal(1, editor.Count);
            Assert.Equal(0, editor.SelectedIndex);
        }