Adding unit test for `function`, and improving its error messages.