# HG changeset patch # User Diggory Hardy # Date 1230461715 0 # Node ID 9ac208b53582f404ece6589df6d54e108aa8721c # Parent aba2dd815a1f1aff84984630ad7b0094fdebfc6f Unittest for mde.gui.widget.layout. diff -r aba2dd815a1f -r 9ac208b53582 mde/gui/widget/layout.d --- a/mde/gui/widget/layout.d Fri Dec 26 12:07:38 2008 +0000 +++ b/mde/gui/widget/layout.d Sun Dec 28 10:55:15 2008 +0000 @@ -702,6 +702,65 @@ static this () { instances = new HashMap!(widgetID,AlignColumns); } + + debug invariant() + { + if (setupWidths) { + assert (width.length == minWidth.length); + wdim x = 0; + foreach (i,w; width) { + assert (minWidth[i] <= w); // even when "not sizable", cols may get enlarged + assert (x == pos[i]); + x += w + spacing; + } + assert (x - spacing == w); + x = spacing * cast(wdim)(minWidth.length - 1); + foreach (mw; minWidth) + x += mw; + assert (x == mw); + } + } + + debug (mdeUnitTest) unittest { + bool throws (void delegate() dg) { + bool r = false; + try { + dg(); + } catch (Exception e) { + r = true; + } + return r; + } + + AlignColumns a, a2, b; + a = getInstance ("a", 2); + a2 = getInstance ("a", 2); + b = getInstance ("b", 5); + assert (a is a2); + assert (a !is b); + assert (throws ({ getInstance ("a", 4); })); + + a.setup (0, 3); + a.spacing = 6; + a.minWidth[0] = 50; + a.minWidth[1] = 6; + a.sizable[1] = true; + a.setWidths; + assert (a.w == 62); + + b.setup (0,3); + b.spacing = 2; + foreach (ref wd; b.minWidth) + wd = 10; + b.sizable[1] = b.sizable[3] = true; + b.setWidths; + assert (b.w == 58); + + assert (b.resizeWidth (60, -1) == 60); + assert (b.width[3] == 12); + + logger.info ("Unittest complete."); + } } // Index types. Note that in some cases they need to hold negative values. diff -r aba2dd815a1f -r 9ac208b53582 mde/mde.d --- a/mde/mde.d Fri Dec 26 12:07:38 2008 +0000 +++ b/mde/mde.d Sun Dec 28 10:55:15 2008 +0000 @@ -34,6 +34,7 @@ import mde.file.ssi; import mde.file.mergetag.mdeUT; import mde.lookup.Translation; + import mde.gui.widget.layout; } //BEGIN A simple drawable to print a message in the window.