(creator, getter, setter, expectedToken = T)
| 19 | } |
| 20 | |
| 21 | function test(creator, getter, setter, expectedToken = T) { |
| 22 | // Warm up the creator function so there's feedback and the boilerplate |
| 23 | // gets created. |
| 24 | warmup(creator); |
| 25 | |
| 26 | const o1 = creator(); |
| 27 | assertEquals(expectedToken, getter(o1)); |
| 28 | |
| 29 | if (setter == undefined) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | // Test that we did a deep copy by setting a field in o1, creating another |
| 34 | // object, and asserting that it got a fresh copy of the data. |
| 35 | setter(o1); |
| 36 | assertNotEquals(expectedToken, getter(o1)); |
| 37 | |
| 38 | const o2 = creator(); |
| 39 | assertEquals(expectedToken, getter(o2)); |
| 40 | } |
| 41 | |
| 42 | // Shallow array: |
| 43 | test(() => { return [T, 2, 3]; }, (o) => o[0], (o) => o[0] = T2); |
no test coverage detected