mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-05-27 10:32:44 -05:00
Fix Tests
This commit is contained in:
parent
7b0c9f06e8
commit
030d8187ed
|
|
@ -553,6 +553,7 @@ namespace HavenSoft.HexManiac.Core.Models {
|
|||
if (existingRun is PointerRun && !(run is NoInfoRun) && !(run is PointerRun)) {
|
||||
var destination = ReadPointer(existingRun.Start);
|
||||
ClearPointer(changeToken, existingRun.Start, destination);
|
||||
index = BinarySearch(run.Start); // have to recalculate index, because ClearPointer can removed runs.
|
||||
}
|
||||
run = run.MergeAnchor(existingRun.PointerSources);
|
||||
if (run is NoInfoRun) run = existingRun.MergeAnchor(run.PointerSources); // when writing an anchor with no format, keep the existing format.
|
||||
|
|
@ -917,7 +918,7 @@ namespace HavenSoft.HexManiac.Core.Models {
|
|||
}
|
||||
|
||||
public override int FindFreeSpace(int start, int minimumLength) {
|
||||
start = FreeSpaceStart;
|
||||
if (FreeSpaceStart != 0) start = FreeSpaceStart;
|
||||
if (start < EarliestAllowedAnchor) start = EarliestAllowedAnchor;
|
||||
const int SpacerLength = 0x100;
|
||||
minimumLength += 0x140; // make sure there's plenty of room after, so that we're not in the middle of some other data set
|
||||
|
|
@ -1025,8 +1026,14 @@ namespace HavenSoft.HexManiac.Core.Models {
|
|||
public override void ClearPointer(ModelDelta currentChange, int source, int destination) {
|
||||
var index = BinarySearch(destination);
|
||||
currentChange.RemoveRun(runs[index]);
|
||||
runs[index] = runs[index].RemoveSource(source);
|
||||
currentChange.AddRun(runs[index]);
|
||||
|
||||
var newRun = runs[index].RemoveSource(source);
|
||||
if (newRun is NoInfoRun nir && nir.PointerSources.Count == 0) {
|
||||
runs.RemoveAt(index);
|
||||
} else {
|
||||
runs[index] = newRun;
|
||||
currentChange.AddRun(newRun);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearFormat(ModelDelta changeToken, int start, int length, bool keepInitialAnchorPointers, bool alsoClearData) {
|
||||
|
|
|
|||
|
|
@ -487,6 +487,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
|||
tabs.Add(content);
|
||||
SelectedIndex = tabs.Count - 1;
|
||||
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, content));
|
||||
AddContentListeners(content);
|
||||
if (content is IViewPort viewModel) {
|
||||
viewModel.UseCustomHeaders = useTableEntryHeaders;
|
||||
viewModel.AutoAdjustDataWidth = AutoAdjustDataWidth;
|
||||
|
|
@ -494,7 +495,6 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
|||
viewModel.StretchData = StretchData;
|
||||
viewModel.ValidateMatchedWords();
|
||||
}
|
||||
AddContentListeners(content);
|
||||
}
|
||||
|
||||
public void SwapTabs(int a, int b) {
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
|||
}
|
||||
}
|
||||
|
||||
private bool autoAdjustDataWidth, allowMultipleElementsPerLine;
|
||||
private bool autoAdjustDataWidth = true, allowMultipleElementsPerLine = true;
|
||||
public bool AutoAdjustDataWidth { get => autoAdjustDataWidth; set => Set(ref autoAdjustDataWidth, value); }
|
||||
public bool AllowMultipleElementsPerLine { get => allowMultipleElementsPerLine; set => Set(ref allowMultipleElementsPerLine, value); }
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools {
|
|||
var first = Math.Min(selectionStart, selectionEnd);
|
||||
var last = Math.Max(selectionStart, selectionEnd);
|
||||
for (int i = 0; i < Elements.Count; i++) Elements[i].Selected = first <= i && i <= last;
|
||||
createGradient.CanExecuteChanged.Invoke(createGradient, EventArgs.Empty);
|
||||
createGradient?.CanExecuteChanged.Invoke(createGradient, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,10 +42,10 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
[Fact]
|
||||
public void TableToolUpdatesAfterAnchorChange() {
|
||||
viewPort.AnchorText = "^array[data1. b data2.]8";
|
||||
Assert.Equal(3, viewPort.Tools.TableTool.Children.Count);
|
||||
Assert.Equal(4, viewPort.Tools.TableTool.Children.Count); // header + 3 elements
|
||||
|
||||
viewPort.AnchorText = "^array[data1. bc data2.]8";
|
||||
Assert.Equal("bc", ((FieldArrayElementViewModel)viewPort.Tools.TableTool.Children[1]).Name);
|
||||
Assert.Equal("bc", ((FieldArrayElementViewModel)viewPort.Tools.TableTool.Children[2]).Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -756,7 +756,7 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
|
||||
// act: change the table contents
|
||||
viewPort.SelectionStart = new Point(1, 0);
|
||||
var element = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children[0];
|
||||
var element = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children.Single(child => child is FieldArrayElementViewModel faevm && faevm.Name == "name");
|
||||
element.Content = "dog";
|
||||
|
||||
// assert: main view was updated
|
||||
|
|
@ -784,7 +784,7 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
viewPort.Edit("u");
|
||||
|
||||
// assert: main view was updated
|
||||
var element = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children[0];
|
||||
var element = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children.Single(child => child is FieldArrayElementViewModel faevm && faevm.Name == "name");
|
||||
Assert.Equal("cut", element.Content);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using HavenSoft.HexManiac.Core.ViewModels.DataFormats;
|
|||
using HavenSoft.HexManiac.Core.ViewModels.Tools;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace HavenSoft.HexManiac.Tests {
|
||||
|
|
@ -138,8 +139,8 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
viewPort.Edit("^table[description<\"\">]4 <000000>"); // note that this auto-scrolls, since a table was created
|
||||
viewPort.MoveSelectionStart.Execute(Direction.Left); // select the pointer we just completed
|
||||
|
||||
Assert.Equal(2, viewPort.Tools.TableTool.Children.Count);
|
||||
Assert.IsType<TextStreamElementViewModel>(viewPort.Tools.TableTool.Children[1]);
|
||||
Assert.Equal(3, viewPort.Tools.TableTool.Children.Count); // header, pointer, content
|
||||
Assert.IsType<TextStreamElementViewModel>(viewPort.Tools.TableTool.Children[2]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -151,12 +152,12 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
viewPort.SelectionStart = new Point(0, 4);
|
||||
viewPort.Edit("^table[description<\"\">]4 <000000>"); // note that this auto-scrolls, since a table was created
|
||||
viewPort.SelectionStart = new Point(0, 0);
|
||||
var textViewModel = (TextStreamElementViewModel)viewPort.Tools.TableTool.Children[1];
|
||||
var textViewModel = (TextStreamElementViewModel)viewPort.Tools.TableTool.Children.Single(child => child is TextStreamElementViewModel);
|
||||
|
||||
// act: use the tool to change the content, forcing a repoint
|
||||
messages.Clear();
|
||||
textViewModel.Content = "Xyz";
|
||||
var pointerViewModel = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children[0];
|
||||
var pointerViewModel = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children.Single(child => child is FieldArrayElementViewModel);
|
||||
|
||||
Assert.Single(messages); // we repointed
|
||||
Assert.NotEqual("<000000>", pointerViewModel.Content); // other tool field was updated
|
||||
|
|
@ -357,7 +358,7 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
Assert.Equal("tutormoves", segment.SourceArrayName);
|
||||
Assert.Equal(8, run.Length);
|
||||
|
||||
var bitList = (BitListArrayElementViewModel)viewPort.Tools.TableTool.Children[0];
|
||||
var bitList = (BitListArrayElementViewModel)viewPort.Tools.TableTool.Children.Single(child => child is BitListArrayElementViewModel);
|
||||
Assert.Equal("Four", bitList[2].BitLabel);
|
||||
|
||||
bitList[2].IsChecked = true; // "Adam" should be able to learn "Four"
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
|
||||
// Assert: Table Tool is updated
|
||||
viewPort.Tools.SelectedIndex = Enumerable.Range(0, 10).First(i => viewPort.Tools[i] == viewPort.Tools.TableTool);
|
||||
var field = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children[0];
|
||||
var field = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children[1];
|
||||
Assert.Equal("Larry", field.Content);
|
||||
}
|
||||
|
||||
|
|
@ -176,7 +176,7 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
|
||||
// Act: Update via the Table Tool
|
||||
viewPort.Tools.SelectedIndex = Enumerable.Range(0, 10).First(i => viewPort.Tools[i] == viewPort.Tools.TableTool);
|
||||
var field = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children[0];
|
||||
var field = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children[1];
|
||||
field.Content = "Larry";
|
||||
|
||||
// Assert: Text Tool is updated
|
||||
|
|
@ -218,7 +218,7 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
viewPort.Tools.SelectedIndex = Enumerable.Range(0, 10).First(i => viewPort.Tools[i] == viewPort.Tools.StringTool); // open the string tool
|
||||
viewPort.Tools.StringTool.ContentIndex = 12; // place the cursor somewhere, like the UI would
|
||||
viewPort.Tools.SelectedIndex = Enumerable.Range(0, 10).First(i => viewPort.Tools[i] == viewPort.Tools.TableTool); // open the table tool
|
||||
var field = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children[0];
|
||||
var field = (FieldArrayElementViewModel)viewPort.Tools.TableTool.Children[1];
|
||||
field.Content = "Larry"; // make a change with the table tool
|
||||
|
||||
Assert.NotEqual(new Point(), viewPort.SelectionStart);
|
||||
|
|
|
|||
|
|
@ -472,7 +472,7 @@ ApplicationVersion = '''0.1.0'''
|
|||
|
||||
[Fact]
|
||||
public void CanSaveVersionToToml() {
|
||||
var metadata = new StoredMetadata(null, null, null, null, new StubMetadataInfo { VersionNumber = "0.1.0" });
|
||||
var metadata = new StoredMetadata(null, null, null, null, new StubMetadataInfo { VersionNumber = "0.1.0" }, default);
|
||||
var lines = metadata.Serialize();
|
||||
Assert.Contains("[General]", lines);
|
||||
Assert.Contains("ApplicationVersion = '''0.1.0'''", lines);
|
||||
|
|
@ -480,7 +480,7 @@ ApplicationVersion = '''0.1.0'''
|
|||
|
||||
[Fact]
|
||||
public void NullVersionIsNotSavedToToml() {
|
||||
var metadata = new StoredMetadata(null, null, null, null, new StubMetadataInfo());
|
||||
var metadata = new StoredMetadata(null, null, null, null, new StubMetadataInfo(), default);
|
||||
var lines = metadata.Serialize();
|
||||
Assert.All(lines, line => Assert.DoesNotContain("ApplicationVersion = '''", line));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
|
||||
// update count via table: child run should update
|
||||
var tool = ViewPort.Tools.TableTool;
|
||||
var childCountField = (ComboBoxArrayElementViewModel)tool.Children[0];
|
||||
var childCountField = (ComboBoxArrayElementViewModel)tool.Children[1];
|
||||
childCountField.SelectedIndex = 3;
|
||||
Assert.Equal(0x10, ((ITableRun)Model.GetNextRun(0xA0)).ElementLength);
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ namespace HavenSoft.HexManiac.Tests {
|
|||
|
||||
// update count via table: sibling should update
|
||||
var tool = ViewPort.Tools.TableTool;
|
||||
var childCountField = (ComboBoxArrayElementViewModel)tool.Children[0];
|
||||
var childCountField = (ComboBoxArrayElementViewModel)tool.Children[1];
|
||||
childCountField.SelectedIndex = 3;
|
||||
Assert.Equal(3, Model[0x28]);
|
||||
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@
|
|||
<StackPanel Visibility="{Binding Visible, Converter={StaticResource BoolToVisibility}}">
|
||||
<hsg3hv:CommonTableStreamControl />
|
||||
<hsg3hv:PixelImage SnapsToDevicePixels="True" />
|
||||
<DockPanel>
|
||||
<DockPanel Visibility="{Binding HasMultiplePages, Converter={StaticResource BoolToVisibility}}" LastChildFill="False">
|
||||
<Button Content="Previous" Command="{Binding PreviousPage}" DockPanel.Dock="Left"/>
|
||||
<Button Content="Next" Command="{Binding NextPage}" DockPanel.Dock="Right"/>
|
||||
</DockPanel>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user