Smart pascal source code
type
TBase = class
procedure Check(i: Integer); virtual;
end;
type
TChild = class(TBase)
end;
type
TSubChild = class(TBase)
procedure Check(i: Integer); override;
end;
procedure TBase.Check(i: Integer);
require i > 0;
begin
WriteLn('base ' + IntToStr(i));
ensure i < 10;
end;
procedure TSubChild.Check(i: Integer);
begin
WriteLn('subchild ' + IntToStr(i));
ensure i < 5: 'was ' + IntToStr(i);
end;
var b = TBase.Create;
WriteLn('TBase');
b.Check(1);
try
b.Check(-1);
except
on E: Exception do
WriteLn(E.Message);
end;
b.Check(7);
try
b.Check(10);
except
on E: Exception do
WriteLn(E.Message);
end;
var c = TChild.Create;
WriteLn('TChild');
c.Check(1);
try
c.Check(-1);
except
on E: Exception do
WriteLn(E.Message);
end;
c.Check(7);
try
c.Check(10);
except
on E: Exception do
WriteLn(E.Message);
end;
var s = TSubChild.Create;
WriteLn('TSubChild');
s.Check(1);
try
s.Check(-1);
except
on E: Exception do
WriteLn(E.Message);
end;
s.Check(4);
try
s.Check(7);
except
on E: Exception do
WriteLn(E.Message);
end;
try
s.Check(10);
except
on E: Exception do
WriteLn(E.Message);
end;
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
TBase
base 1
Pre-condition failed in TBase.Check [line: 15, column: 4], i > 0
base 7
base 10
Post-condition failed in TBase.Check [line: 19, column: 4], i < 10
TChild
base 1
Pre-condition failed in TBase.Check [line: 15, column: 4], i > 0
base 7
base 10
Post-condition failed in TBase.Check [line: 19, column: 4], i < 10
TSubChild
subchild 1
Pre-condition failed in TBase.Check [line: 15, column: 4], i > 0
subchild 4
subchild 7
Post-condition failed in TSubChild.Check [line: 26, column: 4], was 7
subchild 10
Post-condition failed in TSubChild.Check [line: 26, column: 4], was 10
-----------------------------
{<<<<<<<<< THE END >>>>>>>>>}
var TBase = {
$ClassName:"TBase",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
}
,Check:function(Self, i) {
if (!(i>0)) $CondFailed("Pre-condition failed in TBase.Check [line: 18, column: 9], ","i > 0");
WriteLn(("base "+i.toString()));
if (!(i<10)) $CondFailed("Post-condition failed in TBase.Check [line: 21, column: 10], ","i < 10");
}
,Destroy:TObject.Destroy
,Check$:function($){return $.ClassType.Check.apply($.ClassType, arguments)}
};
var TSubChild = {
$ClassName:"TSubChild",$Parent:TBase
,$Init:function ($) {
TBase.$Init($);
}
,Check:function(Self, i$1) {
if (!(i>0)) $CondFailed("Pre-condition failed in TBase.Check [line: 18, column: 9], ","i > 0");
WriteLn(("subchild "+i$1.toString()));
if (!(i$1<5)) $CondFailed("Post-condition failed in TSubChild.Check [line: 27, column: 10], ",("was "+i$1.toString()));
if (!(i<10)) $CondFailed("Post-condition failed in TBase.Check [line: 21, column: 10], ","i < 10");
}
,Destroy:TObject.Destroy
,Check$:function($){return $.ClassType.Check.apply($.ClassType, arguments)}
};
var TChild = {
$ClassName:"TChild",$Parent:TBase
,$Init:function ($) {
TBase.$Init($);
}
,Destroy:TObject.Destroy
,Check:TBase.Check
};
var b = null,
c = null,
s = null;
/* <<< main JS >>> */
b = TObject.Create($New(TBase));
WriteLn("TBase");
TBase.Check$($Check(b,""),1);
try {
TBase.Check$($Check(b,""),-1);
} catch ($e) {
var E = $W($e);
WriteLn($Check(E,"").FMessage) }
TBase.Check$($Check(b,""),7);
try {
TBase.Check$($Check(b,""),10);
} catch ($e) {
var E$1 = $W($e);
WriteLn($Check(E$1,"").FMessage) }
c = TObject.Create($New(TChild));
WriteLn("TChild");
TBase.Check$($Check(c,""),1);
try {
TBase.Check$($Check(c,""),-1);
} catch ($e) {
var E$2 = $W($e);
WriteLn($Check(E$2,"").FMessage) }
TBase.Check$($Check(c,""),7);
try {
TBase.Check$($Check(c,""),10);
} catch ($e) {
var E$3 = $W($e);
WriteLn($Check(E$3,"").FMessage) }
s = TObject.Create($New(TSubChild));
WriteLn("TSubChild");
TBase.Check$($Check(s,""),1);
try {
TBase.Check$($Check(s,""),-1);
} catch ($e) {
var E$4 = $W($e);
WriteLn($Check(E$4,"").FMessage) }
TBase.Check$($Check(s,""),4);
try {
TBase.Check$($Check(s,""),7);
} catch ($e) {
var E$5 = $W($e);
WriteLn($Check(E$5,"").FMessage) }
try {
TBase.Check$($Check(s,""),10);
} catch ($e) {
var E$6 = $W($e);
WriteLn($Check(E$6,"").FMessage) }