Skip to content

Commit f3f5d4e

Browse files
author
Timmy Silesmo
committed
refactored test to work with new test structure
1 parent a145f18 commit f3f5d4e

8 files changed

Lines changed: 73 additions & 7 deletions

File tree

crates/csharp/src/function.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -892,13 +892,6 @@ impl Bindgen for FunctionBindgen<'_, '_> {
892892
}
893893

894894
results.push(format!("{length}"));
895-
if FunctionKind::Freestanding == *self.kind || self.interface_gen.direction == Direction::Export {
896-
self.interface_gen.require_interop_using("System.Text");
897-
self.interface_gen.require_interop_using("System.Runtime.InteropServices");
898-
} else {
899-
self.interface_gen.require_using("System.Text");
900-
self.interface_gen.require_using("System.Runtime.InteropServices");
901-
}
902895
}
903896

904897
Instruction::StringLift { .. } => {

tests/runtime/lists/runner.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,33 @@ void exports_runner_run() {
232232
runner_list_f32_free(&ret.f0);
233233
runner_list_f64_free(&ret.f1);
234234
}
235+
236+
{
237+
runner_tuple2_string_list_u8_t headers_data[2];
238+
runner_string_set(&headers_data[0].f0, "Content-Type");
239+
uint8_t val0[] = "text/plain";
240+
headers_data[0].f1.ptr = val0;
241+
headers_data[0].f1.len = 10;
242+
243+
runner_string_set(&headers_data[1].f0, "Content-Length");
244+
uint8_t val1[] = "9";
245+
headers_data[1].f1.ptr = val1;
246+
headers_data[1].f1.len = 1;
247+
248+
runner_list_tuple2_string_list_u8_t headers = { headers_data, 2 };
249+
runner_list_tuple2_string_list_u8_t result;
250+
test_lists_to_test_wasi_http_headers_roundtrip(&headers, &result);
251+
252+
assert(result.len == 2);
253+
assert(result.ptr[0].f0.len == 12);
254+
assert(memcmp(result.ptr[0].f0.ptr, "Content-Type", 12) == 0);
255+
assert(result.ptr[0].f1.len == 10);
256+
assert(memcmp(result.ptr[0].f1.ptr, "text/plain", 10) == 0);
257+
assert(result.ptr[1].f0.len == 14);
258+
assert(memcmp(result.ptr[1].f0.ptr, "Content-Length", 14) == 0);
259+
assert(result.ptr[1].f1.len == 1);
260+
assert(result.ptr[1].f1.ptr[0] == '9');
261+
262+
runner_list_tuple2_string_list_u8_free(&result);
263+
}
235264
}

tests/runtime/lists/runner.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,18 @@ void exports::runner::Run()
105105
std::vector<double>{DBL_MIN, DBL_MAX, -HUGE_VAL, HUGE_VAL}
106106
)
107107
));
108+
109+
{
110+
std::vector<uint8_t> val0 = {'t', 'e', 'x', 't', '/', 'p', 'l', 'a', 'i', 'n'};
111+
std::vector<uint8_t> val1 = {'9'};
112+
std::vector<std::tuple<std::string_view, std::span<const uint8_t>>> headers;
113+
headers.push_back(std::make_tuple(std::string_view("Content-Type"), std::span<const uint8_t>(val0)));
114+
headers.push_back(std::make_tuple(std::string_view("Content-Length"), std::span<const uint8_t>(val1)));
115+
auto result = WasiHttpHeadersRoundtrip(headers);
116+
assert(result.size() == 2);
117+
assert(equal(std::get<0>(result[0]), "Content-Type"));
118+
assert(equal(std::get<1>(result[0]), std::vector<uint8_t>{'t', 'e', 'x', 't', '/', 'p', 'l', 'a', 'i', 'n'}));
119+
assert(equal(std::get<0>(result[1]), "Content-Length"));
120+
assert(equal(std::get<1>(result[1]), std::vector<uint8_t>{'9'}));
121+
}
108122
}

tests/runtime/lists/runner.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ func Run() {
3232
assertEqual(test.ListResult2(), "hello!")
3333
assert(slices.Equal(test.ListResult3(), []string{"hello,", "world!"}))
3434
assert(slices.Equal(test.ListRoundtrip([]uint8{}), []uint8{}))
35+
36+
{
37+
headers := []Tuple2[string, []uint8]{
38+
{V1: "Content-Type", V2: []uint8("text/plain")},
39+
{V1: "Content-Length", V2: []uint8("9")},
40+
}
41+
result := test.WasiHttpHeadersRoundtrip(headers)
42+
assertEqual(len(result), 2)
43+
assertEqual(result[0].V1, "Content-Type")
44+
assert(slices.Equal(result[0].V2, []uint8("text/plain")))
45+
assertEqual(result[1].V1, "Content-Length")
46+
assert(slices.Equal(result[1].V2, []uint8("9")))
47+
}
3548
}
3649

3750
func assertEqual[T comparable](a T, b T) {

tests/runtime/lists/test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,7 @@ void exports_test_lists_to_test_list_minmax_float(test_list_f32_t *a, test_list_
161161
ret->f0 = *a;
162162
ret->f1 = *b;
163163
}
164+
165+
void exports_test_lists_to_test_wasi_http_headers_roundtrip(test_list_tuple2_string_list_u8_t *a, test_list_tuple2_string_list_u8_t *ret0) {
166+
*ret0 = *a;
167+
}

tests/runtime/lists/test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,7 @@ std::tuple<wit::vector<uint64_t>, wit::vector<int64_t>> exports::test::lists::to
129129
std::tuple<wit::vector<float>, wit::vector<double>> exports::test::lists::to_test::ListMinmaxFloat(wit::vector<float> a, wit::vector<double> b) {
130130
return std::make_tuple(std::move(a), std::move(b));
131131
}
132+
133+
wit::vector<std::tuple<wit::string, wit::vector<uint8_t>>> exports::test::lists::to_test::WasiHttpHeadersRoundtrip(wit::vector<std::tuple<wit::string, wit::vector<uint8_t>>> a) {
134+
return a;
135+
}

tests/runtime/lists/test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,7 @@ func ListMinmax64(x []uint64, y []int64) ([]uint64, []int64) {
111111
func ListMinmaxFloat(x []float32, y []float64) ([]float32, []float64) {
112112
return x, y
113113
}
114+
115+
func WasiHttpHeadersRoundtrip(x []Tuple2[string, []uint8]) []Tuple2[string, []uint8] {
116+
return x
117+
}

tests/runtime/lists/test.mbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ pub fn string_roundtrip(a : String) -> String {
124124
a
125125
}
126126

127+
///|
128+
pub fn wasi_http_headers_roundtrip(a : Array[(String, FixedArray[Byte])]) -> Array[(String, FixedArray[Byte])] {
129+
a
130+
}
131+
127132
///|
128133
pub fn allocated_bytes() -> UInt {
129134
// not quite sure about this

0 commit comments

Comments
 (0)