# # Copyright (c) 2002, Benja Fallenstein # # You may use and distribute under the terms of either the GNU Lesser # General Public License, either version 2 of the license or, # at your choice, any later version. Alternatively, you may use and # distribute under the terms of the XPL. # # See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of # the licenses. # # This software is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README # file for more details. # import java, gzz from gzz.zzutil import Containment class Dims: def __init__(self, s): for name in ['contain', 'contain_list']: setattr(self, name, s.getDim(getattr(gzz.zzutil.Ids, 'd_' + name))) def testGetContained(): s = space() d = Dims(s) c = s.N() c.setText("Hell") c1 = c.N(d.contain) c1.setText("o") c2 = c1.N(d.contain_list) c2.setText(" World") c1a = c1.N(d.contain) c1b = c1a.N(d.contain_list) c1b.setText(",") c3 = c2.N(d.contain_list) c3.setText("!") assert c.t() == "Hell" assert Containment.getContainedText(c) == "Hello, World!" assert Containment.getContainedText(c1) == "o," assert Containment.getContainedText(c2) == " World" assert Containment.getContainedText(c3) == "!" enfs = [s.getCellTexter().getEnfilade(x, None) for x in (c, c1, c1a, c1b, c2, c3)] empty = enfs[0].getMaker().makeEnfilade() enf = reduce(lambda e,f: e.plus(f), enfs, empty) assert enf.makeString() == "Hello, World!" assert Containment.getContainedEnfilade(c) == enf assert Containment.getContainedEnfilade(c1) == \ enfs[1].plus(enfs[2].plus(enfs[3])) assert Containment.getContainedEnfilade(c2) == enfs[4] assert Containment.getContainedEnfilade(c3) == enfs[5] def testAddContained(): s = space() d = Dims(s) c = s.N() c.setText("A") c1 = s.N() c1.setText(" true") c1a = s.N() c1a.setText(" ") c2 = s.N() c2.setText("challenge") add = Containment.addContainedCell get = Containment.getContainedText add(c, c1); add(c, c2); add(c1, c1a); assert get(c) == "A true challenge" assert get(c1) == " true " assert c.t() == "A" try: add(c2, c1a) except java.lang.IllegalArgumentException: pass else: assert 0 assert get(c) == "A true challenge" assert get(c1) == " true " assert c.t() == "A"