aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/indent2_SUITE_data/src/iodata.erl
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2019-04-17 13:20:56 +0200
committerHans Bolinder <[email protected]>2019-05-07 08:25:03 +0200
commit77cbe3b6ced0ca42cf3ec5c8ca0333d9418a0372 (patch)
tree5e5e5f8785e10647ac62fb026134925ad64b053f /lib/dialyzer/test/indent2_SUITE_data/src/iodata.erl
parentb0a7495c44ebf6741714948bdf5c0cb9593ec953 (diff)
downloadotp-77cbe3b6ced0ca42cf3ec5c8ca0333d9418a0372.tar.gz
otp-77cbe3b6ced0ca42cf3ec5c8ca0333d9418a0372.tar.bz2
otp-77cbe3b6ced0ca42cf3ec5c8ca0333d9418a0372.zip
dialyzer: Add test cases with indentation
A smallish selection of already existing tests, run with the indentation option.
Diffstat (limited to 'lib/dialyzer/test/indent2_SUITE_data/src/iodata.erl')
-rw-r--r--lib/dialyzer/test/indent2_SUITE_data/src/iodata.erl41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/dialyzer/test/indent2_SUITE_data/src/iodata.erl b/lib/dialyzer/test/indent2_SUITE_data/src/iodata.erl
new file mode 100644
index 0000000000..caa44f6c91
--- /dev/null
+++ b/lib/dialyzer/test/indent2_SUITE_data/src/iodata.erl
@@ -0,0 +1,41 @@
+-module(iodata).
+
+%% A small part of beam_asm.
+
+-export([encode/2]).
+
+-spec encode(non_neg_integer(), integer()) -> iodata(). % extra range binary()
+
+encode(Tag, N) when Tag >= 0, N < 0 ->
+ encode1(Tag, negative_to_bytes(N));
+encode(Tag, N) when Tag >= 0, N < 16 ->
+ (N bsl 4) bor Tag; % not in the specification
+encode(Tag, N) when Tag >= 0, N < 16#800 ->
+ [((N bsr 3) band 2#11100000) bor Tag bor 2#00001000, N band 16#ff];
+encode(Tag, N) when Tag >= 0 ->
+ encode1(Tag, to_bytes(N)).
+
+encode1(Tag, Bytes) ->
+ case iolist_size(Bytes) of
+ Num when 2 =< Num, Num =< 8 ->
+ [((Num-2) bsl 5) bor 2#00011000 bor Tag| Bytes];
+ Num when 8 < Num ->
+ [2#11111000 bor Tag, encode(0, Num-9)| Bytes]
+ end.
+
+to_bytes(N) ->
+ Bin = binary:encode_unsigned(N),
+ case Bin of
+ <<0:1,_/bits>> -> Bin;
+ <<1:1,_/bits>> -> [0,Bin]
+ end.
+
+negative_to_bytes(N) when N >= -16#8000 ->
+ <<N:16>>;
+negative_to_bytes(N) ->
+ Bytes = byte_size(binary:encode_unsigned(-N)),
+ Bin = <<N:Bytes/unit:8>>,
+ case Bin of
+ <<0:1,_/bits>> -> [16#ff,Bin];
+ <<1:1,_/bits>> -> Bin
+ end.