This repository was archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring_test.cpp
More file actions
84 lines (68 loc) · 2.11 KB
/
string_test.cpp
File metadata and controls
84 lines (68 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "test_helper.hpp"
#include "../string.hpp"
#include "../utils.hpp"
#include <cstring>
namespace lib_ruby_parser
{
#ifndef MAYBE_STRING_HAS_BLOB
#define MAYBE_STRING_HAS_BLOB
BLOB(MaybeString);
#endif // MAYBE_STRING_HAS_BLOB
static char *new_owned_string(const char *s)
{
char *out = static_cast<char *>(malloc(strlen(s)));
strncpy(out, s, strlen(s));
return out;
}
extern "C"
{
StringBlob lib_ruby_parser__test__make_string_foo(void);
}
static void test_rust_string_fields(void)
{
annotate_test;
String foo = from_blob<StringBlob, String>(
lib_ruby_parser__test__make_string_foo());
assert_string_eq(foo, "foo");
String moved = std::move(foo);
}
static void test_owned_string_fields(void)
{
annotate_test;
String bar = String::Owned(new_owned_string("bar"), 3);
assert_string_eq(bar, "bar");
}
static void test_copied_string_fields(void)
{
annotate_test;
String baz = String::Copied("baz");
assert_string_eq(baz, "baz");
}
extern "C"
{
MaybeStringBlob lib_ruby_parser__test__make_some_string_foo(void);
MaybeStringBlob lib_ruby_parser__test__make_none_string(void);
}
static void test_maybe_string_fields(void)
{
annotate_test;
MaybeString some_string = from_blob<MaybeStringBlob, MaybeString>(
lib_ruby_parser__test__make_some_string_foo());
assert(some_string.is_some());
assert_string_eq(some_string.string, "foo");
MaybeString none_string = from_blob<MaybeStringBlob, MaybeString>(
lib_ruby_parser__test__make_none_string());
assert(none_string.is_none());
}
void run_test_group_string(void);
void run_test_group_string(void)
{
const test_fn_t tests[] = {
test_rust_string_fields,
test_owned_string_fields,
test_copied_string_fields,
test_maybe_string_fields,
};
run_tests_as_group("string", tests, sizeof(tests) / sizeof(test_fn_t));
}
}