Nit: it would probably be preferable to write this assert as:

assert(regions.forall(_.refId == referenceId))

so that we are testing that the affirmative case does occur instead of testing to make sure that the negative case isn't happening.