class Vehicle def drive(key as int) require key>0 pass def noRequireInBase(i as int) pass def noRequireInDerived(i as int) require i > 0 pass def twoBaseMethods(i as int) require i>0 pass def twoBaseMethods(s as String) require s.length pass shared def sharedMethod(key as int) require key > 0 pass class Car inherits Vehicle def drive(keyy as int) is override or require keyy==0 # the arg 'keyy' is intentionally spelled different to test that doing so works pass def noRequireInBase(i as int) is override or require i > 0 body pass def noRequireInDerived(i as int) is override pass def twoBaseMethods(i as int) is override or require i==0 pass shared def sharedMethod(key as int) is new require key==0 pass class Test def main is shared v = Vehicle() v.drive(1) expect RequireException v.drive(0) c = Car() c.drive(1) c.drive(0) expect RequireException c.drive(-1) c.noRequireInBase(1) c.noRequireInBase(0) # because base is essentially "require true" c.noRequireInDerived(1) expect RequireException c.noRequireInDerived(0) # base fails # multiple requirement failures: try c.drive(-1) catch re as RequireException assert re.next is not nil assert re.next.next is nil c.twoBaseMethods(0) c.twoBaseMethods(1) expect RequireException c.twoBaseMethods(-1) # shared: # not that there really isn't any overriding with shared methods # the following tests confirm that Vehicle.sharedMethod(1) expect RequireException Vehicle.sharedMethod(0) Car.sharedMethod(0) expect RequireException Car.sharedMethod(1)