SpecFlow.VisualStudio
SpecFlow.VisualStudio copied to clipboard
VS Integration: Automatic Table Formatting does not work well with fullwidth characters
I really like the Automatic Table Formatting feature in VS Integration, which is basically aligning table columns while writing step examples whenever you type a pipe (|) character.
However when it comes to fullwidth characters(Chinese for example), it didn't align table columns properly:
http://imgur.com/VtTV319
Hope this can be fixed or somebody kindly provide hints on where the alignment logic is so we can try to send a PR for this.
Here is the image.

I wonder: Perhaps we should turn off the table formatting if the document contains these types of characters?
Is it hard to do table formatting with these types of characters?
@lukefan6 Could you provide us with a feature file with this type of characters?
Please see sample below:
Feature: Feature_A
Scenario: Scenario_A
Given 異常資料
| Col_A | Col_B | Col_C | Col_D | Col_E |
When 呼叫GetSummary
Then Summary的Status應該為"Normal"
And Summary的Result應該為
| Title | Degree | Unit |
| 異常 | 0 | 筆 |
I don't know, it might be hard to do the formatting with these characters. I'm looking the same now, and it seems that we'd have to base the table formatting based on the width of the characters (which seems to be variable) rather than the number of characters.
That might be possible, but in the meantime -- it would probably be better to not break the tables if these characters are used. Then, at least, SpecFlow would not be doing harm.
The new question would be... are any of these characters being used? Or... is a toggle set in the SpecFlow config that turns off the table formatting?
I prefer not giving up auto table formatting because I really love this feature lol
However, after a few digging I began to realize it won't be a easy job. At first I believe Encoding.GetByteCount helps:
string a = "測";
int width = Encoding.GetEncoding("big5").GetByteCount(a);
Console.WriteLine(width); // 2
However we have to 'guess' the encoding, which won't be easy.
Is it possible that we develop some kind of plugin or config so that users can specify what language their feature file is?
I definitely don't want to give up on the feature, either. It's really nice!
The question to me is how we do the fills. A monospace font makes things very easy because we just fill in any gaps with spaces. We can't do that with the characters above, as all of our options with spaces will lead to strange results:
| Thing |
| 測 |
| 測 |
| 資料 |
| 資料 |
Nothing lines up. We'd have to use some other sort of fill character... a character that already exists in whatever font or language the user happens to use. But if we used a different fill character, we might create a weird scenario where someone hitting backspace might find they have to backspace more than you'd expect (if a thin white space character even existed). We could put a lot of effort into this, and be in situations where things just can't line up.
The only option I see is to turn off the feature (which may exist already?), get out of the way, and allow the programmer to deal with it. If SpecFlow is rewriting the tables under the programmer, then there is no hope for a programmer with this data.