-
-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathtest_hpyunicodebuilder.py
More file actions
23 lines (22 loc) · 926 Bytes
/
test_hpyunicodebuilder.py
File metadata and controls
23 lines (22 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from .support import HPyTest
class TestString(HPyTest):
def test_unicode_builder(self):
mod = self.make_module("""
HPyDef_METH(f, "f", f_impl, HPyFunc_NOARGS)
static HPy f_impl(HPyContext *ctx, HPy h_self)
{
HPyUnicodeBuilder builder = HPyUnicodeBuilder_New(ctx, 0);
if(HPy_IsNull(builder)) {
HPyErr_SetString(ctx, ctx->h_RuntimeError, "Could not create HPyUnicodeBuilder");
return HPy_NULL;
}
HPyUnicodeBuilder_Add(ctx, builder, "hello ");
HPyUnicodeBuilder_Add(ctx, builder, "world");
HPyUnicodeBuilder_Add(ctx, builder, "!");
HPy h_string = HPyUnicodeBuilder_Build(ctx, builder);
return h_string;
}
@EXPORT(f)
@INIT
""")
assert mod.f() == "hello world!"