From b40ad7c83f29d0f6628c2ba6a82b66be2885fdaa Mon Sep 17 00:00:00 2001 From: eulerkochy Date: Sun, 7 Jul 2019 21:13:34 +0530 Subject: [PATCH] save a byteptr memory, add tests --- vlib/builtin/string.v | 2 +- vlib/builtin/string_test.v | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index a5c04759ee..c465e451ef 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -769,7 +769,7 @@ pub fn (s []string) join_lines() string { pub fn (s string) reverse() string { mut res := string { len: s.len - str: malloc(s.len + 1) + str: malloc(s.len) } for i := s.len - 1; i >= 0; i-- { diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 3c142ebc07..d112e0db49 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -293,3 +293,9 @@ fn test_all_after() { assert q == 'hello' } +fn test_reverse() { + s := 'hello' + assert s.reverse() == 'olleh' + t := '' + assert t.reverse() == t +}