Created
May 21, 2018 23:22
-
-
Save leoniv/c94bfdcea0a0df279fe2a6db770568d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Var PARSE_RESULT; | |
Var EXCUTE_CONTEXT; | |
function NewSpec(mess, owner) | |
return New Structure("Spec, Owner", mess, owner); | |
endfunction | |
function NewTest(mess, owner) | |
return New Structure("Name, Owner, FullSpecName, FullTestName", mess, owner, FullSpecName(Owner), FullTestName(mess, Owner)); | |
endfunction | |
function EXCUTE_CONTEXT() | |
if EXCUTE_CONTEXT = Undefined then | |
EXCUTE_CONTEXT = New structure("PARSE_RESULT, CurrentTest", Undefined, Undefined); | |
endif; | |
return EXCUTE_CONTEXT; | |
endfunction | |
function PARSE_RESULT() | |
if PARSE_RESULT = Undefined then | |
PARSE_RESULT = New structure("TestCase, Specs, Tests", Undefined, New Array, New Array); | |
endif; | |
return PARSE_RESULT; | |
endfunction | |
function _can_execute_(mess) | |
return EXCUTE_CONTEXT; | |
endfunction | |
function Exec(PARSE_RESULT, TestName) export | |
EXCUTE_CONTEXT().PARSE_RESULT = PARSE_RESULT; | |
for each test in EXCUTE_CONTEXT().PARSE_RESULT.Tests do | |
EXCUTE_CONTEXT().CurrentTest = Test; | |
if TestName = "" OR RegexMatch(Test.FullTestName, TestName) then | |
ЭтотОбъект.GetForm(PARSE_RESULT.TestCase); | |
endif; | |
enddo; | |
return "FIXME"; | |
endfunction | |
function Parse(FormName) export | |
PARSE_RESULT().TestCase = FormName; | |
ЭтотОбъект.GetForm(FormName); | |
return PARSE_RESULT(); | |
endfunction | |
function _parsing_() | |
return ValueIsFilled(PARSE_RESULT); | |
endfunction | |
function _can_execute_before_() | |
return not _parsing_() | |
endfunction | |
function _can_execute_after_() | |
return not _parsing_() | |
endfunction | |
function _can_execute_it_(mess) | |
return Not _parsing_() And EXCUTE_CONTEXT().CurrentTest.Name = mess; | |
endfunction | |
function AddSpec(Spec) | |
PARSE_RESULT().Specs.Add(Spec); | |
endfunction | |
function AddTest(Test) | |
PARSE_RESULT().Tests.Add(Test); | |
endfunction | |
function LastSpec() | |
if PARSE_RESULT().Specs.Count() = 0 then | |
return Undefined; | |
endif; | |
return PARSE_RESULT().Specs[PARSE_RESULT().Specs.Ubound()] | |
endfunction | |
function FullTestName(Name, Val Owner) | |
return FullSpecName(Owner) + "::" + Name; | |
endfunction | |
function FullSpecName(val Owner) | |
r = ""; | |
while Owner <> Undefined do | |
r = Owner.Spec + "::" + r; | |
Owner = Owner.Owner; | |
enddo; | |
return r; | |
endfunction | |
//SPEC DSL | |
function desc(mess) export | |
if _parsing_() then | |
AddSpec(NewSpec(Mess, LastSpec())); | |
endif; | |
return true | |
endfunction | |
function before() export | |
return _can_execute_before_(); | |
endfunction | |
function after() export | |
return _can_execute_after_(); | |
endfunction | |
function it(mess) export | |
if _parsing_() then | |
AddTest(NewTest(Mess, LastSpec())); | |
endif; | |
return _can_execute_it_(mess); | |
endfunction | |
function RegexMatch(str, pattern) | |
return true; | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment