Skip to content

Commit

Permalink
Merge pull request #4 from vietkungfu/master
Browse files Browse the repository at this point in the history
Close file after parsing string
  • Loading branch information
easco authored Oct 20, 2017
2 parents 78202a8 + e3640a7 commit a8a86da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/configparser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ defmodule ConfigParser do
def parse_string(config_string) do
{:ok, pid} = StringIO.open(config_string)
line_stream = IO.stream(pid, :line)
parse_stream(line_stream)
result = parse_stream(line_stream)
StringIO.close(pid)
result
end

@doc """
Expand Down
7 changes: 7 additions & 0 deletions test/configparser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ defmodule ConfigParserTest do
""", {:ok, %{"section" => %{"key" => "value"}}} )
end

test "close StringIO after read" do
process_count_before = Process.list |> length
ConfigParser.parse_string("test")
process_count_after = Process.list |> length
assert process_count_before == process_count_after
end

test "extracts a list of sections from parsed config data" do
{:ok, parse_result} = ConfigParser.parse_string("""
[first_section]
Expand Down

0 comments on commit a8a86da

Please sign in to comment.