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
|
|
|
|
|
|
|
Public Sub TestAssert()
|
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.Ok(True, "Testing True")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
|
|
|
Public Sub TestAssertEmpty()
|
|
|
|
|
|
|
|
Assert.Null("", "Empty with \"\"")
|
|
|
|
Assert.Null(Null, "Empty with Null")
|
|
|
|
|
|
|
|
End
|
|
|
|
|
|
|
|
Public Sub TestAssertEqualsFloat()
|
|
|
|
|
|
|
|
Dim f As Float
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
Public Sub TestAssertEqualsLong()
|
|
|
|
|
|
|
|
Dim l As Long
|
|
|
|
|
|
|
|
l = 555555555555555555
|
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.Equals(555555555555555555, l, "Check with two long")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
|
|
|
Public Sub TestAssertEqualsDate()
|
|
|
|
|
|
|
|
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-02-24 17:59:14 +01:00
|
|
|
Assert.Equals(d, d2, "Check with equal dates")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
|
|
|
Public Sub TestAssertEqualsObject()
|
|
|
|
|
|
|
|
Dim s As New TestCase("1", Me)
|
|
|
|
Dim s2 As Object
|
|
|
|
|
|
|
|
s2 = s
|
|
|
|
|
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
|
|
|
|
2019-11-15 22:33:54 +01:00
|
|
|
Public Sub TestAssertEqualsString()
|
|
|
|
|
|
|
|
Dim s1, s2 As String
|
|
|
|
|
|
|
|
s1 = "blaahhh"
|
|
|
|
s2 = "blaahhh"
|
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Assert.StringEquals(s1, s2, "Equal Strings")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
|
|
|
Public Sub TestAssertNotNull()
|
|
|
|
|
|
|
|
Assert.NotNull("" & Null & 1, "String is not Null")
|
|
|
|
Assert.NotNull(Me, "Object is not Null")
|
|
|
|
|
|
|
|
End
|
|
|
|
|
|
|
|
Public Sub TestAssertError()
|
|
|
|
|
|
|
|
Dim r As Float
|
2020-02-23 12:38:53 +01:00
|
|
|
|
2019-11-15 22:33:54 +01:00
|
|
|
Try r = 2 / 0
|
2019-12-30 22:10:37 +01:00
|
|
|
Assert.Error("Test error")
|
2019-11-15 22:33:54 +01:00
|
|
|
|
|
|
|
End
|
|
|
|
|
2020-02-24 17:59:14 +01:00
|
|
|
Public Sub TestAssertErrorCode()
|
2019-12-30 22:10:37 +01:00
|
|
|
|
|
|
|
Dim r As Float
|
2020-02-23 12:38:53 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
|
Public Sub TestTodoErrorCode()
|
|
|
|
|
|
|
|
Dim r As Float
|
|
|
|
|
|
|
|
Try r = 2 / 1
|
|
|
|
Assert.Todo("See automatic diagnostics 1/2")
|
|
|
|
Assert.ErrorCode(26, "Division by zero?")
|
|
|
|
|
|
|
|
Try r = 2 / 0
|
|
|
|
Assert.Todo("See automatic diagnostics 2/2")
|
|
|
|
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
|
|
|
|
|
|
|
Public Sub TestNote()
|
|
|
|
|
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
|
|
|
|
|
|
|
Public Sub TestLike()
|
|
|
|
|
|
|
|
Assert.Like("Gambas", "G*", "Gambas like G*")
|
|
|
|
Assert.Like("Gambas", "?[Aa]*", "Gambas Like \"?[Aa]*\"")
|
|
|
|
|
2020-05-11 23:28:42 +02:00
|
|
|
End
|