Grails 4.0.1 - Spock unit test cases fail because of spaces

点点圈 提交于 2021-02-08 11:20:29

问题


I am testing i18n formatting using unit tests in my Grails 4.0.1 application but seeing strange results. To me, this specs condition should be satisfied, but it is not.

I don't suppose anyone has had a similar experience that can be explained, or maybe it's simply a bug? Any help would be appreciated.


回答1:


Just as an idea:

Can you iterate over both expected and actual values and convert the characters one by one to the ascii so that you'll probably see the difference

for( c in ​'123 456,78 $') {  
  println "$c   ${(int)c}"
}



回答2:


It was suggested that I get the hex value of each side after which it became clear that the formatter was using a non-breaking line space c2a0 whereas my "expected" value was using the standard kind 20.

I have solved this by using non-breaking spaces on the "expected" side which can be achieved on the Mac by holding Alt + space button as per below.



来源:https://stackoverflow.com/questions/59946271/grails-4-0-1-spock-unit-test-cases-fail-because-of-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!