/red-system/tests/source/units/length-test.reds

http://github.com/dockimbel/Red · Redscript · 82 lines · 62 code · 20 blank · 0 comment · 2 complexity · abece5d3278b1f2992d1e89d7cfd2bc2 MD5 · raw file

  1. Red/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. #include %../../../../quick-test/quick-test.reds
  9. ~~~start-file~~~ "length?"
  10. ===start-group=== "Simple length? tests"
  11. --test-- "length?-1"
  12. --assert 1 = length? "1"
  13. --test-- "length?-2"
  14. l?2-s: "123"
  15. --assert 3 = length? l?2-s
  16. --test-- "length?-3"
  17. l?3-s: "1^(0A)3"
  18. --assert 3 = length? l?3-s
  19. --test-- "length?-4"
  20. --assert 3 = length? "1^(0A)3"
  21. --test-- "length?-5"
  22. l?5-s: "1234567890"
  23. l?5-s/6: null-byte
  24. --assert 5 = length? l?5-s
  25. --test-- "length?-6"
  26. l?6-s: "1234567890"
  27. l?6-s/6: null-byte
  28. l?6-s/6: #"6"
  29. --assert 10 = length? l?6-s
  30. ===end-group===
  31. ===start-group=== "Chaining function calls"
  32. --test-- "len-chain-1"
  33. lc1-func: func [
  34. s [c-string!]
  35. return: [c-string!]
  36. ][
  37. s
  38. ]
  39. --assert 5 = length? lc1-func "Peter"
  40. --test-- "len-chain-2"
  41. lc2-func: func [
  42. s [c-string!]
  43. return: [c-string!]
  44. ][
  45. s
  46. ]
  47. --assert 5 = length? lc1-func lc1-func "Nenad"
  48. ===end-group===
  49. ===start-group=== "Allocated strings"
  50. --test-- "len-alloc-1"
  51. la1-s1: make-c-string 128
  52. la1-s1/128: null-byte
  53. --assert 128 > length? la1-s1
  54. --test-- "len-alloc-2"
  55. la2-s1: make-c-string 128
  56. la2-s1/1: null-byte
  57. --assert 0 = length? la2-s1
  58. --test-- "len-alloc-3"
  59. la2-s1: make-c-string 128
  60. la2-s1: "Nenad"
  61. --assert 5 = length? la2-s1
  62. ~~~end-file~~~