The BSON corpus test runner is written to follow the specification instructions for a language with no native intermediate representation of BSON. While it is true we do not have a native representation of a document, since we just wrap bson_t s which are already stored in BSON format, we do have native representations of all the other BSON types.
We should implement the round trip tests for languages with native representations by adding assertions that do something like:
1. Parse a document from the raw data
2. Recursively convert the document to a [String: BSONValue]. This will convert every stored value to a native Swift type. (I don't think we can use the decoder here, as it will not recursively parse nested documents into maps.)
3. Recursively convert the [String: BSONValue] back into a document. This will encode every stored value back to BSON.
4. Check that the new document matches the input
(Note: may need to do something special to preserve key order since dictionaries don't guarantee it)
This would allow us to catch bugs like
SWIFT-351 for example – there are BSON corpus cases for multi-byte UTF8, and converting the stored strings to Swift strings and then putting them back into documents would have shown us that we cut off the end of string.