Skip to content

Commit

Permalink
Fix the return type of 'jerry_string_substr'.
Browse files Browse the repository at this point in the history
Also added new unit test to test basic functionality of 'jerry_string_substr'.

JerryScript-DCO-1.0-Signed-off-by: Laszlo Lango laszlo.lango@h-lab.eu
  • Loading branch information
LaszloLango committed Dec 10, 2024
1 parent c509a06 commit 2d552fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jerry-core/include/jerryscript-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void *jerry_string_user_ptr (const jerry_value_t value, bool *is_external);
* @defgroup jerry-api-string-op Operations
* @{
*/
jerry_size_t jerry_string_substr (const jerry_value_t value, jerry_length_t start, jerry_length_t end);
jerry_value_t jerry_string_substr (const jerry_value_t value, jerry_length_t start, jerry_length_t end);
jerry_size_t jerry_string_to_buffer (const jerry_value_t value,
jerry_encoding_t encoding,
jerry_char_t *buffer_p,
Expand Down
16 changes: 16 additions & 0 deletions tests/unit-core/test-api-strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ main (void)
jerry_value_free (test_str);
}

/* Test jerry_string_substr */
{
jerry_value_t expected_str = jerry_string_sz ("Hello");
jerry_value_t test_str = jerry_string_sz ("Hello World!");

// Read the string into a byte buffer.
jerry_value_t sub_str = jerry_string_substr (test_str, 0, 5);

TEST_ASSERT (!strict_equals (sub_str, test_str));
TEST_ASSERT (strict_equals (sub_str, expected_str));

jerry_value_free (sub_str);
jerry_value_free (expected_str);
jerry_value_free (test_str);
}

jerry_cleanup ();

return 0;
Expand Down

0 comments on commit 2d552fc

Please sign in to comment.