|
1 | 1 | import { deepStrictEqual } from "assert";
|
2 | | -import { Encoder, Decoder } from "@msgpack/msgpack"; |
| 2 | +import { Encoder, Decoder,decode } from "@msgpack/msgpack"; |
3 | 3 |
|
4 | 4 | const createStream = async function* (...args: any) {
|
5 | 5 | for (const item of args) {
|
@@ -108,5 +108,47 @@ describe("shared instances", () => {
|
108 | 108 | deepStrictEqual(a, [[object]], `#${i}`);
|
109 | 109 | }
|
110 | 110 | });
|
| 111 | + |
| 112 | + context("regression #212", () => { |
| 113 | + it("runs multiple times", () => { |
| 114 | + const encoder = new Encoder(); |
| 115 | + const decoder = new Decoder(); |
| 116 | + |
| 117 | + const data1 = { |
| 118 | + isCommunication: false, |
| 119 | + isWarning: false, |
| 120 | + alarmId: "619f65a2774abf00568b7210", |
| 121 | + intervalStart: "2022年05月20日T12:00:00.000Z", |
| 122 | + intervalStop: "2022年05月20日T13:00:00.000Z", |
| 123 | + triggeredAt: "2022年05月20日T13:00:00.000Z", |
| 124 | + component: "someComponent", |
| 125 | + _id: "6287920245a582301475627d", |
| 126 | + }; |
| 127 | + |
| 128 | + const data2 = { |
| 129 | + foo: "bar", |
| 130 | + }; |
| 131 | + |
| 132 | + const arr = [data1, data2]; |
| 133 | + const enc = arr.map((x) => [x, encoder.encode(x)] as const); |
| 134 | + |
| 135 | + enc.forEach(([orig, acc]) => { |
| 136 | + const des = decoder.decode(acc); |
| 137 | + deepStrictEqual(des, orig); |
| 138 | + }); |
| 139 | + }); |
| 140 | + }); |
| 141 | + |
| 142 | + context("Encoder#encodeSharedRef()", () => { |
| 143 | + it("returns the shared reference", () => { |
| 144 | + const encoder = new Encoder(); |
| 145 | + |
| 146 | + const a = encoder.encodeSharedRef(true); |
| 147 | + const b = encoder.encodeSharedRef(false); |
| 148 | + |
| 149 | + deepStrictEqual(decode(a), decode(b)); // yes, this is the expected behavior |
| 150 | + deepStrictEqual(a.buffer, b.buffer); |
| 151 | + }); |
| 152 | + }); |
111 | 153 | });
|
112 | 154 | });
|
0 commit comments