/red-system/tests/source/units/length-test.reds
Unknown | 82 lines | 62 code | 20 blank | 0 comment | 0 complexity | abece5d3278b1f2992d1e89d7cfd2bc2 MD5 | raw file
1Red/System [ 2 Title: "Red/System length? test script" 3 Author: "Peter W A Wood" 4 File: %length-test.reds 5 Rights: "Copyright (C) 2011 Peter W A Wood. 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~~~ "length?" 12 13===start-group=== "Simple length? tests" 14 15 --test-- "length?-1" 16 --assert 1 = length? "1" 17 18 --test-- "length?-2" 19 l?2-s: "123" 20 --assert 3 = length? l?2-s 21 22 --test-- "length?-3" 23 l?3-s: "1^(0A)3" 24 --assert 3 = length? l?3-s 25 26 --test-- "length?-4" 27 --assert 3 = length? "1^(0A)3" 28 29 --test-- "length?-5" 30 l?5-s: "1234567890" 31 l?5-s/6: null-byte 32 --assert 5 = length? l?5-s 33 34 --test-- "length?-6" 35 l?6-s: "1234567890" 36 l?6-s/6: null-byte 37 l?6-s/6: #"6" 38 --assert 10 = length? l?6-s 39 40===end-group=== 41 42===start-group=== "Chaining function calls" 43 44 --test-- "len-chain-1" 45 lc1-func: func [ 46 s [c-string!] 47 return: [c-string!] 48 ][ 49 s 50 ] 51 --assert 5 = length? lc1-func "Peter" 52 53 --test-- "len-chain-2" 54 lc2-func: func [ 55 s [c-string!] 56 return: [c-string!] 57 ][ 58 s 59 ] 60 --assert 5 = length? lc1-func lc1-func "Nenad" 61 62===end-group=== 63 64===start-group=== "Allocated strings" 65 66 --test-- "len-alloc-1" 67 la1-s1: make-c-string 128 68 la1-s1/128: null-byte 69 --assert 128 > length? la1-s1 70 71 --test-- "len-alloc-2" 72 la2-s1: make-c-string 128 73 la2-s1/1: null-byte 74 --assert 0 = length? la2-s1 75 76 --test-- "len-alloc-3" 77 la2-s1: make-c-string 128 78 la2-s1: "Nenad" 79 --assert 5 = length? la2-s1 80 81~~~end-file~~~ 82