Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the return type of 'jerry_string_substr'. #5185

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 test_str = jerry_string_sz ("Hello World!");
LaszloLango marked this conversation as resolved.
Show resolved Hide resolved
jerry_value_t expected_str = jerry_string_sz ("Hello");

// 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
Loading