【发布时间】:2020-04-26 11:50:02
【问题描述】:
我正在使用intl package 最新版本0.16.1 为货币格式创建单元测试。
我的格式化程序是:final currencyFormat = NumberFormat.simpleCurrency(locale: 'pt_BR');
我的预期结果是:var expected = r'R$ 1,00';。我以这种方式将我的格式化程序应用于值1.0:var formatted = currencyFormat.format(1.0) 导致R$ 1,00。
当我使用expect(formatted, expected) 测试两个值时,它显示结果不一样。
Expected: 'R$ 1,00'
Actual: 'R$ 1,00'
Which: is different.
Expected: R$ 1,00
Actual: R$ 1,00
^
Differ at offset 2
好吧,我花了一些时间发现两个字符串的符文只有一个字符差异。
预期符文:(82, 36, 32, 49, 44, 48, 48)
格式化符文:(82, 36, 160, 49, 44, 48, 48)
我的问题是:如果在格式化时使用了不间断空格,那么在没有文档讨论的情况下如何避免这个错误?
【问题讨论】:
标签: unit-testing flutter dart dart-intl