Show
Ignore:
Timestamp:
07/31/08 21:19:39 (5 months ago)
Author:
Chuck.Esterbrook
Message:

Added support for omitting "this" and/or EventArgs?() in a "raise" statement.
Also, added warning that "this" is unnecessary and can be removed.
Also, added more error checking.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Tests/220-delegates-etc/120-events/300-raise.cobra

    r1560 r1566  
    55        event click as ClickHandler 
    66 
    7         def receiveMouseClick 
     7        def receiveMouseClick1 
    88                # pretend it's always in our bounds and we're enabled 
    9 #               raise .click(this, EventArgs()) 
    10                 raise .click, this, EventArgs() 
    11 #               raise .click, EventArgs() 
    12 #               raise .click 
    13 #               raise .click, this 
     9                raise .click, this, EventArgs()  # .warning. unnecessary "this" 
     10         
     11        def receiveMouseClick2 
     12                raise .click, EventArgs() 
     13 
     14        def receiveMouseClick3 
     15                raise .click, this  # .warning. unnecessary "this" 
     16 
     17        def receiveMouseClick4 
     18                raise .click 
    1419 
    1520 
     
    1823        shared 
    1924 
    20                 var _didClick = false 
     25                var _butt as Button 
     26                var _clickCount = 0 
    2127                 
    2228                def main 
    23                         butt = Button() 
     29                        butt = _butt = Button() 
     30 
    2431                        listen butt.click, ref .handleClick 
    25                         assert not _didClick 
    26                         butt.receiveMouseClick 
    27                         assert _didClick 
     32                        assert .clickCount == 0 
     33 
     34                        butt.receiveMouseClick1 
     35                        assert .clickCount == 1 
     36 
     37                        butt.receiveMouseClick2 
     38                        assert .clickCount == 2 
     39 
     40                        butt.receiveMouseClick3 
     41                        assert .clickCount == 3 
     42 
     43                        butt.receiveMouseClick4 
     44                        assert .clickCount == 4 
     45 
     46                get clickCount from var 
    2847 
    2948                def handleClick(sender as Object, args as EventArgs) 
    30                         _didClick = true 
     49                        assert sender is _butt 
     50                        assert (args to dynamic?) inherits EventArgs 
     51                        _clickCount += 1