-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing issue #19 #30
Open
m1ome
wants to merge
6
commits into
henrik:master
Choose a base branch
from
m1ome:issue_19
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fixing issue #19 #30
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,76 @@ | ||
defmodule EnumTest do | ||
use ExUnit.Case | ||
|
||
alias ProgressBar.Utils | ||
import ExUnit.CaptureIO | ||
|
||
test "it works with enums" do | ||
test_pid = self() | ||
|
||
io = | ||
capture_io(fn -> | ||
list = ProgressBar.from_enum([1, 2, 3, 4, 5], fn _ -> send(test_pid, :fn_run) end) | ||
|
||
assert list == [1, 2, 3, 4, 5] | ||
end) | ||
|
||
assert split_bars(io) == [ | ||
"|", | ||
"|", | ||
"0%", | ||
"|===============", | ||
"|", | ||
"20%", | ||
"|=============================", | ||
"|", | ||
"40%", | ||
"|============================================", | ||
"|", | ||
"60%", | ||
"|==========================================================", | ||
"|", | ||
"80%", | ||
"|=========================================================================|", | ||
"100%" | ||
] | ||
|
||
for _ <- 1..5, do: assert_received(:fn_run) | ||
refute_received :fn_run | ||
end | ||
|
||
test "it works with streams" do | ||
io = | ||
capture_io(fn -> | ||
list = | ||
[1, 2, 3, 4, 5] | ||
|> ProgressBar.from_stream() | ||
|> Enum.into([]) | ||
|
||
assert list == [1, 2, 3, 4, 5] | ||
end) | ||
|
||
assert split_bars(io) == [ | ||
"|", | ||
"|", | ||
"0%", | ||
"|===============", | ||
"|", | ||
"20%", | ||
"|=============================", | ||
"|", | ||
"40%", | ||
"|============================================", | ||
"|", | ||
"60%", | ||
"|==========================================================", | ||
"|", | ||
"80%", | ||
"|=========================================================================|", | ||
"100%" | ||
] | ||
end | ||
|
||
defp split_bars(string) do | ||
string |> String.replace(Utils.ansi_prefix(), "\n") |> String.split() | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My Elixir is rusty (haven't written much in the past few years) and I never were super familiar with streams.
Is it reasonable to execute the stream here by counting the length? It was suggested in #19 that the length could be passed in, but I'm not sure in what situations you might know the length and also have a stream that you don't want to execute here. The user will need to execute it again after the
map
/each
below to get any output.cc @kelvinst if you remember or still have any specific use case around this where this detail would matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well thought. I can't think of a case where one would have the length of a stream before actually going through it. Maybe one would already go through the stream of another operation and already have its length, but then it does not make sense to attach a progress bar after that again, IDK.
Anyway, I think it's ok to get the length this way, we might just want to warn people that the Stream is going to be traversed to get its final length and print the %
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add this message to readme