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-26 20:45:18 +02:00
|
|
|
Public Sub Assert()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(1)
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.Ok(True, "Testing True")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-26 20:45:18 +02:00
|
|
|
Public Sub AssertEmpty()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(2)
|
2019-11-15 22:33:54 +01:00
|
|
|
Assert.Null("", "Empty with \"\"")
|
|
|
|
Assert.Null(Null, "Empty with Null")
|
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-26 20:45:18 +02:00
|
|
|
Public Sub AssertEqualsFloat()
|
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-26 20:45:18 +02:00
|
|
|
Public Sub AssertEqualsLong()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Dim l As Long
|
|
|
|
|
|
|
|
l = 555555555555555555
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(1)
|
2020-05-12 00:49:33 +02:00
|
|
|
Assert.Equals(555555555555555555, l, "Check long")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-26 20:45:18 +02:00
|
|
|
Public Sub AssertEqualsDate()
|
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)
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(1)
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.Equals(d, d2, "Check with equal dates")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-26 20:45:18 +02:00
|
|
|
Public Sub AssertEqualsObject()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Dim s As New TestCase("1", Me)
|
|
|
|
Dim s2 As Object
|
|
|
|
|
|
|
|
s2 = s
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(1)
|
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-26 20:45:18 +02:00
|
|
|
Public Sub AssertEqualsString()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Dim s1, s2 As String
|
|
|
|
|
|
|
|
s1 = "blaahhh"
|
|
|
|
s2 = "blaahhh"
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(1)
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.StringEquals(s1, s2, "Equal Strings")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-26 20:45:18 +02:00
|
|
|
Public Sub AssertNotNull()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(2)
|
2019-11-15 22:33:54 +01:00
|
|
|
Assert.NotNull("" & Null & 1, "String is not Null")
|
|
|
|
Assert.NotNull(Me, "Object is not Null")
|
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-26 20:45:18 +02:00
|
|
|
Public Sub AssertError()
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
Dim r As Float
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(1)
|
2019-11-15 22:33:54 +01:00
|
|
|
Try r = 2 / 0
|
2020-05-23 11:52:32 +02:00
|
|
|
|
2019-12-30 22:10:37 +01:00
|
|
|
Assert.Error("Test error")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-26 20:45:18 +02:00
|
|
|
Public Sub AssertErrorCode()
|
2019-12-30 22:10:37 +01:00
|
|
|
|
|
|
|
Dim r As Float
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(1)
|
2019-12-30 22:10:37 +01:00
|
|
|
Try r = 2 / 0
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.ErrorCode(26, "Test error with code")
|
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-05-26 20:45:18 +02:00
|
|
|
Public Sub TodoErrorCode()
|
2020-02-24 17:59:14 +01:00
|
|
|
|
|
|
|
Dim r As Float
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(2)
|
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Try r = 2 / 1
|
2020-05-28 09:30:15 +02:00
|
|
|
Test.Todo("See automatic diagnostics 1/2")
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.ErrorCode(26, "Division by zero?")
|
|
|
|
|
|
|
|
Try r = 2 / 0
|
2020-05-28 09:30:15 +02:00
|
|
|
Test.Todo("See automatic diagnostics 2/2")
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.ErrorCode(25, "Division by zero?")
|
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-26 20:45:18 +02:00
|
|
|
Public Sub Note()
|
2020-02-01 23:54:01 +01:00
|
|
|
|
2020-05-23 11:52:32 +02:00
|
|
|
Test.Plan(0)
|
2020-04-27 12:01:47 +02:00
|
|
|
Test.Note("The next note is Null and that's alright:")
|
|
|
|
Test.Note(Null)
|
|
|
|
Test.SkipAll("This doesn't actually assert anything")
|
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-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
|