Skip to content

Commit dfcf8e8

Browse files
committed
added tests and test framework
the framework is in development
1 parent 6d69898 commit dfcf8e8

12 files changed

Lines changed: 620 additions & 9 deletions

File tree

tests/Exporter/Exporter.au3

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include-once
2+
;https://github.com/sebastianbergmann/exporter/blob/2.0/src/Exporter.php
3+
4+
Func Au3ExporterExporter_Export($value, $indentation = 0)
5+
Return Au3ExporterExporter_RecursiveExport($value, $indentation)
6+
EndFunc
7+
8+
Func Au3ExporterExporter_RecursiveExport(ByRef $value, $indentation, $processed = Null)
9+
If $value == Null Then Return "null"
10+
11+
If $value == True Then Return "true"
12+
13+
If $value == False Then Return "false"
14+
15+
If IsFloat($value) And Int($value) == $value Then Return StringFormat("%s.0", $value)
16+
17+
If IsPtr($value) Or IsHWnd($value) Then Return StringFormat("resource(%d) of type (%s)", $value, VarGetType($value))
18+
19+
if IsString($value) Then
20+
If StringRegExp("[^\x09-\x0d\x1b\x20-\xff]", $value) Then Return "Binary String: 0x" & $value ;https://github.com/sebastianbergmann/exporter/blob/2.0/src/Exporter.php#L235
21+
22+
Return "'" & StringRegExpReplace($value, "(\r\n|\n\r|\r)", @CRLF) & "'"
23+
EndIf
24+
25+
Local $whitespace = StringRepeat(" ", 4 * $indentation)
26+
27+
;~ If Not $processed Then $processed = new Context
28+
29+
;Local $key = $processed->contains($value)
30+
If IsArray($value) Then
31+
#cs
32+
If Not $key == False Then Return "Array &" & $key
33+
34+
Local $array = $value
35+
$key = $processed->add($value)
36+
$values = ""
37+
38+
If UBound($array) > 0 Then
39+
Local $k
40+
For $k=0 To UBound($array)-1
41+
Local $v = $array[$k]
42+
$values &= StringFormat("%s %s => %s" & @CRLF, $whitespace, Au3ExporterExporter_RecursiveExport($k, $indentation), Au3ExporterExporter_RecursiveExport($value($k), $indentation + 1, $processed))
43+
Next
44+
Local $values = "\n" & $values & $whitespace
45+
EndIf
46+
Return StringFormat("Array &%s (%s)", $key, $values)
47+
#ce
48+
EndIf
49+
50+
If IsObj($value) Then
51+
#cs
52+
Local $class = get_class($value)
53+
54+
Local $hash = $processed->contains($value)
55+
If $hash Then Return StringFormat("%s Object &%s", $class, $hash)
56+
57+
$hash = $processed->add($value)
58+
$values = ""
59+
$array = $this->toArray($value)
60+
61+
If UBound($array) > 0 Then
62+
Local $k
63+
For $k=0 To UBound($array)-1
64+
Local $v = $array[$k]
65+
$values &= StringFormat("%s %s => %s" & @CRLF, $whitespace, Au3ExporterExporter_RecursiveExport($k, $indentation), Au3ExporterExporter_RecursiveExport($v, $indentation + 1, $processed))
66+
Next
67+
$values = @CRLF & $value & $whitespace
68+
EndIf
69+
Return StringFormat("%s Object &%s (%s)", $class, $hash, $values)
70+
#ce
71+
EndIf
72+
73+
;Return var_export($value)
74+
$return = String($value)
75+
Return $return?$return:VarGetType($value)
76+
EndFunc
77+
78+
Func StringRepeat($sChar, $nCount); https://www.autoitscript.com/forum/topic/140190-stringrepeat-very-fast-using-memset/
79+
$tBuffer = DLLStructCreate("char[" & $nCount & "]")
80+
DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DLLStructGetPtr($tBuffer), "int", Asc($sChar), "int", $nCount)
81+
Return DLLStructGetData($tBuffer, 1)
82+
EndFunc
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Global Const $Au3UnitConstraintCount = 1 ;https://github.com/sebastianbergmann/phpunit/blob/7.2/src/Framework/Constraint/Constraint.php#L72
2+
3+
Func Au3UnitConstraintConstraint_Evaluate($constraint, $other, $description = "", $returnResult = false, $line = Null, $passedToContraint = Null)
4+
Local $success = False
5+
6+
Local $matches = Call("Au3UnitConstraint" & $constraint & "_Matches", $other, $passedToContraint)
7+
If @error = 0xDEAD And @extended = 0xBEEF Then $matches = Call("Au3UnitConstraint" & $constraint & "_Matches", $other)
8+
If @error = 0xDEAD And @extended = 0xBEEF Then $matches = Call("Au3UnitConstraintConstraint_Matches", $other)
9+
If $matches Then $success = True
10+
11+
If $returnResult Then Return $success
12+
13+
If Not $success Then
14+
Call("Au3UnitConstraint" & $constraint & "_Fail", $other, $description, Null, $line)
15+
If @error = 0xDEAD And @extended = 0xBEEF Then Call("Au3UnitConstraintConstraint_Fail", $constraint, $other, $description, Null, $line, $passedToContraint)
16+
If @error = 0xDEAD And @extended = 0xBEEF Then Exit MsgBox(0, "Au3Unit", "Au3UnitConstraintConstraint_Fail function is missing"&@CRLF&"Exitting") + 1
17+
Return SetError(@error)
18+
EndIf
19+
EndFunc
20+
21+
Func Au3UnitConstraintConstraint_Fail($constraint, $other, $description, $comparisonFailure = Null, $line = Null, $passedToContraint = Null)
22+
Local $failureDescription = Call("Au3UnitConstraint" & $constraint & "_FailureDescription", $other, $passedToContraint)
23+
If @error = 0xDEAD And @extended = 0xBEEF Then $failureDescription = Call("Au3UnitConstraint" & $constraint & "_FailureDescription", $other)
24+
If @error = 0xDEAD And @extended = 0xBEEF Then $failureDescription = Call("Au3UnitConstraintConstraint_FailureDescription", $constraint, $other, $passedToContraint)
25+
$failureDescription = StringFormat("Failed asserting that %s.", $failureDescription)
26+
27+
Local $additionalFailureDescription = Call("Au3UnitConstraint" & $constraint & "_AdditionalFailureDescription", $other)
28+
If @error = 0xDEAD And @extended = 0xBEEF Then $additionalFailureDescription = Call("Au3UnitConstraintConstraint_AdditionalFailureDescription", $other)
29+
30+
If $additionalFailureDescription Then $failureDescription &= @CRLF & $additionalFailureDescription
31+
32+
If Not ($description = "") Then $failureDescription = $description & @CRLF & $failureDescription
33+
34+
ConsoleWriteError($failureDescription&@CRLF&@ScriptFullPath&":"&$line&@CRLF)
35+
Return SetError(1)
36+
EndFunc
37+
38+
Func Au3UnitConstraintConstraint_Matches($other)
39+
Return False
40+
EndFunc
41+
42+
#include "..\..\Exporter\Exporter.au3"
43+
Func Au3UnitConstraintConstraint_FailureDescription($constraint, $other, $passedToContraint = Null)
44+
Local $toString = Call("Au3UnitConstraint" & $constraint & "_ToString", $other)
45+
If @error = 0xDEAD And @extended = 0xBEEF Then $toString = Call("Au3UnitConstraintConstraint_ToString", $other)
46+
Return Au3ExporterExporter_Export(@NumParams=3?$passedToContraint:$other) & " " & $toString
47+
EndFunc
48+
49+
Func Au3UnitConstraintConstraint_AdditionalFailureDescription($other)
50+
Return ""
51+
EndFunc
52+
53+
Func Au3UnitConstraintConstraint_ToString()
54+
Return ""
55+
EndFunc

