aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test/src
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2010-11-02 12:09:06 +0100
committerLukas Larsson <[email protected]>2010-11-02 12:09:06 +0100
commitf1a93fefc975f9ce7121dec156d853c2b0cde7d1 (patch)
tree6688c5f84e40aee8e5d71897540187923eeedb4b /lib/common_test/src
parent158ed71a5ddc5050809723a214a8d8c841022871 (diff)
parent19ee7aa8aa107cf78d6eb520b1bc23c578191cac (diff)
downloadotp-f1a93fefc975f9ce7121dec156d853c2b0cde7d1.tar.gz
otp-f1a93fefc975f9ce7121dec156d853c2b0cde7d1.tar.bz2
otp-f1a93fefc975f9ce7121dec156d853c2b0cde7d1.zip
Merge branch 'lukas/common_test/ct_parse_table/OTP-8907' into dev
* lukas/common_test/ct_parse_table/OTP-8907: Update parse_table to take multiline sql rows Add test cases for ct:parse_table
Diffstat (limited to 'lib/common_test/src')
-rw-r--r--lib/common_test/src/ct_util.erl31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/common_test/src/ct_util.erl b/lib/common_test/src/ct_util.erl
index 0a434666fa..b5ab4cbb6e 100644
--- a/lib/common_test/src/ct_util.erl
+++ b/lib/common_test/src/ct_util.erl
@@ -556,10 +556,37 @@ listenv(Telnet) ->
%%% @hidden
%%% @equiv ct:parse_table/1
parse_table(Data) ->
- [Heading|Lines]=
- [remove_space(string:tokens(L, "|"),[]) || L <- Data, hd(L)==$|],
+ {Heading, Rest} = get_headings(Data),
+ Lines = parse_row(Rest,[],size(Heading)),
{Heading,Lines}.
+get_headings(["|" ++ Headings | Rest]) ->
+ {remove_space(string:tokens(Headings, "|"),[]), Rest};
+get_headings([_ | Rest]) ->
+ get_headings(Rest);
+get_headings([]) ->
+ {{},[]}.
+
+parse_row(["|" ++ _ = Row | T], Rows, NumCols) when NumCols > 1 ->
+ case string:tokens(Row, "|") of
+ Values when length(Values) =:= NumCols ->
+ parse_row(T,[remove_space(Values,[])|Rows], NumCols);
+ Values when length(Values) < NumCols ->
+ parse_row([Row ++"\n"++ hd(T) | tl(T)], Rows, NumCols)
+ end;
+parse_row(["|" ++ _ = Row | T], Rows, 1 = NumCols) ->
+ case string:rchr(Row, $|) of
+ 1 ->
+ parse_row([Row ++"\n"++hd(T) | tl(T)], Rows, NumCols);
+ _Else ->
+ parse_row(T, [remove_space(string:tokens(Row,"|"),[])|Rows],
+ NumCols)
+ end;
+parse_row([_Skip | T], Rows, NumCols) ->
+ parse_row(T, Rows, NumCols);
+parse_row([], Rows, _NumCols) ->
+ lists:reverse(Rows).
+
remove_space([Str|Rest],Acc) ->
remove_space(Rest,[string:strip(string:strip(Str),both,$')|Acc]);
remove_space([],Acc) ->