From a9e6a768c5a59a1ab69ccfbfb37c8939583a0284 Mon Sep 17 00:00:00 2001 From: Gustaf Lindstedt Date: Sun, 15 Mar 2015 21:14:31 +0800 Subject: legacy test script: minor string handling fix #2181 Add check to see if a string contains ], which can result in cases where wrapping a string in [[...]] breaks. Use [=[...]=] instead on those strings. Use [=[...]=] for insert() and expect(). --- scripts/legacy2luatest.pl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/legacy2luatest.pl b/scripts/legacy2luatest.pl index fb14da8157..51997c037b 100755 --- a/scripts/legacy2luatest.pl +++ b/scripts/legacy2luatest.pl @@ -54,9 +54,9 @@ sub read_in_file { if (@{$input_lines}) { my $last_input_line = pop @{$input_lines}; unshift @{$command_lines}, ''; - unshift @{$command_lines}, $last_input_line . ']])'; + unshift @{$command_lines}, $last_input_line . ']=])'; unshift @{$command_lines}, @{$input_lines}; - unshift @{$command_lines}, "insert([["; + unshift @{$command_lines}, "insert([=["; @{$input_lines} = (); } @@ -133,8 +133,15 @@ sub read_in_file { # If line contains single quotes or backslashes, use double # square brackets to wrap string. if (/'/ || /\\/) { - $startstr = '[['; - $endstr = ']]'; + # If the line contains a closing square bracket, + # wrap it with [=[...]=]. + if (/\]/) { + $startstr = '[=['; + $endstr = ']=]'; + } else { + $startstr = '[['; + $endstr = ']]'; + } } # Emit 'feed' if not a search ('/') or ex (':') command. @@ -190,7 +197,7 @@ sub read_ok_file { if (-f $ok_file) { push @assertions, ''; push @assertions, "-- Assert buffer contents."; - push @assertions, "expect([["; + push @assertions, "expect([=["; open my $ok_file_handle, '<', $ok_file; @@ -202,7 +209,7 @@ sub read_ok_file { close $ok_file_handle; - $assertions[-1] .= "]])"; + $assertions[-1] .= "]=])"; } return \@assertions; -- cgit