tests/Unit/Constraint/IsEqual.au3

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include-once
2+
;https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Constraint/IsEqual.php
3+
;shallow implementation
4+
5+
Func Au3UnitConstraintIsEqual_Matches($other, $exspected)
6+
If Not (VarGetType($other) == VarGetType($exspected)) Then Return False
7+
If IsString($other) Then Return $exspected == $other
8+
If IsArray($other) Then
9+
;Return UBound($other, 0) = UBound($exspected, 0)
10+
11+
Local $count = 0
12+
Local $i
13+
Local $index[UBound($other, 0)]
14+
Local $val
15+
For $i = 0 To UBound($index)-1
16+
$index[$i] = 0
17+
Next
18+
19+
While 1
20+
$val1 = Execute(StringFormat("$other[%s]", _ArrayToString($index, "][")))
21+
If @error <> 0 Then Return False
22+
$val2 = Execute(StringFormat("$exspected[%s]", _ArrayToString($index, "][")))
23+
If @error <> 0 Then Return False
24+
If Not Au3UnitConstraintIsEqual_Matches($val1, $val2) Then Return False
25+
26+
Local $innerIndex = UBound($index, 1)
27+
While 1
28+
$innerIndex-=1
29+
If $innerIndex < 0 Then ExitLoop
30+
$index[$innerIndex] += 1
31+
If Not ($index[$innerIndex] >= UBound($other, $innerIndex + 1)) Then
32+
ExitLoop
33+
EndIf
34+
If $innerIndex = 0 And $index[$innerIndex] = UBound($other, 1) Then ExitLoop 2
35+
$index[$innerIndex] = 0
36+
WEnd
37+
38+
$count += 1
39+
WEnd
40+
41+
Return True
42+
EndIf
43+
Return $other = $exspected
44+
EndFunc
45+
46+
Func Au3UnitConstraintIsEqual_ToString($a)
47+
Return StringFormat("is equal to %s", $a)
48+
EndFunc
49+
#cs
50+
#include <Array.au3>
51+
52+
Dim $aArray[3][1][2] = [[['a','a1']],[['b','b1']],[['c','c1']]]
53+
54+
$count = 0
55+
Dim $index[UBound($aArray, 0)]
56+
For $i = 0 To UBound($index)-1
57+
$index[$i] = 0
58+
Next
59+
60+
While 1
61+
ConsoleWrite($index[0])
62+
63+
$val = Execute(StringFormat("$aArray[%s]", _ArrayToString($index, "][")))
64+
ConsoleWrite(StringFormat('index: [%s] = %s', _ArrayToString($index, "]["), $val)&@CRLF)
65+
66+
$innerIndex = UBound($index, 1)
67+
While 1
68+
$innerIndex-=1
69+
If $innerIndex < 0 Then ExitLoop
70+
$index[$innerIndex] += 1
71+
If Not ($index[$innerIndex] >= UBound($aArray, $innerIndex + 1)) Then
72+
ExitLoop
73+
EndIf
74+
If $innerIndex = 0 And $index[$innerIndex] = UBound($aArray, 1) Then ExitLoop 2
75+
$index[$innerIndex] = 0
76+
WEnd
77+
78+
$count += 1
79+
WEnd
80+
#ce

