From 3a79096bdbeef14f94aca240a39cae907b2e3fc6 Mon Sep 17 00:00:00 2001 From: Dave Machado Date: Fri, 28 Jul 2017 12:32:39 -0400 Subject: [PATCH] use regex to check number of padding spaces --- build/test.rb | 3 +++ build/validate_format.rb | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 build/test.rb diff --git a/build/test.rb b/build/test.rb new file mode 100644 index 00000000..416349f0 --- /dev/null +++ b/build/test.rb @@ -0,0 +1,3 @@ +s = " lol " +puts s[/\A +/].size +puts s[/ +\z/].size \ No newline at end of file diff --git a/build/validate_format.rb b/build/validate_format.rb index baf9244f..a85a6edc 100755 --- a/build/validate_format.rb +++ b/build/validate_format.rb @@ -39,16 +39,17 @@ File.foreach(filename).with_index do | line, line_num | values = line.split("|") + ################### GLOBAL ################### values.each.with_index do |val, val_index| msg = "" case val_index when INDEX_TITLE..INDEX_LINK - if val[0] != " " || val[val.length-1] != " " - add_error(line_num, val_index, "pad before and after string with spaces") + # every line segment should start and end with exactly 1 space + if val[/\A */].size != 1 || val[/ *\z/].size != 1 + add_error(line_num, val_index, "string should start and end with exactly 1 space") end end end - ################# DESCRIPTION ################ # First character should be capitalized desc_val = values[INDEX_DESCRIPTION].lstrip.chop