test("write and read a soul relation with state is ok", (t, done) => {
radisk("key", [{"#": "soul"}, 1234])
setTimeout(() => {
assert.deepEqual(puts, {
"!": '\x1F+0\x1F#\x1F"key\x1F=\x1F#soul\x031234\x1F\n',
})
done()
}, 10)
})
I noticed some typos after my first commit to Holster and wondered how they didn't get picked up. A lot of the current code is copied over from Porting Gun, so I'm still working out how it all works and was genuinely curious why it hadn't caused errors.
The typo was in a utility function that checks if an object is a soul relation (fixed version):
// Check if an object is a soul relation, ie {'#': 'UUID'}
const rel = {
is: value => {
if (value && value["#"] && !value._ && obj.is(value)) {
let o = {}
obj.map(value, map_soul, o)
if (o.id) return o.id
}
return false
},
// Convert a soul into a relation and return it.
ify: soul => obj.put({}, "#", soul),
}
But why hadn't it caused any errors? Turns out it was called in Radisk.encode(), but only if it was passed an object, and it wasn't. Radisk is called by store, but it was using JSON.stringify to store a value and it's state as an array, so Radisk was only receiving strings! So now besides the original typo, I'm wondering why I can't just store the array and not use JSON in store.js. That led to updating the file format to include state, which explains the test at the start of this post!
Test driven development
I noticed some typos after my first commit to Holster and wondered how they didn't get picked up. A lot of the current code is copied over from Porting Gun, so I'm still working out how it all works and was genuinely curious why it hadn't caused errors.
The typo was in a utility function that checks if an object is a soul relation (fixed version):
But why hadn't it caused any errors? Turns out it was called in Radisk.encode(), but only if it was passed an object, and it wasn't. Radisk is called by store, but it was using JSON.stringify to store a value and it's state as an array, so Radisk was only receiving strings! So now besides the original typo, I'm wondering why I can't just store the array and not use JSON in store.js. That led to updating the file format to include state, which explains the test at the start of this post!