tests/Unit/Constraint/IsFalse.au3

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include-once
2+
3+
Func Au3UnitConstraintIsFalse_Matches($other, $a)
4+
Return $other==False
5+
EndFunc
6+
7+
Func Au3UnitConstraintIsFalse_ToString($value)
8+
Return "is false"
9+
EndFunc
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include-once
2+
;https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Constraint/IsIdentical.php
3+
4+
Func Au3UnitConstraintIsIdentical_Evaluate($other, $description = "", $returnResult = false, $line = Null, $exspected = Null)
5+
Local $success = $exspected == $other
6+
7+
If $returnResult Then Return $success
8+
9+
If Not $success Then
10+
;~ Local $f = Null
11+
12+
;FIXME: look into implementing some of the original functionallity, @see https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Constraint/IsIdentical.php#L84-L102
13+
Call("Au3UnitConstraintIsIdentical_Fail", $other, $description, Null, $line, $exspected)
14+
If @error = 0xDEAD And @extended = 0xBEEF Then Call("Au3UnitConstraintConstraint_Fail", "IsIdentical", $other, $description, Null, $line)
15+
If @error = 0xDEAD And @extended = 0xBEEF Then Exit MsgBox(0, "Au3Unit", "Au3UnitConstraintConstraint_Fail function is missing"&@CRLF&"Exitting") + 1
16+
Return SetError(@error)
17+
EndIf
18+
EndFunc
19+
20+
Func Au3UnitConstraintIsIdentical_Fail($other, $description, $comparisonFailure, $line, $exspected)
21+
Local $failureDescription = Call("Au3UnitConstraintIsIdentical_FailureDescription", $other, $exspected)
22+
If @error = 0xDEAD And @extended = 0xBEEF Then $failureDescription = Call("Au3UnitConstraintConstraint_FailureDescription", "IsIdentical", $other)
23+
$failureDescription = StringFormat("Failed asserting that %s.", $failureDescription)
24+
25+
Local $additionalFailureDescription = Call("Au3UnitConstraintIsIdentical_AdditionalFailureDescription", $other)
26+
If @error = 0xDEAD And @extended = 0xBEEF Then $additionalFailureDescription = Call("Au3UnitConstraintConstraint_AdditionalFailureDescription", $other)
27+
28+
If $additionalFailureDescription Then $failureDescription &= @CRLF & $additionalFailureDescription
29+
30+
If Not ($description = "") Then $failureDescription = $description & @CRLF & $failureDescription
31+
32+
ConsoleWriteError($failureDescription&@CRLF&@ScriptFullPath&":"&$line&@CRLF)
33+
Return SetError(1)
34+
EndFunc
35+
36+
Func Au3UnitConstraintIsIdentical_FailureDescription($other, $exspected)
37+
Local $toString = Call("Au3UnitConstraintIsIdentical_ToString", $exspected)
38+
If @error = 0xDEAD And @extended = 0xBEEF Then $toString = Call("Au3UnitConstraintConstraint_ToString", $other)
39+
Return Au3ExporterExporter_Export($other) & " " & $toString
40+
EndFunc
41+
42+
Func Au3UnitConstraintIsIdentical_ToString($value)
43+
;If IsObj($value);TODO: https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Constraint/IsIdentical.php#L115
44+
45+
Return 'is identical to ' & Au3ExporterExporter_Export($value)
46+
EndFunc

