# HG changeset patch # User Andy Register # Date 1357074178 -3600 # Node ID 6251fa48d28b928ff8e9f95ef71a160846d3e152 # Parent 704e15f8fecdee9ad56b439917c00880d98df9e3 textscan.m: various whitespace & delimiter tests added diff -r 704e15f8fecd -r 6251fa48d28b scripts/io/textscan.m --- a/scripts/io/textscan.m Tue Jan 01 14:55:31 2013 -0500 +++ b/scripts/io/textscan.m Tue Jan 01 22:02:58 2013 +0100 @@ -195,6 +195,7 @@ error ("textscan: character value required for EndOfLine"); endif else + if (! ischar (fid)) ## Determine EOL from file. Search for EOL candidates in first BUFLENGTH chars eol_srch_len = min (length (str), BUFLENGTH); ## First try DOS (CRLF) @@ -207,6 +208,9 @@ else eol_char = "\n"; endif + else + eol_char = "\n"; + endif ## Set up the default endofline param value args(end+1:end+2) = {"endofline", eol_char}; endif @@ -408,3 +412,88 @@ %! data = textscan(" 1. 1 \n 2 3\n", '%f %f'); %! assert (data{1}, [1; 2], 1e-15); %! assert (data{2}, [1; 3], 1e-15); + +%% Whitespace test (bug #37333) using delimiter ";" +%!test +%! tc = []; +%! tc{1, 1} = "C:/code;"; +%! tc{1, end+1} = "C:/code/meas;"; +%! tc{1, end+1} = " C:/code/sim;"; +%! tc{1, end+1} = "C:/code/utils;"; +%! string = [tc{:}]; +%! c = textscan (string, "%s", "delimiter", ";"); +%! for k = 1:numel (c{1}) +%! lh = c{1}{k}; +%! rh = tc{k}; +%! rh(rh == ";") = ""; +%! rh = strtrim (rh); +%! assert (strcmp (lh, rh)); +%! end + +%% Whitespace test (bug #37333), adding multipleDelimsAsOne true arg +%!test +%! tc = []; +%! tc{1, 1} = "C:/code;"; +%! tc{1, end+1} = " C:/code/meas;"; +%! tc{1, end+1} = "C:/code/sim;;"; +%! tc{1, end+1} = "C:/code/utils;"; +%! string = [tc{:}]; +%! c = textscan (string, "%s", "delimiter", ";", "multipleDelimsAsOne", 1); +%! for k = 1:numel (c{1}) +%! lh = c{1}{k}; +%! rh = tc{k}; +%! rh(rh == ";") = ""; +%! rh = strtrim (rh); +%! assert (strcmp (lh, rh)); +%! end + +%% Whitespace test (bug #37333), adding multipleDelimsAsOne false arg +%!test +%! tc = []; +%! tc{1, 1} = "C:/code;"; +%! tc{1, end+1} = " C:/code/meas;"; +%! tc{1, end+1} = "C:/code/sim;;"; +%! tc{1, end+1} = ""; +%! tc{1, end+1} = "C:/code/utils;"; +%! string = [tc{:}]; +%! c = textscan (string, "%s", "delimiter", ";", "multipleDelimsAsOne", 0); +%! for k = 1:numel (c{1}) +%! lh = c{1}{k}; +%! rh = tc{k}; +%! rh(rh == ";") = ""; +%! rh = strtrim (rh); +%! assert (strcmp (lh, rh)); +%! end + +%% Whitespace test (bug #37333) whitespace "" arg +%!test +%! tc = []; +%! tc{1, 1} = "C:/code;"; +%! tc{1, end+1} = " C:/code/meas;"; +%! tc{1, end+1} = "C:/code/sim;"; +%! tc{1, end+1} = "C:/code/utils;"; +%! string = [tc{:}]; +%! c = textscan (string, "%s", "delimiter", ";", "whitespace", ""); +%! for k = 1:numel (c{1}) +%! lh = c{1}{k}; +%! rh = tc{k}; +%! rh(rh == ";") = ""; +%! assert (strcmp (lh, rh)); +%! end + +%% Whitespace test (bug #37333), whitespace " " arg +%!test +%! tc = []; +%! tc{1, 1} = "C:/code;"; +%! tc{1, end+1} = " C:/code/meas;"; +%! tc{1, end+1} = "C:/code/sim;"; +%! tc{1, end+1} = "C:/code/utils;"; +%! string = [tc{:}]; +%! c = textscan (string, "%s", "delimiter", ";", "whitespace", " "); +%! for k = 1:numel (c{1}) +%! lh = c{1}{k}; +%! rh = tc{k}; +%! rh(rh == ";") = ""; +%! rh = strtrim (rh); +%! assert (strcmp (lh, rh)); +%! end