Sorcerer's IsleCode cfPassphrase / files

  1<cfcomponent>
  2<cfscript>
  3
  4	function init()
  5	{
  6		this.Results = [];
  7		this.Messages = [];
  8
  9		variables.Status =
 10			{ Pass : "."
 11			, Fail : "!"
 12			, Skip : "-"
 13			};
 14	}
 15
 16
 17	function start()
 18	{
 19		this.StartTime = getTickCount();
 20	}
 21
 22
 23	function end()
 24	{
 25		return '<br/>#this.Name#: #ArrayToList(this.Results,'')#'
 26			& '<br/>time: #getTickCount()-this.StartTime#ms'
 27			& '<pre>#ArrayToList(this.Messages,'<br/>')#</pre>'
 28			;
 29	}
 30
 31
 32	function assertEqual(a,b,Msg='')
 33	{
 34		if ( len(Arguments.Msg) )
 35			return assertTrue( a eq b , Arguments.Msg );
 36
 37		return assertTrue( a eq b , 'Expected [#a#] to be same as [#b#]' );
 38	}
 39
 40
 41	function assertNotEqual(a,b,Msg='')
 42	{
 43		if ( len(Arguments.Msg) )
 44			return assertFalse( a eq b , Arguments.Msg );
 45
 46		return assertFalse( a eq b , 'Expected [#a#] to differ from [#b#]' );
 47	}
 48
 49
 50	function assertTrue(a,Msg='')
 51	{
 52		if ( not isBoolean(a) )
 53			return fail('Expected boolean, received [#a#]');
 54
 55		if ( not a )
 56		{
 57			if ( len(Arguments.Msg) )
 58				return fail(Arguments.Msg);
 59
 60			return fail('Expected True received [#a#]');
 61		}
 62
 63		return pass();
 64	}
 65
 66
 67	function assertFalse(a,Msg='')
 68	{
 69		if ( not isBoolean(a) )
 70			return fail('Expected boolean, received [#a#]');
 71
 72		if ( a )
 73		{
 74			if ( len(Arguments.Msg) )
 75				return fail(Arguments.Msg);
 76
 77			return fail('Expected False received [#a#]');
 78		}
 79
 80		return pass();
 81	}
 82
 83
 84	function pass()
 85	{
 86		ArrayAppend(this.Results,Status.Pass);
 87		return true;
 88	}
 89
 90
 91	function fail(Msg)
 92	{
 93		if ( len(Arguments.Msg) )
 94			logMessage(Msg);
 95
 96		ArrayAppend(this.Results,Status.Fail);
 97		return false;
 98	}
 99
100
101	function skip(n=1)
102	{
103		ArrayAppend(this.Results,RepeatString(Status.Skip,n));
104		logMessage('Skipped #n# assertions.');
105	}
106
107
108	function logMessage(Msg)
109	{
110		ArrayAppend(this.Messages,Msg);
111	}
112
113
114</cfscript>
115</cfcomponent>