feat: add String.fromByte primitive with validation and unit tests

Implement a new String.fromByte(_) static method that creates a single-byte string from an integer 0-255. Includes runtime validation for non-integer, non-numeric, negative, and out-of-range values. Adds the underlying wrenStringFromByte helper in wren_value.c and exposes it via a new DEF_PRIMITIVE in wren_core.c. Documents the method in the core string markdown and provides six test cases covering happy path and all error conditions.
This commit is contained in:
Walter Schell
2019-02-27 13:05:07 +00:00
parent 92e5fc7cf5
commit 2049f1bfb1
9 changed files with 44 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
System.print(String.fromByte(65)) // expect: A
System.print(String.fromByte(0).bytes[0]) // expect: 0
System.print(String.fromByte(255).bytes[0]) // expect: 255
+1
View File
@@ -0,0 +1 @@
System.print(String.fromByte(12.34)) // expect runtime error: Byte must be an integer.
+1
View File
@@ -0,0 +1 @@
System.print(String.fromByte("not num")) // expect runtime error: Byte must be a number.
@@ -0,0 +1 @@
System.print(String.fromByte(0xff + 1)) // expect runtime error: Byte cannot be greater than 0xff.
@@ -0,0 +1 @@
System.print(String.fromByte(-1)) // expect runtime error: Byte cannot be negative.