Fixes #3064. Pos.View returns PosCombine (#3065)

This commit is contained in:
BDisp
2023-12-19 23:34:17 +00:00
committed by GitHub
parent 06ad562bc6
commit 74afd18148
8 changed files with 104 additions and 70 deletions

View File

@@ -87,15 +87,14 @@ namespace Terminal.Gui.ViewTests {
var testVal = Rect.Empty;
var testValView = new View (testVal);
var dim = Dim.Width (testValView);
Assert.Equal ($"View(Width,View()({testVal}))", dim.ToString ());
Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
testValView.Dispose ();
testVal = new Rect (1, 2, 3, 4);
testValView = new View (testVal);
dim = Dim.Width (testValView);
Assert.Equal ($"View(Width,View()({testVal}))", dim.ToString ());
Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
testValView.Dispose ();
}
[Fact, TestRespondersDisposed]
@@ -157,13 +156,13 @@ namespace Terminal.Gui.ViewTests {
var testVal = Rect.Empty;
var testValview = new View (testVal);
var dim = Dim.Height (testValview);
Assert.Equal ($"View(Height,View()({testVal}))", dim.ToString ());
Assert.Equal ($"View(Height,View(){testVal})", dim.ToString ());
testValview.Dispose ();
testVal = new Rect (1, 2, 3, 4);
testValview = new View (testVal);
dim = Dim.Height (testValview);
Assert.Equal ($"View(Height,View()({testVal}))", dim.ToString ());
Assert.Equal ($"View(Height,View(){testVal})", dim.ToString ());
testValview.Dispose ();
}
@@ -438,12 +437,12 @@ namespace Terminal.Gui.ViewTests {
Assert.Equal (49, f2.Frame.Width); // 50-1=49
Assert.Equal (5, f2.Frame.Height);
Assert.Equal ("Combine(View(Width,FrameView(f1)((0,0,49,5)))-Absolute(2))", v1.Width.ToString ());
Assert.Equal ("Combine(View(Width,FrameView(f1)(0,0,49,5))-Absolute(2))", v1.Width.ToString ());
Assert.Equal ("Combine(Fill(0)-Absolute(2))", v1.Height.ToString ());
Assert.Equal (47, v1.Frame.Width); // 49-2=47
Assert.Equal (89, v1.Frame.Height); // 98-5-2-2=89
Assert.Equal ("Combine(View(Width,FrameView(f2)((49,0,49,5)))-Absolute(2))", v2.Width.ToString ());
Assert.Equal ("Combine(View(Width,FrameView(f2)(49,0,49,5))-Absolute(2))", v2.Width.ToString ());
Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ());
Assert.Equal (47, v2.Frame.Width); // 49-2=47
Assert.Equal (89, v2.Frame.Height); // 98-5-2-2=89
@@ -458,8 +457,8 @@ namespace Terminal.Gui.ViewTests {
Assert.Equal (50, v4.Frame.Width);
Assert.Equal (50, v4.Frame.Height);
Assert.Equal ("Combine(View(Width,Button(v1)((2,7,47,89)))-View(Width,Button(v3)((0,0,9,9))))", v5.Width.ToString ());
Assert.Equal ("Combine(View(Height,Button(v1)((2,7,47,89)))-View(Height,Button(v3)((0,0,9,9))))", v5.Height.ToString ());
Assert.Equal ("Combine(View(Width,Button(v1)(2,7,47,89))-View(Width,Button(v3)(0,0,9,9)))", v5.Width.ToString ());
Assert.Equal ("Combine(View(Height,Button(v1)(2,7,47,89))-View(Height,Button(v3)(0,0,9,9)))", v5.Height.ToString ());
Assert.Equal (38, v5.Frame.Width); // 47-9=38
Assert.Equal (80, v5.Frame.Height); // 89-9=80
@@ -491,13 +490,13 @@ namespace Terminal.Gui.ViewTests {
Assert.Equal (5, f2.Frame.Height);
v1.Text = "Button1";
Assert.Equal ("Combine(View(Width,FrameView(f1)((0,0,99,5)))-Absolute(2))", v1.Width.ToString ());
Assert.Equal ("Combine(View(Width,FrameView(f1)(0,0,99,5))-Absolute(2))", v1.Width.ToString ());
Assert.Equal ("Combine(Fill(0)-Absolute(2))", v1.Height.ToString ());
Assert.Equal (97, v1.Frame.Width); // 99-2=97
Assert.Equal (189, v1.Frame.Height); // 198-2-7=189
v2.Text = "Button2";
Assert.Equal ("Combine(View(Width,FrameView(f2)((99,0,99,5)))-Absolute(2))", v2.Width.ToString ());
Assert.Equal ("Combine(View(Width,FrameView(f2)(99,0,99,5))-Absolute(2))", v2.Width.ToString ());
Assert.Equal ("Combine(Fill(0)-Absolute(2))", v2.Height.ToString ());
Assert.Equal (97, v2.Frame.Width); // 99-2=97
Assert.Equal (189, v2.Frame.Height); // 198-2-7=189
@@ -521,8 +520,8 @@ namespace Terminal.Gui.ViewTests {
Assert.Equal (1, v4.Frame.Height); // 1 because is Dim.DimAbsolute
v5.Text = "Button5";
Assert.Equal ("Combine(View(Width,Button(v1)((2,7,97,189)))-View(Width,Button(v3)((0,0,19,19))))", v5.Width.ToString ());
Assert.Equal ("Combine(View(Height,Button(v1)((2,7,97,189)))-View(Height,Button(v3)((0,0,19,19))))", v5.Height.ToString ());
Assert.Equal ("Combine(View(Width,Button(v1)(2,7,97,189))-View(Width,Button(v3)(0,0,19,19)))", v5.Width.ToString ());
Assert.Equal ("Combine(View(Height,Button(v1)(2,7,97,189))-View(Height,Button(v3)(0,0,19,19)))", v5.Height.ToString ());
Assert.Equal (78, v5.Frame.Width); // 97-9=78
Assert.Equal (170, v5.Frame.Height); // 189-19=170

View File

@@ -390,140 +390,140 @@ namespace Terminal.Gui.ViewTests {
testInt = 0;
testRect = Rect.Empty;
pos = Pos.Left (new View ());
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
pos = Pos.Left (new View (testRect));
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
testRect = new Rect (1, 2, 3, 4);
pos = Pos.Left (new View (testRect));
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
// Pos.Left(win) + 0
pos = Pos.Left (new View (testRect)) + testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
testInt = 1;
// Pos.Left(win) +1
pos = Pos.Left (new View (testRect)) + testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
testInt = -1;
// Pos.Left(win) -1
pos = Pos.Left (new View (testRect)) - testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
// Pos.X
side = "x";
testInt = 0;
testRect = Rect.Empty;
pos = Pos.X (new View ());
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
pos = Pos.X (new View (testRect));
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
testRect = new Rect (1, 2, 3, 4);
pos = Pos.X (new View (testRect));
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
// Pos.X(win) + 0
pos = Pos.X (new View (testRect)) + testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
testInt = 1;
// Pos.X(win) +1
pos = Pos.X (new View (testRect)) + testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
testInt = -1;
// Pos.X(win) -1
pos = Pos.X (new View (testRect)) - testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
// Pos.Top
side = "y";
testInt = 0;
testRect = Rect.Empty;
pos = Pos.Top (new View ());
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
pos = Pos.Top (new View (testRect));
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
testRect = new Rect (1, 2, 3, 4);
pos = Pos.Top (new View (testRect));
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
// Pos.Top(win) + 0
pos = Pos.Top (new View (testRect)) + testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
testInt = 1;
// Pos.Top(win) +1
pos = Pos.Top (new View (testRect)) + testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
testInt = -1;
// Pos.Top(win) -1
pos = Pos.Top (new View (testRect)) - testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
// Pos.Y
side = "y";
testInt = 0;
testRect = Rect.Empty;
pos = Pos.Y (new View ());
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
pos = Pos.Y (new View (testRect));
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
testRect = new Rect (1, 2, 3, 4);
pos = Pos.Y (new View (testRect));
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
// Pos.Y(win) + 0
pos = Pos.Y (new View (testRect)) + testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
testInt = 1;
// Pos.Y(win) +1
pos = Pos.Y (new View (testRect)) + testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
testInt = -1;
// Pos.Y(win) -1
pos = Pos.Y (new View (testRect)) - testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
// Pos.Bottom
side = "bottom";
testRect = Rect.Empty;
testInt = 0;
pos = Pos.Bottom (new View ());
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
pos = Pos.Bottom (new View (testRect));
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
testRect = new Rect (1, 2, 3, 4);
pos = Pos.Bottom (new View (testRect));
Assert.Equal ($"Combine(View({side},View()({testRect})){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"View(side={side},target=View(){testRect})", pos.ToString ());
// Pos.Bottom(win) + 0
pos = Pos.Bottom (new View (testRect)) + testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
testInt = 1;
// Pos.Bottom(win) +1
pos = Pos.Bottom (new View (testRect)) + testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
testInt = -1;
// Pos.Bottom(win) -1
pos = Pos.Bottom (new View (testRect)) - testInt;
Assert.Equal ($"Combine(Combine(View({side},View()({testRect}))+Absolute(0)){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
Assert.Equal ($"Combine(View(side={side},target=View(){testRect}){(testInt < 0 ? '-' : '+')}Absolute({testInt}))", pos.ToString ());
#if DEBUG_IDISPOSABLE
// HACK: Force clean up of Responders to avoid having to Dispose all the Views created above.
@@ -1084,5 +1084,41 @@ namespace Terminal.Gui.ViewTests {
super.Dispose ();
}
[Fact]
public void DoNotReturnPosCombine ()
{
var v = new View () { Id = "V" };
var pos = Pos.Left (v);
Assert.Equal (
"View(side=x,target=View(V)(0,0,0,0))",
pos.ToString ());
pos = Pos.X (v);
Assert.Equal (
"View(side=x,target=View(V)(0,0,0,0))",
pos.ToString ());
pos = Pos.Top (v);
Assert.Equal (
"View(side=y,target=View(V)(0,0,0,0))",
pos.ToString ());
pos = Pos.Y (v);
Assert.Equal (
"View(side=y,target=View(V)(0,0,0,0))",
pos.ToString ());
pos = Pos.Right (v);
Assert.Equal (
"View(side=right,target=View(V)(0,0,0,0))",
pos.ToString ());
pos = Pos.Bottom (v);
Assert.Equal (
"View(side=bottom,target=View(V)(0,0,0,0))",
pos.ToString ());
}
}
}

View File

@@ -22,7 +22,7 @@ namespace Terminal.Gui.ViewTests {
var r = new View ();
Assert.NotNull (r);
Assert.Equal (LayoutStyle.Computed, r.LayoutStyle);
Assert.Equal ("View()((0,0,0,0))", r.ToString ());
Assert.Equal ("View()(0,0,0,0)", r.ToString ());
Assert.False (r.CanFocus);
Assert.False (r.HasFocus);
Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds);
@@ -47,7 +47,7 @@ namespace Terminal.Gui.ViewTests {
r = new View (Rect.Empty);
Assert.NotNull (r);
Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
Assert.Equal ("View()((0,0,0,0))", r.ToString ());
Assert.Equal ("View()(0,0,0,0)", r.ToString ());
Assert.False (r.CanFocus);
Assert.False (r.HasFocus);
Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds);
@@ -72,7 +72,7 @@ namespace Terminal.Gui.ViewTests {
r = new View (new Rect (1, 2, 3, 4));
Assert.NotNull (r);
Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
Assert.Equal ("View()((1,2,3,4))", r.ToString ());
Assert.Equal ("View()(1,2,3,4)", r.ToString ());
Assert.False (r.CanFocus);
Assert.False (r.HasFocus);
Assert.Equal (new Rect (0, 0, 3, 4), r.Bounds);
@@ -97,7 +97,7 @@ namespace Terminal.Gui.ViewTests {
r = new View ("Vertical View", TextDirection.TopBottom_LeftRight);
Assert.NotNull (r);
Assert.Equal (LayoutStyle.Computed, r.LayoutStyle);
Assert.Equal ("View(Vertical View)((0,0,1,13))", r.ToString ());
Assert.Equal ("View(Vertical View)(0,0,1,13)", r.ToString ());
Assert.False (r.CanFocus);
Assert.False (r.HasFocus);
Assert.Equal (new Rect (0, 0, 1, 13), r.Bounds);
@@ -117,7 +117,6 @@ namespace Terminal.Gui.ViewTests {
Assert.Null (r.MostFocused);
Assert.Equal (TextDirection.TopBottom_LeftRight, r.TextDirection);
r.Dispose ();
}
[Fact, TestRespondersDisposed]