From d3bdadd76b59770c9402db1f2475cf760f8f682b Mon Sep 17 00:00:00 2001 From: Johnny Richard Date: Mon, 18 Apr 2022 00:59:18 +0200 Subject: string_view: Implement string_view_to_cstr --- test/string_view_test.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/string_view_test.c') diff --git a/test/string_view_test.c b/test/string_view_test.c index a050239..7b2400c 100644 --- a/test/string_view_test.c +++ b/test/string_view_test.c @@ -48,6 +48,22 @@ test_from_cstr(const MunitParameter params[], return MUNIT_OK; } +static MunitResult +test_to_cstr(const MunitParameter params[], + void *user_data_or_fixture) +{ + char *cstr = "hello world"; + + string_view_t sv = string_view_new(cstr, 5); + + char actual[sv.size + 1]; + string_view_to_cstr(&sv, actual); + + assert_string_equal(actual, "hello"); + + return MUNIT_OK; +} + static MunitResult test_eq(const MunitParameter params[], void *user_data_or_fixture) @@ -101,6 +117,7 @@ test_chop_by_delim_when_has_no_delim(const MunitParameter params[], static MunitTest tests[] = { { "/test_create_new", test_create_new, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, { "/test_from_cstr", test_from_cstr, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, + { "/test_to_cstr", test_to_cstr, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, { "/test_eq", test_eq, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, { "/test_chop_by_delim_when_has_delim", test_chop_by_delim_when_has_delim, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, { "/test_chop_by_delim_when_has_no_delim", test_chop_by_delim_when_has_no_delim, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, -- cgit v1.2.3