Skip to content

Commit 09b8de0

Browse files
committed
test(check.rb): add --fold-markers option
Example usage: check.rb --fold-markers '*{{{,*}}}'
1 parent 76f6321 commit 09b8de0

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

check/check.rb

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,22 @@ def classes_info_list
897897
end
898898
899899
# Convert a .frm file to a .rb file and load it.
900-
def make_ruby_file(filename)
900+
def make_ruby_file(filename, fold_markers = nil)
901+
# Handle fold markers.
902+
if fold_markers.nil?
903+
fold_open_pattern = /^\*..#\[/
904+
fold_open_with_name_pattern = /^\*..#\[\s*([^:]*)/
905+
fold_close_pattern = /^\*..#\]/
906+
fold_close_with_name_pattern = /^\*..#\]\s*([^:]*)/
907+
else
908+
fold_open_marker = Regexp.escape(fold_markers[:open])
909+
fold_close_marker = Regexp.escape(fold_markers[:close])
910+
fold_open_pattern = /^#{fold_open_marker}/
911+
fold_open_with_name_pattern = /^#{fold_open_marker}\s*([^:]*)/
912+
fold_close_pattern = /^#{fold_close_marker}/
913+
fold_close_with_name_pattern = /^#{fold_close_marker}\s*([^:]*)/
914+
end
915+
901916
# Check existing files.
902917
full_filename = File.expand_path(filename)
903918
inname = File.basename(filename)
@@ -931,7 +946,7 @@ def make_ruby_file(filename)
931946
lineno += 1
932947
if level == 0
933948
case line
934-
when /^\*..#\[\s*([^:]*)/
949+
when fold_open_with_name_pattern
935950
# fold open: start a class
936951
fold = $1.strip
937952
if fold.empty?
@@ -963,14 +978,14 @@ def make_ruby_file(filename)
963978
else
964979
line = "class Test_#{classname} < Test::Unit::TestCase; include FormTest"
965980
end
966-
when /^\*..#\]/
981+
when fold_close_pattern
967982
# unexpected fold close
968983
fatal("unexpected fold close", inname, lineno)
969984
else
970985
# as commentary
971986
line = ""
972987
end
973-
elsif heredoc.nil? && line =~ /^\*..#\]\s*([^:]*)/ && level == 1
988+
elsif heredoc.nil? && line =~ fold_close_with_name_pattern && level == 1
974989
# fold close: end of the class
975990
fold = $1.strip
976991
foldname = info.foldname
@@ -1087,10 +1102,10 @@ def make_ruby_file(filename)
10871102
line = ""
10881103
else
10891104
if heredoc.nil?
1090-
if line =~ /^\*..#\[/
1105+
if line =~ fold_open_pattern
10911106
# fold open
10921107
level += 1
1093-
elsif line =~ /^\*..#\]\s*([^:]*)/
1108+
elsif line =~ fold_close_with_name_pattern
10941109
# fold close
10951110
level -= 1
10961111
elsif line =~ /<</ && (line =~ /<<-?(\w+)/ ||
@@ -1558,6 +1573,8 @@ def main
15581573
"Do not run tests matching NAME") { |pat| opts.exclude_patterns << pat }
15591574
parser.on("-g", "--group GROUPID/GROUPCOUNT",
15601575
"Split tests and run only one group") { |group| opts.group_id, opts.group_count = parse_group(group) }
1576+
parser.on("--fold-markers OPEN,CLOSE",
1577+
"Set fold markers") { |open_close| a = open_close.split(",", 2); opts.fold_markers = { open: a[0], close: a[1] } }
15611578
parser.on("-v", "--verbose",
15621579
"Enable verbose output") { opts.verbose = true }
15631580
parser.on("--show-newlines",
@@ -1606,7 +1623,7 @@ def main
16061623
end
16071624
16081625
opts.files.uniq.sort.each do |file|
1609-
FormTest.tests.make_ruby_file(file)
1626+
FormTest.tests.make_ruby_file(file, opts.fold_markers)
16101627
end
16111628
16121629
# Split tests into groups and run only one group.

0 commit comments

Comments
 (0)