6.19.10.2.3.1. Begin/end test

Start data section to interscript/tests/test_beginend.pak[1 /1 ]
     1: @head(1,'Begin/End test')
     2: We test the @begin and @end commands with a simple scoping test.
     3: First, a level is set to 1, and we create a class with
     4: a destructor and an object thereof.
     5: @class X:
     6:    def __init__(self, level, weaver):
     7:      self.level = level
     8:      self.current_weaver = weaver
     9:      self.str = str
    10:    def __del__(self):
    11:      self.current_weaver.writeline('X object of level '+self.str(self.level)+' destroyed.')
    12:  level=1
    13:  x = X(level, get_weaver())
    14: @weave('Level is '+str(level)+'. ')
    15: @p()
    16: Now, a new block.
    17: @begin()
    18: Check old value of level.
    19: @weave('Level is '+str(level)+'. ')
    20: Now set level to 2, and create another class object.
    21: @level = 2
    22: @x = X(level,get_weaver())
    23: @weave('Level is '+str(level)+'. ')
    24: @p()
    25: Finally we end the block here. This should kill the inner class object.
    26: @end()
    27: @p()
    28: Back in the old block we test the level.
    29: @weave('Level is '+str(level)+'. ')
    30: That's the simple test. Now, the outer class object should die.
End data section to interscript/tests/test_beginend.pak[1]
We can look at the html results at ../tests/en_test_beginend.html