这两个字符串有什么区别?
使用 nUnit 测试特定区域性的输出(货币格式),但我们得到以下结果。
Fail: Formatting currency amount
String lengths are both 11. Strings differ at index 2.
Expected: "12 765,87 €"
But was: "12 765,87 €"
-------------^
我们看不出字符串之间的区别。 我们的预期结果使用“空格”字符。
我们是否可以将不同的空格字符放入接受的结果中以使测试通过?
顺便说一下,测试的培养物是 fr-FR。
编辑:谢谢 Adam,你对 unicode 字符很了解。 我们改变了预期结果,现在每个单元测试都通过了。
Using nUnit to test the output (currency formatting) for a specific culture but we are getting the following result.
Fail: Formatting currency amount
String lengths are both 11. Strings differ at index 2.
Expected: "12 765,87 €"
But was: "12 765,87 €"
-------------^
We can't see the difference between the strings. Our expected result uses a "Space" character.
Is there a different space character that we can put into the accepted result to get the test to pass?
By the way, the tested culture is fr-FR.
Edit: Thanks Adam you are spot on with the unicode character. We have changed our expected results and now each Unit test passes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它们可能是不同类型的空间。 Unicode 有许多不同的空格字符。 通过将字符转换为整数来查看索引 2 处的代码点以获得答案。
编辑
为了回应您的评论,代码点 160 是一个不间断空格。 您可以直接将其输入到源代码中(例如,在 Windows 上的数字键盘上按 Alt+0160) ,或使用转义序列:
It's possible they're different types of spaces. Unicode has a lot of different space characters. Take a look at the code points at index 2 by casting the characters to integers to get your answer.
Edit
In response to your comment, code point 160 is a non-breaking space. You can enter it directly into your source code (e.g. Alt+0160 on the numeric keypad on Windows), or use an escape sequence:
最有可能的是一个空白字符,但不是空格,以避免标签等在启用自动换行时将数字分成两部分。
Most likely it's a character that is blank, but not a space, to avoid labels and such to break the number in two when word-wrapping is enabled.