From 4c257f70165e56f5b00d6bc46766a1464ee06d57 Mon Sep 17 00:00:00 2001 From: Jan Hruban Date: Tue, 14 May 2024 10:37:02 +0200 Subject: [PATCH] Extend test for log-parser 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. --- .../log-parser/test/log_parser_test.exs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/exercises/concept/log-parser/test/log_parser_test.exs b/exercises/concept/log-parser/test/log_parser_test.exs index e87583247a..ba11bde364 100644 --- a/exercises/concept/log-parser/test/log_parser_test.exs +++ b/exercises/concept/log-parser/test/log_parser_test.exs @@ -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