Skip to content

Commit 1df2153

Browse files
sashabelozerovctran
authored andcommitted
[Fix #675] Correct indentation for double-byte characters (#676)
1 parent a816255 commit 1df2153

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/annotate/annotate_models.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ def format_default(col_name, max_size, col_type, bare_type_allowance, attrs)
920920
end
921921

922922
def width(string)
923-
string.chars.inject(0) { |acc, elem| acc + (elem.bytesize == 1 ? 1 : 2) }
923+
string.chars.inject(0) { |acc, elem| acc + (elem.bytesize == 3 ? 2 : 1) }
924924
end
925925

926926
def mb_chars_ljust(string, length)

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,9 @@ def self.when_called_with(options = {})
10061006
[:active, :boolean, { limit: 1, comment: 'ACTIVE' }],
10071007
[:name, :string, { limit: 50, comment: 'NAME' }],
10081008
[:notes, :text, { limit: 55, comment: 'NOTES' }],
1009+
[:cyrillic, :text, { limit: 30, comment: 'Кириллица' }],
1010+
[:japanese, :text, { limit: 60, comment: '熊本大学 イタリア 宝島' }],
1011+
[:arabic, :text, { limit: 20, comment: 'لغة' }],
10091012
[:no_comment, :text, { limit: 20, comment: nil }],
10101013
[:location, :geometry_collection, { limit: nil, comment: nil }]
10111014
]
@@ -1017,12 +1020,15 @@ def self.when_called_with(options = {})
10171020
#
10181021
# Table name: users
10191022
#
1020-
# id(ID) :integer not null, primary key
1021-
# active(ACTIVE) :boolean not null
1022-
# name(NAME) :string(50) not null
1023-
# notes(NOTES) :text(55) not null
1024-
# no_comment :text(20) not null
1025-
# location :geometry_collect not null
1023+
# id(ID) :integer not null, primary key
1024+
# active(ACTIVE) :boolean not null
1025+
# name(NAME) :string(50) not null
1026+
# notes(NOTES) :text(55) not null
1027+
# cyrillic(Кириллица) :text(30) not null
1028+
# japanese(熊本大学 イタリア 宝島) :text(60) not null
1029+
# arabic(لغة) :text(20) not null
1030+
# no_comment :text(20) not null
1031+
# location :geometry_collect not null
10261032
#
10271033
EOS
10281034

0 commit comments

Comments
 (0)