Fix macro expansion (issue #872)

PR #856 introduced issue #872, in which macros are only expanded in a single block, due to erroneous logic in `expand_macros(blocks)`. This PR adds a test for macro expansion in multiple blocks and fixes the issue.