forked from bytecodealliance/wit-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <assert.h> | ||
#include <strings_cpp.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
void assert_str(std::string_view str, const char* expected) { | ||
size_t expected_len = strlen(expected); | ||
assert(str.size() == expected_len); | ||
assert(memcmp(str.data(), expected, expected_len) == 0); | ||
} | ||
|
||
void exports::strings::TestImports() { | ||
test::strings::imports::TakeBasic(std::string_view("latin utf16")); | ||
|
||
wit::string str2 = test::strings::imports::ReturnUnicode(); | ||
assert_str(str2.get_view(), "🚀🚀🚀 𠈄𓀀"); | ||
} | ||
|
||
wit::string exports::strings::ReturnEmpty() { | ||
// return a non-zero address (follows cabi_realloc logic) | ||
return wit::string((char const*)1, 0); | ||
} | ||
|
||
// new API: Identical for guest import and export | ||
wit::string exports::strings::Roundtrip(std::string_view str) { | ||
assert(str.size() > 0); | ||
return wit::string::from_view(str); | ||
} |