2020-02-23 12:38:53 +01:00
|
|
|
' Gambas test file
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-02-10 13:58:51 +01:00
|
|
|
''' Tests all Asserts
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
Public Sub Approximate()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Dim f As Float
|
|
|
|
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(1)
|
2019-11-15 22:33:54 +01:00
|
|
|
f = 0.55555555555555
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.Approximate(f, 0.55555555555555, 0, "Check with equal floats")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
Public Sub Equals()
|
|
|
|
|
|
|
|
Test.Plan(3)
|
|
|
|
|
|
|
|
' ------------------------------------------------- Long
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Dim l As Long
|
|
|
|
|
|
|
|
l = 555555555555555555
|
2020-05-12 00:49:33 +02:00
|
|
|
Assert.Equals(555555555555555555, l, "Check long")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
' ------------------------------------------------- Date
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Dim d As Date
|
2019-12-30 22:10:37 +01:00
|
|
|
Dim sdate As String
|
2019-11-15 22:33:54 +01:00
|
|
|
Dim d2 As Date
|
|
|
|
|
|
|
|
d = Now()
|
2019-12-30 22:10:37 +01:00
|
|
|
sdate = CString(d)
|
|
|
|
d2 = CDate(sdate)
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
Assert.Equals(d, d2, "Check with equal dates")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
' ------------------------------------------------- Object
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Dim s As New TestCase("1", Me)
|
|
|
|
Dim s2 As Object
|
|
|
|
|
|
|
|
s2 = s
|
2020-05-28 11:14:58 +02:00
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.Equals(s2, s, "Equal Objects")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
2020-02-23 12:38:53 +01:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
Public Sub Error()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
Dim r As Float
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(1)
|
2020-05-28 11:14:58 +02:00
|
|
|
Try r = 2 / 0
|
|
|
|
|
|
|
|
Assert.Error("Test error")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
Public Sub ErrorCode()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
Dim r As Float
|
|
|
|
|
|
|
|
Test.Plan(1)
|
|
|
|
Try r = 2 / 0
|
|
|
|
Assert.ErrorCode(26, "Test error with code")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
Public Sub Fail()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(1)
|
2020-05-28 11:14:58 +02:00
|
|
|
Test.IntendedFailure()
|
|
|
|
Assert.Fail()
|
2020-05-23 11:52:32 +02:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
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)
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
Public Sub GreaterEqual()
|
2019-12-30 22:10:37 +01:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
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)
|
2020-02-24 17:59:14 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
Public Sub IsType()
|
2020-02-24 17:59:14 +01:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
Dim thing As Variant
|
2020-05-23 11:52:32 +02:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
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)
|
2020-02-24 17:59:14 +01:00
|
|
|
|
2019-12-30 22:10:37 +01:00
|
|
|
|
2020-01-24 10:10:39 +01:00
|
|
|
End
|
2020-02-01 23:54:01 +01:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
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)
|
2020-02-01 23:54:01 +01:00
|
|
|
|
2020-05-28 11:14:58 +02:00
|
|
|
' ------------------------------------------------- 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)
|
2020-02-01 23:54:01 +01:00
|
|
|
|
2020-02-10 13:58:51 +01:00
|
|
|
End
|
2020-05-02 17:22:58 +02:00
|
|
|
|
2020-05-26 20:45:18 +02:00
|
|
|
Public Sub Like()
|
2020-05-28 11:14:58 +02:00
|
|
|
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(2)
|
2020-05-02 17:22:58 +02:00
|
|
|
Assert.Like("Gambas", "G*", "Gambas like G*")
|
|
|
|
Assert.Like("Gambas", "?[Aa]*", "Gambas Like \"?[Aa]*\"")
|
|
|
|
|
2020-05-11 23:28:42 +02:00
|
|
|
End
|
2020-05-28 11:14:58 +02:00
|
|
|
|
|
|
|
Public Sub Match()
|
|
|
|
|
|
|
|
Test.Plan(1)
|
|
|
|
Test.Todo()
|
|
|
|
Assert.Match("No idea..", "..how to test this")
|
|
|
|
|
|
|
|
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.Todo
|
|
|
|
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
|