-
Notifications
You must be signed in to change notification settings - Fork 269
Expand file tree
/
Copy pathrunner.cs
More file actions
173 lines (147 loc) · 5.99 KB
/
runner.cs
File metadata and controls
173 lines (147 loc) · 5.99 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System.Diagnostics;
using RunnerWorld.wit.Imports.test.lists;
using System.Text;
namespace RunnerWorld;
public class RunnerWorldExportsImpl : IRunnerWorldExports
{
public static void Run()
{
IToTestImports.EmptyListParam(new byte[0]);
IToTestImports.EmptyStringParam("");
{
byte[] result = IToTestImports.EmptyListResult();
Debug.Assert(result.Length == 0);
}
{
string result = IToTestImports.EmptyStringResult();
Debug.Assert(result.Length == 0);
}
IToTestImports.ListParam(new byte[] { (byte)1, (byte)2, (byte)3, (byte)4 });
IToTestImports.ListParam((new byte[] { (byte)1, (byte)2, (byte)3, (byte)4 }).AsSpan());
IToTestImports.ListParam((new byte[] { (byte)1, (byte)2, (byte)3, (byte)4 }).AsMemory());
IToTestImports.ListParam2("foo");
IToTestImports.ListParam3(new List<String>() {
"foo",
"bar",
"baz"
});
IToTestImports.ListParam4(new List<List<String>>() {
new List<String>() {
"foo",
"bar"
},
new List<String>() {
"baz"
}
});
List<string> randomStrings = new List<string>();
for (int i = 0; i < 1000; i++)
{
randomStrings.Add(Guid.NewGuid().ToString());
}
IToTestImports.ListParamLarge(randomStrings);
{
byte[] result = IToTestImports.ListResult();
Debug.Assert(result.Length == 5);
Debug.Assert(result[0] == (byte)1);
Debug.Assert(result[1] == (byte)2);
Debug.Assert(result[2] == (byte)3);
Debug.Assert(result[3] == (byte)4);
Debug.Assert(result[4] == (byte)5);
}
{
string result = IToTestImports.ListResult2();
Console.WriteLine(result);
Debug.Assert(result == "hello!");
}
{
List<String> result = IToTestImports.ListResult3();
Debug.Assert(result.Count() == 2);
Console.WriteLine(result[0]);
Console.WriteLine(result[1]);
Debug.Assert(result[0] == "hello,");
Debug.Assert(result[1] == "world!");
}
string[] strings = { "x", "", "hello", "hello ⚑ world" };
foreach (string s in strings)
{
string result = IToTestImports.StringRoundtrip(s);
Debug.Assert(result == s);
byte[] bytes = Encoding.UTF8.GetBytes(s);
Debug.Assert(bytes.SequenceEqual(IToTestImports.ListRoundtrip(bytes)));
}
{
var (u, s) = IToTestImports.ListMinmax8(
new byte[] { byte.MinValue, byte.MaxValue },
new sbyte[] { sbyte.MinValue, sbyte.MaxValue }
);
Debug.Assert(u.Length == 2 && u[0] == byte.MinValue && u[1] == byte.MaxValue);
Debug.Assert(s.Length == 2 && s[0] == sbyte.MinValue && s[1] == sbyte.MaxValue);
}
{
var (u, s) = IToTestImports.ListMinmax16(
new ushort[] { ushort.MinValue, ushort.MaxValue },
new short[] { short.MinValue, short.MaxValue }
);
Console.WriteLine(u[0]);
Console.WriteLine(u[1]);
Debug.Assert(u.Length == 2, $"u.Length {u.Length}");
Debug.Assert(u[0] == ushort.MinValue, $"u[0] == {u[0]}");
Debug.Assert(u[1] == ushort.MaxValue, $"u[1] == {u[1]}");
Debug.Assert(s.Length == 2);
Console.WriteLine(s[0]);
Console.WriteLine(s[1]);
Debug.Assert(s.Length == 2 && s[0] == short.MinValue && s[1] == short.MaxValue);
}
{
var (u, s) = IToTestImports.ListMinmax32(
new uint[] { uint.MinValue, uint.MaxValue },
new int[] { int.MinValue, int.MaxValue }
);
Debug.Assert(u.Length == 2 && u[0] == uint.MinValue && u[1] == uint.MaxValue);
Debug.Assert(s.Length == 2 && s[0] == int.MinValue && s[1] == int.MaxValue);
}
{
var (u, s) = IToTestImports.ListMinmax64(
new ulong[] { ulong.MinValue, ulong.MaxValue },
new long[] { long.MinValue, long.MaxValue }
);
Debug.Assert(u.Length == 2 && u[0] == ulong.MinValue && u[1] == ulong.MaxValue);
Debug.Assert(s.Length == 2 && s[0] == long.MinValue && s[1] == long.MaxValue);
}
{
var (u, s) = IToTestImports.ListMinmaxFloat(
new float[] {
float.MinValue,
float.MaxValue,
float.NegativeInfinity,
float.PositiveInfinity
},
new double[] {
double.MinValue,
double.MaxValue,
double.NegativeInfinity,
double.PositiveInfinity
});
Debug.Assert(u.Length == 4
&& u[0] == float.MinValue
&& u[1] == float.MaxValue
&& u[2] == float.NegativeInfinity
&& u[3] == float.PositiveInfinity);
Debug.Assert(s.Length == 4
&& s[0] == double.MinValue
&& s[1] == double.MaxValue
&& s[2] == double.NegativeInfinity
&& s[3] == double.PositiveInfinity);
}
{
var headers = new List<(string, byte[])>() { ("Content-Type", Encoding.UTF8.GetBytes("text/plain")), ("Content-Length", Encoding.UTF8.GetBytes("Not found".Count().ToString())) };
var result = IToTestImports.WasiHttpHeadersRoundtrip(headers);
for (var i = 0; i < result.Count(); i++)
{
Debug.Assert(result[i].Item1 == headers[i].Item1);
Debug.Assert(headers[i].Item2.SequenceEqual(result[i].Item2));
}
}
}
}