|
| 1 | +//@ wasmtime-flags = '-Wcomponent-model-map' |
| 2 | +//@ [lang] |
| 3 | +//@ skip-wit-component = true |
| 4 | + |
| 5 | +using System.Diagnostics; |
| 6 | +using System.Text; |
| 7 | + |
| 8 | +namespace TestWorld.wit.Exports.test.maps |
| 9 | +{ |
| 10 | + public class ToTestExportsImpl : IToTestExports |
| 11 | + { |
| 12 | + public static Dictionary<string, uint> NamedRoundtrip(Dictionary<uint, string> a) |
| 13 | + { |
| 14 | + Debug.Assert(a.Count == 2); |
| 15 | + Debug.Assert(a[1] == "uno"); |
| 16 | + Debug.Assert(a[2] == "two"); |
| 17 | + |
| 18 | + return a.ToDictionary(entry => entry.Value, entry => entry.Key); |
| 19 | + } |
| 20 | + |
| 21 | + public static Dictionary<string, byte[]> BytesRoundtrip(Dictionary<string, byte[]> a) |
| 22 | + { |
| 23 | + Debug.Assert(a.Count == 2); |
| 24 | + Debug.Assert(a["hello"].SequenceEqual(Encoding.UTF8.GetBytes("world"))); |
| 25 | + Debug.Assert(a["bin"].SequenceEqual(new byte[] { 0, 1, 2 })); |
| 26 | + |
| 27 | + return a; |
| 28 | + } |
| 29 | + |
| 30 | + public static Dictionary<uint, string> EmptyRoundtrip(Dictionary<uint, string> a) |
| 31 | + { |
| 32 | + Debug.Assert(a.Count == 0); |
| 33 | + return a; |
| 34 | + } |
| 35 | + |
| 36 | + public static Dictionary<string, uint?> OptionRoundtrip(Dictionary<string, uint?> a) |
| 37 | + { |
| 38 | + Debug.Assert(a.Count == 2); |
| 39 | + Debug.Assert(a["some"] == 42); |
| 40 | + Debug.Assert(a["none"] == null); |
| 41 | + |
| 42 | + return a; |
| 43 | + } |
| 44 | + |
| 45 | + public static IToTestExports.LabeledEntry RecordRoundtrip(IToTestExports.LabeledEntry a) |
| 46 | + { |
| 47 | + Debug.Assert(a.label == "test-label"); |
| 48 | + Debug.Assert(a.values.Count == 2); |
| 49 | + Debug.Assert(a.values[10] == "ten"); |
| 50 | + Debug.Assert(a.values[20] == "twenty"); |
| 51 | + |
| 52 | + return a; |
| 53 | + } |
| 54 | + |
| 55 | + public static Dictionary<string, uint> InlineRoundtrip(Dictionary<uint, string> a) |
| 56 | + { |
| 57 | + return a.ToDictionary(entry => entry.Value, entry => entry.Key); |
| 58 | + } |
| 59 | + |
| 60 | + public static Dictionary<uint, string> LargeRoundtrip(Dictionary<uint, string> a) |
| 61 | + { |
| 62 | + Debug.Assert(a.Count == 100); |
| 63 | + return a; |
| 64 | + } |
| 65 | + |
| 66 | + public static (Dictionary<string, uint>, Dictionary<string, byte[]>) MultiParamRoundtrip( |
| 67 | + Dictionary<uint, string> a, |
| 68 | + Dictionary<string, byte[]> b) |
| 69 | + { |
| 70 | + Debug.Assert(a.Count == 2); |
| 71 | + Debug.Assert(b.Count == 1); |
| 72 | + |
| 73 | + return (a.ToDictionary(entry => entry.Value, entry => entry.Key), b); |
| 74 | + } |
| 75 | + |
| 76 | + public static Dictionary<string, Dictionary<uint, string>> NestedRoundtrip( |
| 77 | + Dictionary<string, Dictionary<uint, string>> a) |
| 78 | + { |
| 79 | + Debug.Assert(a.Count == 2); |
| 80 | + Debug.Assert(a["group-a"].Count == 2); |
| 81 | + Debug.Assert(a["group-a"][1] == "one"); |
| 82 | + Debug.Assert(a["group-a"][2] == "two"); |
| 83 | + Debug.Assert(a["group-b"].Count == 1); |
| 84 | + Debug.Assert(a["group-b"][10] == "ten"); |
| 85 | + |
| 86 | + return a; |
| 87 | + } |
| 88 | + |
| 89 | + public static IToTestExports.MapOrString VariantRoundtrip(IToTestExports.MapOrString a) |
| 90 | + { |
| 91 | + return a; |
| 92 | + } |
| 93 | + |
| 94 | + public static Dictionary<uint, string> ResultRoundtrip( |
| 95 | + Result<Dictionary<uint, string>, string> a) |
| 96 | + { |
| 97 | + if (a.IsErr) |
| 98 | + { |
| 99 | + throw new WitException<string>(a.AsErr, 0); |
| 100 | + } |
| 101 | + |
| 102 | + return a.AsOk; |
| 103 | + } |
| 104 | + |
| 105 | + public static (Dictionary<uint, string>, ulong) TupleRoundtrip( |
| 106 | + (Dictionary<uint, string>, ulong) a) |
| 107 | + { |
| 108 | + Debug.Assert(a.Item1.Count == 1); |
| 109 | + Debug.Assert(a.Item1[7] == "seven"); |
| 110 | + Debug.Assert(a.Item2 == 42); |
| 111 | + |
| 112 | + return a; |
| 113 | + } |
| 114 | + |
| 115 | + public static Dictionary<uint, string> SingleEntryRoundtrip(Dictionary<uint, string> a) |
| 116 | + { |
| 117 | + Debug.Assert(a.Count == 1); |
| 118 | + Debug.Assert(a[99] == "ninety-nine"); |
| 119 | + |
| 120 | + return a; |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments