Skip to content

Commit

Permalink
Extend test for log-parser
Browse files Browse the repository at this point in the history
I have seen several "Community Solutions" for this exercise which were
not correct:

  def valid_line?(line) do
    line =~ ~r/^\[DEBUG|INFO|WARNING|ERROR\]/
  end

This would yield wrong result for some lines, which are now covered by
the test.
  • Loading branch information
hrubi committed May 14, 2024
1 parent 013e423 commit 4c257f7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion exercises/concept/log-parser/test/log_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,31 @@ defmodule LogParserTest do
end

@tag task_id: 1
test "level must be wrapped in square brackets" do
test "DEBUG level must be wrapped in square brackets" do
assert LogParser.valid_line?("DEBUG something really bad happened") == false
assert LogParser.valid_line?("[DEBUG something really bad happened") == false
assert LogParser.valid_line?("DEBUG] something really bad happened") == false
end

@tag task_id: 1
test "INFO level must be wrapped in square brackets" do
assert LogParser.valid_line?("INFO something really bad happened") == false
assert LogParser.valid_line?("[INFO something really bad happened") == false
assert LogParser.valid_line?("INFO] something really bad happened") == false
end

@tag task_id: 1
test "WARNING level must be wrapped in square brackets" do
assert LogParser.valid_line?("WARNING something really bad happened") == false
assert LogParser.valid_line?("[WARNING something really bad happened") == false
assert LogParser.valid_line?("WARNING] something really bad happened") == false
end

@tag task_id: 1
test "ERROR level must be wrapped in square brackets" do
assert LogParser.valid_line?("ERROR something really bad happened") == false
assert LogParser.valid_line?("[ERROR something really bad happened") == false
assert LogParser.valid_line?("ERROR] something really bad happened") == false
end

@tag task_id: 1
Expand Down

0 comments on commit 4c257f7

Please sign in to comment.