[226] | 1 | '--------------------------------------------------------------------
|
---|
| 2 | ' Test case of String Class
|
---|
| 3 | '--------------------------------------------------------------------
|
---|
| 4 |
|
---|
| 5 | Namespace StringTest
|
---|
| 6 |
|
---|
[230] | 7 | Sub TestMain()
|
---|
[641] | 8 |
|
---|
[226] | 9 | Dim s1 = Nothing As String
|
---|
| 10 |
|
---|
| 11 | s1 = New String("hello")
|
---|
| 12 |
|
---|
[641] | 13 | UnitTest("String.GetType", s1.GetType().Name, "String")
|
---|
[226] | 14 |
|
---|
| 15 |
|
---|
[512] | 16 | UnitTest("String.String (case 0)", (memcmp(s1.StrPtr, "hello", SizeOf (Char) * 6) = 0))
|
---|
[226] | 17 |
|
---|
[641] | 18 | UnitTest("String.String (case 1)", s1, "hello")
|
---|
[226] | 19 |
|
---|
| 20 | Dim nsz[2] = [&h31, &h32, &h33] As SByte
|
---|
| 21 | s1 = New String(nsz, 3)
|
---|
[641] | 22 | UnitTest("String.String (case 2)", s1, "123")
|
---|
[226] | 23 |
|
---|
| 24 | Dim wsz[4] = [&h31, &h32, &h33, &h34, &h35] As WCHAR
|
---|
| 25 | s1 = New String(wsz, 5)
|
---|
[641] | 26 | UnitTest("String.String (case 3)", s1, "12345")
|
---|
[226] | 27 |
|
---|
[512] | 28 | s1 = New String(&h30 As Char, 4)
|
---|
[641] | 29 | UnitTest("String.String (case 4)", s1, "0000")
|
---|
[226] | 30 |
|
---|
| 31 | s1 = "literal"
|
---|
[641] | 32 | UnitTest("String.String (case 5)", s1, "literal")
|
---|
[226] | 33 |
|
---|
| 34 | UnitTest("String.Length", (s1.Length = 7))
|
---|
| 35 |
|
---|
[641] | 36 | UnitTest("String.ToString", s1.ToString(), "literal")
|
---|
| 37 | UnitTest("String.Clone", s1.Clone(), "literal")
|
---|
[226] | 38 |
|
---|
| 39 | UnitTest("String.Operator []", (s1[7] = 0))
|
---|
| 40 |
|
---|
| 41 | s1 = New String("abc")
|
---|
| 42 |
|
---|
| 43 | UnitTest("String.IsNullOrEmpty (case 1)", (String.IsNullOrEmpty(Nothing) = True))
|
---|
| 44 | UnitTest("String.IsNullOrEmpty (case 2)", (String.IsNullOrEmpty("") = True))
|
---|
| 45 | UnitTest("String.IsNullOrEmpty (case 3)", (String.IsNullOrEmpty(s1) = False))
|
---|
| 46 |
|
---|
| 47 | UnitTest("String.Compare (case 1)", (String.Compare("ABC", "ABC") = 0))
|
---|
| 48 | UnitTest("String.Compare (case 2)", (String.Compare("ABD", "ABC") > 0))
|
---|
| 49 | UnitTest("String.Compare (case 3)", (String.Compare("ABC", "ABCD") < 0))
|
---|
| 50 |
|
---|
| 51 | Dim o1 = New Object
|
---|
| 52 | Dim o2 = s1 As Object
|
---|
[641] | 53 | UnitTest("String.Concat", String.Concat(o1, o2), "Objectabc")
|
---|
[226] | 54 |
|
---|
[641] | 55 | UnitTest("String.Operator +", (s1 + "def"), "abcdef")
|
---|
| 56 | UnitTest("String.Operator &", (s1 + "xyz"), "abcxyz")
|
---|
[226] | 57 |
|
---|
| 58 | s1 = "へのへの"
|
---|
| 59 | UnitTest("String.Contains (case 1)", (s1.Contains("のへ") = True))
|
---|
| 60 | UnitTest("String.Contains (case 2)", (s1.Contains("もへ") = False))
|
---|
| 61 |
|
---|
| 62 | ' まだまだ追加求む
|
---|
| 63 |
|
---|
[230] | 64 | End Sub
|
---|
| 65 |
|
---|
[226] | 66 | End Namespace
|
---|
[230] | 67 |
|
---|
| 68 | StringTest.TestMain()
|
---|