string_test: fix randomly failed test

* memory should be initialized with zeros before creating string
* there is no string([]array) constructor, string(byteptr) does not count length correctly, using string(byteptr, len) to fix
pull/1444/head
Vitaly Takmazov 2019-08-02 10:20:59 +03:00 committed by Alexander Medvednikov
parent ed3f1d315b
commit 910f350a26
1 changed files with 2 additions and 2 deletions

View File

@ -327,7 +327,7 @@ fn test_interpolation() {
}
fn test_bytes_to_string() {
mut buf := malloc(10)
mut buf := calloc(10)
buf[0] = `h`
buf[1] = `e`
buf[2] = `l`
@ -336,5 +336,5 @@ fn test_bytes_to_string() {
assert string(buf) == 'hello'
assert string(buf, 2) == 'he'
bytes := [`h`, `e`, `l`, `l`, `o`]
assert string(bytes) == 'hello'
assert string(bytes, 5) == 'hello'
}