Giter VIP home page Giter VIP logo

Comments (3)

BDisp avatar BDisp commented on September 24, 2024

@tig I added these two DimAutoStyle.Auto unit tests to give an opinion on how the behavior is verified using ContentSize and Text. Only the test that uses Text fails if the maximum value is defined as Fill(). In my opinion, just like using ContentSize, the value returned from Fill() is what should be considered.

    [Fact]
    public void Dim_Auto_ContentSize_Min_Max ()
    {
        var size = new Size (5, 5);
        var view1 = new View { Width = Auto (DimAutoStyle.Auto, 10), Height = Auto (DimAutoStyle.Auto, 10) };
        view1.SetContentSize (size);
        var view2 = new View { Width = Auto (DimAutoStyle.Auto, 10, 30), Height = Auto (DimAutoStyle.Auto, 10, 30) };
        view2.SetContentSize (size);
        var view3 = new View { Width = Auto (DimAutoStyle.Auto, 10, Fill ()), Height = Auto (DimAutoStyle.Auto, 10, Fill ()) };
        view3.SetContentSize (size);
        var top = new View { Width = 20, Height = 20 };
        top.Add (view1, view2, view3);

        top.LayoutSubviews ();
        Assert.Equal (new (0, 0, 10, 10), view1.Frame);
        Assert.Equal (new (0, 0, 10, 10), view2.Frame);
        Assert.Equal (new (0, 0, 10, 10), view3.Frame);

        size = new (35, 35);
        view1.SetContentSize (size);
        view2.SetContentSize (size);
        view3.SetContentSize (size);
        top.Width = 40;
        top.Height = 40;
        top.LayoutSubviews ();
        Assert.Equal (size, view1.GetContentSize ());
        Assert.Equal (size, view2.GetContentSize ());
        Assert.Equal (size, view3.GetContentSize ());
        Assert.Equal (new (0, 0, 35, 35), view1.Frame);
        Assert.Equal (new (0, 0, 30, 30), view2.Frame);
        Assert.Equal (new (0, 0, 35, 35), view3.Frame);

        size = new (50, 50);
        view1.SetContentSize (size);
        view2.SetContentSize (size);
        view3.SetContentSize (size);
        top.LayoutSubviews ();
        Assert.Equal (size, view1.GetContentSize ());
        Assert.Equal (size, view2.GetContentSize ());
        Assert.Equal (size, view3.GetContentSize ());
        Assert.Equal (new (0, 0, 50, 50), view1.Frame);
        Assert.Equal (new (0, 0, 30, 30), view2.Frame);
        Assert.Equal (new (0, 0, 40, 40), view3.Frame);
    }

    [Fact]
    public void Dim_Auto_Text_Min_Max ()
    {
        var length = 5;
        var view1 = new View { Width = Auto (DimAutoStyle.Auto, 10), Height = Auto (DimAutoStyle.Auto, 10) };
        view1.Text = new ('x', length);
        var view2 = new View { Width = Auto (DimAutoStyle.Auto, 10, 30), Height = Auto (DimAutoStyle.Auto, 10, 30) };
        view2.TextDirection = TextDirection.TopBottom_LeftRight;
        view2.Text = new ('x', length);
        var view3 = new View { Width = Auto (DimAutoStyle.Auto, 10, Fill ()), Height = Auto (DimAutoStyle.Auto, 10, Fill ()) };
        view3.Text = new ('x', length);
        var top = new View { Width = 20, Height = 20 };
        top.Add (view1, view2, view3);

        top.LayoutSubviews ();
        Assert.Equal (new (0, 0, 10, 10), view1.Frame);
        Assert.Equal (new (0, 0, 10, 10), view2.Frame);
        Assert.Equal (new (0, 0, 10, 10), view3.Frame);

        length = 35;
        view1.Text = new ('x', length);
        view2.Text = new ('x', length);
        view3.Text = new ('x', length);
        top.Width = 40;
        top.Height = 40;
        top.LayoutSubviews ();
        Assert.Equal (length, view1.Text.Length);
        Assert.Equal (length, view2.Text.Length);
        Assert.Equal (length, view3.Text.Length);
        Assert.Equal (new (0, 0, 35, 10), view1.Frame);
        Assert.Equal (new (0, 0, 10, 30), view2.Frame);
        // This gives {X = 0 Y = 0 Width = 35 Height = 10}
        // but I think the Fill should be respected
        Assert.Equal (new (0, 0, 40, 10), view3.Frame);

        length = 50;
        view1.Text = new ('x', length);
        view2.Text = new ('x', length);
        view3.Text = new ('x', length);
        top.LayoutSubviews ();
        Assert.Equal (length, view1.Text.Length);
        Assert.Equal (length, view2.Text.Length);
        Assert.Equal (length, view3.Text.Length);
        Assert.Equal (new (0, 0, 50, 10), view1.Frame);
        Assert.Equal (new (0, 0, 10, 30), view2.Frame);
        Assert.Equal (new (0, 0, 40, 10), view3.Frame);
    }

from terminal.gui.

tig avatar tig commented on September 24, 2024

I appreciate you doing this, but there is a LOT going on in those tests. Is there any way you can simplify them down to more precise cases? If not, that's ok... but it would make my life a lot easier.

from terminal.gui.

BDisp avatar BDisp commented on September 24, 2024

Basically in each test, using DimAutoStyle.Auto, I am testing 3 views, where the first does not use the maximum value, the second uses an absolute value and the third uses Fill. In the first test I am using ContentSize and in the second I am using Text, where view2.TextDirection = TextDirection.TopBottom_LeftRight. Practically the tests pass as expected and the only exception is in the second test, using Text, in the view that is using Fill, it does not respect the width of the superview (40), returning Text.Length (35). I didn't want to use Theory to avoid complicating things and making it simpler.

from terminal.gui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.