How to test a visitor that uses visit_mut_script?
Let's say you have a visitor, something like this
Then you create a unit test, something like
The test function won't work because the internal code for
test_transform
parses the input code as a module and not a script, so visit_mut_script
is never called. Is there a different function to use instead of test_transform
or is there a way to make test_transform
use parse_script
instead of parse_module
?3 Replies
So after a bit of digging it seems like
visit_mut_module
, visit_mut_script
and visit_mut_program
can be called if you use parse_program
(I think?) but not parse_module
which is what test_transform
seems to use. Should test_transform
maybe use parse_program
instead?
I think this should probably be the case as a test case could be either a module or a script but right now it's assuming it's always a module which I think is bad, parse_program
doc states: Returns Module if it's a module and returns Script if it's not a module.
so therefor test_transform
should probably use parse_program
correct?You are correct I guess
I’ve made an issue for now, we can perhaps discuss this further and see if changing it would break anything if you are interested