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

http://github.com/dockimbel/Red · Redscript · 172 lines · 133 code · 39 blank · 0 comment · 3 complexity · e58614f4bbd880a1159a30619bf9bc86 MD5 · raw file

  1. Red/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. #include %../../../../quick-test/quick-test.reds
  9. ~~~start-file~~~ "byte!"
  10. ===start-group=== "Byte literals & operators test"
  11. --test-- "byte-type-1"
  12. --assert #"A" = #"A"
  13. --test-- "byte-type-2"
  14. --assert #"A" <> #"B"
  15. --test-- "byte-type-3"
  16. --assert #"A" < #"B"
  17. --test-- "byte-operator-1"
  18. bo1-c: #"^(10)"
  19. bo1-res: -1
  20. either (as byte! 17) < bo1-c [bo1-res: 1][bo1-res: 0]
  21. --assert bo1-res = 0
  22. --test-- "byte-operator-2"
  23. bo1-c: #"^(10)"
  24. either 17 < as integer! bo1-c [bo1-res: 1][bo1-res: 0]
  25. --assert bo1-res = 0
  26. --test-- "byte-operator-3"
  27. bo1-c: #"^(10)"
  28. bol-res: 0
  29. if (as byte! 17) < bo1-c [bo1-res: 1]
  30. --assert bo1-res = 0
  31. --test-- "byte-operator-4"
  32. bo1-c: #"^(10)"
  33. bol-res: 0
  34. if 17 < as integer! bo1-c [bo1-res: 1]
  35. --assert bo1-res = 0
  36. --test-- "byte-operator-5"
  37. bo1-c: #"^(10)"
  38. --assert not ((as byte! 17) < bo1-c)
  39. --test-- "byte-operator-6"
  40. bo1-c: #"^(10)"
  41. --assert not (17 < as integer! bo1-c)
  42. --test-- "byte-operator-7"
  43. --assert not #"^(E1)" < as byte! 0
  44. ===end-group===
  45. ===start-group=== "Byte literals assignment"
  46. --test-- "byte-type-4"
  47. t: #"^(C6)"
  48. --assert t = #"^(C6)"
  49. --test-- "byte-type-5"
  50. u: #"^(C6)"
  51. --assert t = u
  52. ===end-group===
  53. ===start-group=== "Math operations"
  54. --test-- "byte-type-6"
  55. bt-b: #"A"
  56. bt-a: bt-b + 1
  57. --assert bt-a = #"B"
  58. --test-- "byte-type-7"
  59. bt-aa: t / 3
  60. --assert bt-aa = #"B"
  61. ===end-group===
  62. ===start-group=== "Passing byte! as argument and returning a byte!"
  63. bt-foo: func [v [byte!] return: [byte!]][v]
  64. --test-- "byte-type-8"
  65. bt-b: bt-foo bt-a
  66. --assert (bt-b = #"B")
  67. ===end-group===
  68. ===start-group=== "Byte as c-string! element (READ access)"
  69. --test-- "byte-read-1"
  70. byte-test-str: "Hello World!"
  71. br-c: byte-test-str/1
  72. --assert br-c = #"H"
  73. --assert br-c = byte-test-str/1
  74. --assert byte-test-str/1 = br-c
  75. --test-- "byte-read-2"
  76. d: 2
  77. br-c: byte-test-str/d
  78. --assert br-c = #"e"
  79. --assert byte-test-str/1 = #"H"
  80. --assert #"H" = bt-foo byte-test-str/1
  81. --test-- "byte-read-3"
  82. br-c: bt-foo byte-test-str/d
  83. --assert br-c = #"e"
  84. ===end-group===
  85. ===start-group=== "same tests but with local variables"
  86. byte-read: func [/local str [c-string!] c [byte!] d [integer!]][
  87. str: "Hello World!"
  88. --test-- "byte-read-local-1"
  89. c: str/1
  90. --assert c = #"H"
  91. --assert c = str/1
  92. --assert str/1 = c
  93. --test-- "byte-read-local-2"
  94. d: 2
  95. c: str/d
  96. --assert c = #"e"
  97. --assert str/1 = #"H"
  98. --assert #"H" = bt-foo str/1
  99. --test-- "byte-read-local-3"
  100. c: bt-foo str/d
  101. --assert c = #"e"
  102. ]
  103. byte-read
  104. ===end-group===
  105. ===start-group=== "Byte as c-string! element (WRITE access)"
  106. byte-write-str: "Hello "
  107. --test-- "byte-write-1"
  108. byte-write-str/1: #"y"
  109. --assert byte-write-str/1 = #"y"
  110. --test-- "byte-write-2"
  111. c: 6
  112. byte-write-str/c: #"w"
  113. --assert byte-write-str/c = #"w"
  114. --assert byte-write-str/1 = #"y"
  115. --assert byte-write-str/2 = #"e"
  116. --assert byte-write-str/3 = #"l"
  117. --assert byte-write-str/4 = #"l"
  118. --assert byte-write-str/5 = #"o"
  119. --assert byte-write-str/6 = #"w"
  120. --assert 6 = length? byte-write-str
  121. byte-write: func [/local str [c-string!] c [integer!]][
  122. str: "Hello "
  123. --test-- "byte-write-3"
  124. str/1: #"y"
  125. --assert str/1 = #"y"
  126. --test-- "byte-write-4"
  127. c: 6
  128. str/c: #"w"
  129. --assert str/c = #"w"
  130. ]
  131. byte-write
  132. ===end-group===
  133. ~~~end-file~~~