1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2001-2018. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20
21%%
22-module(ei_format_SUITE).
23
24-include_lib("common_test/include/ct.hrl").
25-include("ei_format_SUITE_data/ei_format_test_cases.hrl").
26
27-export([format_wo_ver/1,
28         all/0, suite/0,
29         init_per_testcase/2,
30         atoms/1,
31         tuples/1,
32         lists/1]).
33
34-import(runner, [get_term/1]).
35
36%% This test suite test the erl_format() function.
37%% It uses the port program "ei_format_test".
38
39suite() ->
40    [{ct_hooks,[ts_install_cth]}].
41
42all() ->
43    [format_wo_ver, atoms, tuples, lists].
44
45init_per_testcase(Case, Config) ->
46    runner:init_per_testcase(?MODULE, Case, Config).
47
48%% Tests formatting various atoms.
49
50atoms(Config) when is_list(Config) ->
51    P = runner:start(Config, ?atoms),
52
53    {term, ''} = get_term(P),
54    {term, 'a'} = get_term(P),
55    {term, 'A'} = get_term(P),
56    {term, 'abc'} = get_term(P),
57    {term, 'Abc'} = get_term(P),
58    {term, 'ab@c'} = get_term(P),
59    {term, 'The rain in Spain stays mainly in the plains'} =
60    get_term(P),
61
62    {term, a} = get_term(P),
63    {term, ab} = get_term(P),
64    {term, abc} = get_term(P),
65    {term, ab@c} = get_term(P),
66    {term, abcdefghijklmnopq} = get_term(P),
67
68    {term, ''} = get_term(P),
69    {term, 'a'} = get_term(P),
70    {term, 'A'} = get_term(P),
71    {term, 'abc'} = get_term(P),
72    {term, 'Abc'} = get_term(P),
73    {term, 'ab@c'} = get_term(P),
74    {term, 'The rain in Spain stays mainly in the plains'} =
75    get_term(P),
76
77    {term, a} = get_term(P),
78    {term, ab} = get_term(P),
79    {term, abc} = get_term(P),
80    {term, ab@c} = get_term(P),
81    {term, '   abcdefghijklmnopq   '} = get_term(P),
82
83    runner:recv_eot(P),
84    ok.
85
86
87
88%% Tests formatting various tuples
89
90tuples(Config) when is_list(Config) ->
91    P = runner:start(Config, ?tuples),
92
93    {term, {}} = get_term(P),
94    {term, {a}} = get_term(P),
95    {term, {a, b}} = get_term(P),
96    {term, {a, b, c}} = get_term(P),
97    {term, {1}} = get_term(P),
98    {term, {[]}} = get_term(P),
99    {term, {[], []}} = get_term(P),
100    {term, {[], a, b, c}} = get_term(P),
101    {term, {[], a, [], b, c}} = get_term(P),
102    {term, {[], a, '', b, c}} = get_term(P),
103
104    runner:recv_eot(P),
105    ok.
106
107
108
109%% Tests formatting various lists
110
111lists(Config) when is_list(Config) ->
112    P = runner:start(Config, ?lists),
113
114    {term, []} = get_term(P),
115    {term, [a]} = get_term(P),
116    {term, [a, b]} = get_term(P),
117    {term, [a, b, c]} = get_term(P),
118    {term, [1]} = get_term(P),
119    {term, [[]]} = get_term(P),
120    {term, [[], []]} = get_term(P),
121    {term, [[], a, b, c]} = get_term(P),
122    {term, [[], a, [], b, c]} = get_term(P),
123    {term, [[], a, '', b, c]} = get_term(P),
124    {term, [[x, 2], [y, 3], [z, 4]]}= get_term(P),
125    {term, [{a,b},{c,d}]} = get_term(P),
126    %% {term, [{name, 'Madonna'}, {age, 21}, {data, [{addr, "E-street", 42}]}]} = get_term(P),
127
128    {term, [{pi, F1}, {'cos(70)', F2}]} = get_term(P),
129    %% don't match floats directly
130    true= abs(3.1415-F1) < 0.01,
131    true= abs(0.34202-F2) < 0.01,
132
133    {term, [[pi, F3], ['cos(70)', F4]]} = get_term(P),
134    true= abs(3.1415-F3) < 0.01,
135    true= abs(0.34202-F4) < 0.01,
136
137
138    %%    {term, [[pi, 3.1415], [], ["cos(70)", 0.34202]]} = get_term(P),
139    {term, [-1]} = get_term(P),
140    {term, "hejsan"} = get_term(P),
141
142
143    Str1 = lists:duplicate(65535,$A),
144    Str2 = lists:duplicate(65536,$A),
145    {term,Str1} = get_term(P),
146    {term,Str2} = get_term(P),
147
148    runner:recv_eot(P),
149    ok.
150
151
152format_wo_ver(Config) when is_list(Config) ->
153    P = runner:start(Config, ?format_wo_ver),
154
155    {term, [-1, 2, $c, {a, "b"}, {c, 10}]} = get_term(P),
156
157    runner:recv_eot(P),
158    ok.
159