gambas-source-code/main/lib/test/gb.test/.src/TestMyself/TAllAsserts.test
Tobias Boege efdc072276 gb.test: document and fix Todo tests
[GB.TEST]
* NEW: Add tests for Assert.Match.
* BUG: Assert: document Approximate and RelativeApproximate.
* BUG: Special-case Expected = 0 in RelativeApproximate.
2020-06-01 06:57:45 +02:00

368 lines
7.4 KiB
Text

' Gambas test file
''' Tests all Asserts
Public Sub Approximate()
Dim f As Float
Test.Plan(1)
f = 0.55555555555555
Assert.Approximate(f, 0.55555555555555, 0, "Check with equal floats")
End
Public Sub Equals()
Test.Plan(3)
' ------------------------------------------------- Long
Dim l As Long
l = 555555555555555555
Assert.Equals(555555555555555555, l, "Check long")
' ------------------------------------------------- Date
Dim d As Date
Dim sdate As String
Dim d2 As Date
d = Now()
sdate = CString(d)
d2 = CDate(sdate)
Assert.Equals(d, d2, "Check with equal dates")
' ------------------------------------------------- Object
Dim s As New TestCase("1", Me)
Dim s2 As Object
s2 = s
Assert.Equals(s2, s, "Equal Objects")
End
Public Sub Error()
Dim r As Float
Test.Plan(1)
Try r = 2 / 0
Assert.Error("Test error")
End
Public Sub ErrorCode()
Dim r As Float
Test.Plan(1)
Try r = 2 / 0
Assert.ErrorCode(26, "Test error with code")
End
Public Sub Fail()
Test.Plan(1)
Test.IntendedFailure()
Assert.Fail()
End
Public Sub Greater()
Dim small, great As Variant
Test.Plan(4)
' ------------------------------------------------- String
small = "a"
great = "z"
Assert.Greater(great, small)
' ------------------------------------------------- Integer
small = -1
great = 0
Assert.Greater(great, small)
' ------------------------------------------------- Float
small = 0.1
great = 10000000000000000.5
Assert.Greater(great, small)
' ------------------------------------------------- Date
small = Date(Year(Now), Month(Now), Day(Now))
great = Date(Year(Now) + 1, Month(Now), Day(Now))
Assert.Greater(great, small)
End
Public Sub GreaterEqual()
Dim small, great As Variant
Test.Plan(8)
' ------------------------------------------------- String
small = "a"
great = "z"
Assert.GreaterEqual(great, small)
Assert.GreaterEqual(great, great)
' ------------------------------------------------- Integer
small = -1
great = 0
Assert.GreaterEqual(great, small)
Assert.GreaterEqual(great, great)
' ------------------------------------------------- Float
small = 0.1
great = 10000000000000000.5
Assert.GreaterEqual(great, small)
Assert.GreaterEqual(great, great)
' ------------------------------------------------- Date
small = Date(Year(Now), Month(Now), Day(Now))
great = Date(Year(Now) + 1, Month(Now), Day(Now))
Assert.GreaterEqual(great, small)
Assert.GreaterEqual(great, great)
End
Public Sub IsType()
Dim thing As Variant
Test.Plan(7)
' ------------------------------------------------- Boolean
thing = True
Assert.IsType(thing, gb.Boolean)
' ------------------------------------------------- Integer
thing = 456548812
Assert.IsType(thing, gb.Integer)
thing = 4565488121245
Assert.IsType(thing, gb.Long)
' ------------------------------------------------- Float
thing = 456548812124513564879.123456789134698797987987
Assert.IsType(thing, gb.Float)
' ------------------------------------------------- string
thing = "i bi a sdring"
Assert.IsType(thing, gb.String)
' ------------------------------------------------- Date
thing = Now()
Assert.IsType(thing, gb.Date)
' ------------------------------------------------- Object
thing = Class.Load("TAllAsserts")
Assert.IsType(thing, gb.Object)
End
Public Sub Less()
Dim small, great As Variant
Test.Plan(4)
' ------------------------------------------------- String
small = "a"
great = "z"
Assert.Less(small, great)
' ------------------------------------------------- Integer
small = -1
great = 0
Assert.Less(small, great)
' ------------------------------------------------- Long
small = 0.1
great = 1
Assert.Less(small, great)
' ------------------------------------------------- Date
small = Date(Year(Now), Month(Now), Day(Now))
great = Date(Year(Now) + 1, Month(Now), Day(Now))
Assert.Less(small, great)
End
Public Sub LessEqual()
Dim small, great As Variant
Test.Plan(8)
' ------------------------------------------------- String
small = "a"
great = "z"
Assert.LessEqual(small, great)
Assert.GreaterEqual(great, great)
' ------------------------------------------------- Integer
small = -1
great = 0
Assert.LessEqual(small, great)
Assert.GreaterEqual(great, great)
' ------------------------------------------------- Float
small = 0.1
great = 10000000000000000.5
Assert.LessEqual(small, great)
Assert.GreaterEqual(great, great)
' ------------------------------------------------- Date
small = Date(Year(Now), Month(Now), Day(Now))
great = Date(Year(Now) + 1, Month(Now), Day(Now))
Assert.LessEqual(small, great)
Assert.GreaterEqual(great, great)
End
Public Sub Like()
Test.Plan(2)
Assert.Like("Gambas", "G*", "Gambas like G*")
Assert.Like("Gambas", "?[Aa]*", "Gambas Like \"?[Aa]*\"")
End
Public Sub Match()
Test.Plan(4)
Assert.Match("25724689346a625b5", "^\\d+a\\d+?(\\d)b\\1$", "Match with a frugal quantifier and backreference")
Assert.Match("25724689346a625b5", "^\\d+a\\d+(\\d)b\\1$", "Match with a normal quantifier (backtracking) and backreference")
Test.IntendedFailure
Assert.Match("25724689346a625b5", "^\\d+a\\d++(\\d)b\\1$", "Non-match with a possessive quantifier and backreference")
Assert.Match(Format$(Now, "yyyy-mm-dd"), "^\\d{4}-\\d{2}-\\d{2}$", "Date pattern match")
End
Public Sub NotNull()
Test.Plan(2)
Assert.NotNull("" & Null & 1, "String is not Null")
Assert.NotNull(Me, "Object is not Null")
End
Public Sub NotOk()
Test.Plan(1)
Assert.NotOk(False)
End
Public Sub Notequals()
Dim small, great As Variant
Test.Plan(5)
' ------------------------------------------------- String
small = "a"
great = "z"
Assert.Notequals(great, small)
' ------------------------------------------------- Integer
small = -1
great = 0
Assert.Notequals(great, small)
' ------------------------------------------------- Float
small = 0.1
great = 10000000000000000.5
Assert.Notequals(great, small)
' ------------------------------------------------- Date
small = Date(Year(Now), Month(Now), Day(Now))
great = Date(Year(Now) + 1, Month(Now), Day(Now))
Assert.Notequals(great, small)
' ------------------------------------------------- Object
Dim s As New TestCase("1", Me)
Dim s2 As New TestCase("2", Me)
Assert.Notequals(s2, s)
End
Public Sub Noterror()
Dim x As Variant
Try x = 2 / 0
Test.Plan(1)
'btw we can test Error.Clear
Error.Clear()
Assert.Noterror()
End
Public Sub Null()
Test.Plan(2)
Assert.Null("", "Empty with \"\"")
Assert.Null(Null, "Empty with Null")
End
Public Sub Ok()
Test.Plan(1)
Assert.Ok(True, "Testing True")
End
Public Sub Pass()
Test.Plan(1)
Assert.Pass("Should report ok")
End
Public Sub RelativeApproximate()
Test.Plan(1)
Assert.RelativeApproximate(0, 0, 0)
End
Public Sub StringEquals()
Dim s1, s2 As String
s1 = "blaahhh"
s2 = "blaahhh"
Test.Plan(1)
Assert.StringEquals(s1, s2, "Equal Strings")
End