tests/Unit/Constraint/IsNull.au3

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include-once
2+
3+
Func Au3UnitConstraintIsNull_Matches($other)
4+
return $other == Null
5+
EndFunc
6+
7+
Func Au3UnitConstraintIsNull_ToString($other)
8+
Return "is null"
9+
EndFunc

tests/Unit/Constraint/IsTrue.au3

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include-once
2+
3+
Func Au3UnitConstraintIsTrue_Matches($other, $a)
4+
Return $other==True
5+
EndFunc
6+
7+
Func Au3UnitConstraintIsTrue_ToString($value)
8+
Return "is true"
9+
EndFunc

tests/Unit/Constraint/IsType.au3

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Func Au3UnitConstraintIsType_ToString($value)
2+
Return StringFormat('is of type "%s"', $value)
3+
EndFunc
4+
5+
Func Au3UnitConstraintIsType_FailureDescription($constraint, $other, $exspected)
6+
Local $toString = Call("Au3UnitConstraint" & $constraint & "_ToString", $other)
7+
If @error = 0xDEAD And @extended = 0xBEEF Then $toString = Call("Au3UnitConstraintConstraint_ToString", $other)
8+
Return Au3ExporterExporter_Export($exspected) & " " & $toString
9+
EndFunc
10+
11+
Func Au3UnitConstraintIsType_Matches($other, $value)
12+
Return VarGetType($value) == $other
13+
EndFunc

0 commit comments

Comments
 (0)