internal/mod/modimports: add more syntax edge cases to testdata
I was surprised to see that modimports used cueimports.Read
to only consume enough tokens to read a CUE file's import declarations.
This seems to have been inherited from Go, where there is this API:
package imports
func ReadImports(f io.Reader, reportSyntaxError bool, imports *[]string) ([]byte, error)
The reason ends up being the same for both Go and CUE, as CUE inherited
multiple Go API decisions from Go: both go/parser and cue/parser
will consume an entire input io.Reader, so when there are any large
CUE files in a module, we would read the entire file into memory
when in practice the imports are likely a tiny fraction of the bytes.
Add a comment explaining that, to prevent others from being surprised
just like I was, and add a TODO about cue/parser being better.
Add plenty more testdata txtar cases for edge cases.
Note that a few don't behave the way I might expect, so add TODOs.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I4a7890e5a52d2a71325676116c036095d330c4e4
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194954
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>