/red-system/tests/source/units/byte-test.reds
Unknown | 172 lines | 133 code | 39 blank | 0 comment | 0 complexity | e58614f4bbd880a1159a30619bf9bc86 MD5 | raw file
1Red/System [ 2 Title: "Red/System byte! datatype test script" 3 Author: "Nenad Rakocevic" 4 File: %byte-test.reds 5 Rights: "Copyright (C) 2011 Nenad Rakocevic. All rights reserved." 6 License: "BSD-3 - https://github.com/dockimbel/Red/blob/origin/BSD-3-License.txt" 7] 8 9#include %../../../../quick-test/quick-test.reds 10 11~~~start-file~~~ "byte!" 12 13===start-group=== "Byte literals & operators test" 14 --test-- "byte-type-1" 15 --assert #"A" = #"A" 16 17 --test-- "byte-type-2" 18 --assert #"A" <> #"B" 19 20 --test-- "byte-type-3" 21 --assert #"A" < #"B" 22 23 --test-- "byte-operator-1" 24 bo1-c: #"^(10)" 25 bo1-res: -1 26 either (as byte! 17) < bo1-c [bo1-res: 1][bo1-res: 0] 27 --assert bo1-res = 0 28 29 --test-- "byte-operator-2" 30 bo1-c: #"^(10)" 31 either 17 < as integer! bo1-c [bo1-res: 1][bo1-res: 0] 32 --assert bo1-res = 0 33 34 --test-- "byte-operator-3" 35 bo1-c: #"^(10)" 36 bol-res: 0 37 if (as byte! 17) < bo1-c [bo1-res: 1] 38 --assert bo1-res = 0 39 40 --test-- "byte-operator-4" 41 bo1-c: #"^(10)" 42 bol-res: 0 43 if 17 < as integer! bo1-c [bo1-res: 1] 44 --assert bo1-res = 0 45 46 --test-- "byte-operator-5" 47 bo1-c: #"^(10)" 48 --assert not ((as byte! 17) < bo1-c) 49 50 --test-- "byte-operator-6" 51 bo1-c: #"^(10)" 52 --assert not (17 < as integer! bo1-c) 53 54 --test-- "byte-operator-7" 55 --assert not #"^(E1)" < as byte! 0 56 57===end-group=== 58 59===start-group=== "Byte literals assignment" 60 --test-- "byte-type-4" 61 t: #"^(C6)" 62 --assert t = #"^(C6)" 63 64 --test-- "byte-type-5" 65 u: #"^(C6)" 66 --assert t = u 67===end-group=== 68 69===start-group=== "Math operations" 70 71 --test-- "byte-type-6" 72 bt-b: #"A" 73 bt-a: bt-b + 1 74 --assert bt-a = #"B" 75 76 --test-- "byte-type-7" 77 bt-aa: t / 3 78 --assert bt-aa = #"B" 79 80===end-group=== 81 82===start-group=== "Passing byte! as argument and returning a byte!" 83 bt-foo: func [v [byte!] return: [byte!]][v] 84 85 --test-- "byte-type-8" 86 bt-b: bt-foo bt-a 87 --assert (bt-b = #"B") 88===end-group=== 89 90===start-group=== "Byte as c-string! element (READ access)" 91 --test-- "byte-read-1" 92 byte-test-str: "Hello World!" 93 br-c: byte-test-str/1 94 --assert br-c = #"H" 95 --assert br-c = byte-test-str/1 96 --assert byte-test-str/1 = br-c 97 98 --test-- "byte-read-2" 99 d: 2 100 br-c: byte-test-str/d 101 --assert br-c = #"e" 102 --assert byte-test-str/1 = #"H" 103 --assert #"H" = bt-foo byte-test-str/1 104 105 --test-- "byte-read-3" 106 br-c: bt-foo byte-test-str/d 107 --assert br-c = #"e" 108===end-group=== 109 110===start-group=== "same tests but with local variables" 111 byte-read: func [/local str [c-string!] c [byte!] d [integer!]][ 112 str: "Hello World!" 113 114 --test-- "byte-read-local-1" 115 c: str/1 116 --assert c = #"H" 117 --assert c = str/1 118 --assert str/1 = c 119 120 --test-- "byte-read-local-2" 121 d: 2 122 c: str/d 123 --assert c = #"e" 124 --assert str/1 = #"H" 125 --assert #"H" = bt-foo str/1 126 127 --test-- "byte-read-local-3" 128 c: bt-foo str/d 129 --assert c = #"e" 130 ] 131 byte-read 132===end-group=== 133 134===start-group=== "Byte as c-string! element (WRITE access)" 135 byte-write-str: "Hello " 136 137 --test-- "byte-write-1" 138 byte-write-str/1: #"y" 139 --assert byte-write-str/1 = #"y" 140 141 --test-- "byte-write-2" 142 c: 6 143 byte-write-str/c: #"w" 144 --assert byte-write-str/c = #"w" 145 --assert byte-write-str/1 = #"y" 146 --assert byte-write-str/2 = #"e" 147 --assert byte-write-str/3 = #"l" 148 --assert byte-write-str/4 = #"l" 149 --assert byte-write-str/5 = #"o" 150 --assert byte-write-str/6 = #"w" 151 --assert 6 = length? byte-write-str 152 153 154 byte-write: func [/local str [c-string!] c [integer!]][ 155 str: "Hello " 156 157 --test-- "byte-write-3" 158 str/1: #"y" 159 --assert str/1 = #"y" 160 161 --test-- "byte-write-4" 162 c: 6 163 str/c: #"w" 164 --assert str/c = #"w" 165 166 ] 167 byte-write 168 169===end-group=== 170 171~~~end-file~~~ 172