cucumber / godog

Cucumber for golang
MIT License
2.31k stars 253 forks source link

Table output is not aligned when using non-english characters #94

Open aaronmcohen opened 7 years ago

aaronmcohen commented 7 years ago

When I run a test using this table in my feature file

    Examples: Sample leaders and their countries
      | user | email | country |
      | Serzh Sargsyan | serzh.sargsyan@armenia.gov | Armenia |
      | Ilham Aliyev | ilham.aliyev@azerbaijan.gov | Azerbaijan |
      | Alexander Lukashenko | alexander.lukashenko@belarus.gov | Belarus |
      | ហ៊ុន សែន | hun.aen@cambodia.gov | Cambodia |
      | 习近平 | xi.jinping@china.gov | China |
      | გიორგი მარგველაშვილი | giorgi.margvelashvili@georgia.gov | Georgia |
      | 林鄭月娥 | carrie.lam@hongkong.gov | Hong Kong |
      | حسن روحانی‎‎ | hassan.rouhani@iran.gov | Iran |
      | محمد فؤاد معصوم‎‎ | fuad.masum@iraq.gov | Iraq |
      | Нұрсұлтан Әбішұлы Назарбаев | nursultan.nazarbayev@kazakhstan.gov | Kazakhstan |
      | 김정은 | Kim Jong-un | North Korea |
      | Алмазбек Шаршенович Атамбаев | almazbek.atambayev@kyrgyzstan.gov | Kyrgyzstan |
      | محمد يوسف المقريف‎‎ | magariaf@libya.gov | Libya |
      | 何厚鏵 | edmund.ho.hau.wah@macau.gov | Macau |
      | Игорь Никола́евич Додон | igor.dodon@moldova.gov | Moldova |
      | Цахиагийн Элбэгдорж | tsakhiagiin.elbegdorj@mongolia.gov | Mongolia |
      | Влади́мир Влади́мирович Пу́тин | vladimir.putin@russia.gov | Russia |
      | 蔡英文 | tsai.ing-wen@taiwan.gov | Taiwan |
      | Эмомали́ Шари́пович Рахмо́нов | emomali.rahmon@tajikistan.gov | Tajikistan |
      | Gurbanguly Berdimuhamedow | gurbanguly.berdimuhamedow@turkmenistan.gov | Turkmenistan |
      | Петро́ Олексі́йович Пороше́нко | petro/poroshenko@ukraine.gov | Ukraine |
      | Шавкат Миромонович Мирзиёев | shavkat.mirziyoyev@uzbekistan.gov | Uzbekistan |
      | 陳大光 | trần.dại.quang@vietnam.gov | Vietnam |

the result in the console is:

    Examples: Sample leaders and their countries
      | user                                                       | email                                      | country      |
      | Serzh Sargsyan                                             | serzh.sargsyan@armenia.gov                 | Armenia      |
      | Ilham Aliyev                                               | ilham.aliyev@azerbaijan.gov                | Azerbaijan   |
      | Alexander Lukashenko                                       | alexander.lukashenko@belarus.gov           | Belarus      |
      | ហ៊ុន សែន                                     | hun.aen@cambodia.gov                       | Cambodia     |
      | 习近平                                                  | xi.jinping@china.gov                       | China        |
      | გიორგი მარგველაშვილი | giorgi.margvelashvili@georgia.gov          | Georgia      |
      | 林鄭月娥                                               | carrie.lam@hongkong.gov                    | Hong Kong    |
      | حسن روحانی‎‎                                  | hassan.rouhani@iran.gov                    | Iran         |
      | محمد فؤاد معصوم‎‎                         | fuad.masum@iraq.gov                        | Iraq         |
      | Нұрсұлтан Әбішұлы Назарбаев       | nursultan.nazarbayev@kazakhstan.gov        | Kazakhstan   |
      | 김정은                                                  | Kim Jong-un                                | North Korea  |
      | Алмазбек Шаршенович Атамбаев     | almazbek.atambayev@kyrgyzstan.gov          | Kyrgyzstan   |
      | محمد يوسف المقريف‎‎                     | magariaf@libya.gov                         | Libya        |
      | 何厚鏵                                                  | edmund.ho.hau.wah@macau.gov                | Macau        |
      | Игорь Никола́евич Додон               | igor.dodon@moldova.gov                     | Moldova      |
      | Цахиагийн Элбэгдорж                      | tsakhiagiin.elbegdorj@mongolia.gov         | Mongolia     |
      | Влади́мир Влади́мирович Пу́тин | vladimir.putin@russia.gov                  | Russia       |
      | 蔡英文                                                  | tsai.ing-wen@taiwan.gov                    | Taiwan       |
      | Эмомали́ Шари́пович Рахмо́нов   | emomali.rahmon@tajikistan.gov              | Tajikistan   |
      | Gurbanguly Berdimuhamedow                                  | gurbanguly.berdimuhamedow@turkmenistan.gov | Turkmenistan |
      | Петро́ Олексі́йович Пороше́нко | petro/poroshenko@ukraine.gov               | Ukraine      |
      | Шавкат Миромонович Мирзиёев       | shavkat.mirziyoyev@uzbekistan.gov          | Uzbekistan   |
      | 陳大光                                                  | trần.dại.quang@vietnam.gov             | Vietnam      |

My expectation is that they would be aligned.

l3pp4rd commented 7 years ago

Hi, yes indeed, uses simple builtin len now, will need to fix, thanks for reporting ;)

l3pp4rd commented 7 years ago

This should resolve it, but when I did copy your example, there were still some alignment issues with some character sets and now I'm not exactly certain that this is fully resolved.. can you test it?

l3pp4rd commented 7 years ago

well, looks like for some of locales it would be necessary to use a separate library

2017-07-23-231404

would like to avoid such a dependency.

aaronmcohen commented 7 years ago

What are the impacts of leveraging the dependency? The logic in that go dependency looks complex enough that it would be hard to reproduce otherwise.

l3pp4rd commented 7 years ago

well, even this library cannot predict exact width for characters in all locales, for East Asian it does fix the width, but not many others. This will wait until a better solution is found for such unicode character sets, since the character spacing is different.

2017-07-24-193548

At the moment it will not be aligned properly