How do you unit test regular expressions?

后端 未结 10 736
长发绾君心
长发绾君心 2020-12-12 11:05

I\'m new to TDD, and I find RegExp quite a particular case. Is there any special way to unit test them, or may I just treat them as regular functions?

10条回答
  •  一个人的身影
    2020-12-12 11:45

    I think a simple input ouput test is sufficient. As time goes by and some cases occur in which your regex fails, don't forget to add these cases to the test as well while fixing.

提交回复
热议问题