Skip to content

Commit aa7861d

Browse files
authored
Fix the return type of 'jerry_string_substr'. (jerryscript-project#5185)
Also added new unit test to test basic functionality of 'jerry_string_substr'. JerryScript-DCO-1.0-Signed-off-by: Laszlo Lango [email protected]
1 parent c509a06 commit aa7861d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

jerry-core/include/jerryscript-core.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ void *jerry_string_user_ptr (const jerry_value_t value, bool *is_external);
450450
* @defgroup jerry-api-string-op Operations
451451
* @{
452452
*/
453-
jerry_size_t jerry_string_substr (const jerry_value_t value, jerry_length_t start, jerry_length_t end);
453+
jerry_value_t jerry_string_substr (const jerry_value_t value, jerry_length_t start, jerry_length_t end);
454454
jerry_size_t jerry_string_to_buffer (const jerry_value_t value,
455455
jerry_encoding_t encoding,
456456
jerry_char_t *buffer_p,

tests/unit-core/test-api-strings.c

+16
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,22 @@ main (void)
159159
jerry_value_free (test_str);
160160
}
161161

162+
/* Test jerry_string_substr */
163+
{
164+
jerry_value_t test_str = jerry_string_sz ("Hello World!");
165+
jerry_value_t expected_str = jerry_string_sz ("Hello");
166+
167+
// Read the string into a byte buffer.
168+
jerry_value_t sub_str = jerry_string_substr (test_str, 0, 5);
169+
170+
TEST_ASSERT (!strict_equals (sub_str, test_str));
171+
TEST_ASSERT (strict_equals (sub_str, expected_str));
172+
173+
jerry_value_free (sub_str);
174+
jerry_value_free (expected_str);
175+
jerry_value_free (test_str);
176+
}
177+
162178
jerry_cleanup ();
163179

164180
return 0;

0 commit comments

Comments
 (0)