Fix #33869, some code block is moved to make it easier to test. Added a new test
Follow up recent render system refactoring PRs (split test code), and fine tune the math render (added some new cases)