-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for io_lib (and io, etc...) to format ports. Adds port_to_list/1 to erlang module exports to keep dialyzer happy. Add test/erlang_tests/test_port_to_list.erl to test result of port_to_list/1 using the "echo" port. Signed-off-by: Winford <winford@object.stream>
- Loading branch information
1 parent
fd19f65
commit 82d6f6d
Showing
5 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
%% | ||
%% This file is part of AtomVM. | ||
%% | ||
%% Copyright (c) 2025 <winford@object.stream> | ||
%% All rights reserved. | ||
%% | ||
%% Licensed under the Apache License, Version 2.0 (the "License"); | ||
%% you may not use this file except in compliance with the License. | ||
%% You may obtain a copy of the License at | ||
%% | ||
%% http://www.apache.org/licenses/LICENSE-2.0 | ||
%% | ||
%% Unless required by applicable law or agreed to in writing, software | ||
%% distributed under the License is distributed on an "AS IS" BASIS, | ||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
%% See the License for the specific language governing permissions and | ||
%% limitations under the License. | ||
%% | ||
%% | ||
%% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later | ||
%% | ||
-module(test_port_to_list). | ||
|
||
-export([start/0, test_echo_port_to_list/0]). | ||
|
||
-define(PortBegin, "#Port<0."). | ||
-define(PortEnd, ">"). | ||
|
||
start() -> | ||
test_echo_port_to_list(). | ||
|
||
test_echo_port_to_list() -> | ||
Port = open_port({spawn, "echo"}, []), | ||
validate_port_fmt(Port). | ||
|
||
%% internal | ||
validate_port_fmt(Port) -> | ||
case get_valid_portchars(Port) of | ||
{ok, PortChars} -> | ||
Res = port_to_list(Port) =:= lists:flatten([?PortBegin, PortChars, ?PortEnd]), | ||
case Res of | ||
true -> 0; | ||
_ -> 1 | ||
end; | ||
{invalid_format, Port} -> | ||
1 | ||
end. | ||
|
||
get_valid_portchars(Port) -> | ||
PList = port_to_list(Port), | ||
[_H, T] = string:split(PList, ?PortBegin), | ||
[PortNum, _] = string:split(T, ?PortEnd), | ||
try list_to_integer(PortNum) of | ||
Num when is_integer(Num) -> | ||
{ok, PortNum}; | ||
_ -> | ||
{invalid_format, Port} | ||
catch | ||
_:_ -> | ||
{invalid_format, Port} | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters