Keep magic comments at the top of generated files

At present the comments are preserved, but the auto-generation notice bumps them down below line 1 where they've no effect.

The documentation comment on the syntax of magic comments is: 

https://github.com/ruby/ruby/blob/7ea675732ac1dac72f07756498706678d8725719/encoding.c#L1697

The added regex test tracks the doc comment, except I don't bother checking the encoding string (say, with `Encoding.find($2)`), as I figure that's Ruby's business and users will find out soon enough if they've botched an encoding string.