Update extract-tests.py to use same test directives as rustdoc.

Closes #11362.
auto merge of #11490 : wting/rust/wting_11362_update_extract_tests, r=alexcrichton

Refactored the file quite a bit, I can add unit tests if desired. There's a few changes from the previous version's behavior:

- destination directory will be created if it doesn't exist
- strings and file is written as unicode

I have a few questions, but will ask them in #11362.