From c7db2be6d0f6fba020bf834fb0b3be210d2cc132 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Mon, 4 Nov 2024 18:49:04 +0100 Subject: [PATCH] Add test for note parsing --- backend/utils_test.go | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 backend/utils_test.go diff --git a/backend/utils_test.go b/backend/utils_test.go new file mode 100644 index 0000000..04e1b73 --- /dev/null +++ b/backend/utils_test.go @@ -0,0 +1,76 @@ +package main + +import ( + "testing" + "time" +) + +func TestParseNote(t *testing.T) { + data := `p:Мундиль +g:Культурные люди +d:2024-10-30 +Worgen balance druid +Came to orgrimmar trying to kill saurfang and killing people with <1m hp +18:04:24 > r:Myxich +Is very weak and scared +Has like 7M hp but refuses to fight +Refuses to fight anyone >1M hp that is +Tried hiding tried flying and failed` + note, err := ParseNote(data) + if err != nil { + t.Fatal(err) + } + if note.Player != "Мундиль" { + t.Errorf("Expected player to be Мундиль, got %s", note.Player) + } + if note.Guild != "Культурные люди" { + t.Errorf("Expected guild to be Культурные люди, got %s", note.Guild) + } + if note.Date.Format(time.DateOnly) != "2024-10-30" { + t.Errorf("Expected date to be 2024-10-30, got %s", note.Date.Format(time.DateOnly)) + } +} + +func TestParseNoteNoGuild(t *testing.T) { + data := `p:Kulmi +d:2024-10-30 +Came to orgrimmar trying to kill saurfang +Also killed some weak ass paladin, obviously interested in stomping noobs +Is one of those wpvp heroes, fully kitted out and shit` + note, err := ParseNote(data) + if err != nil { + t.Fatal(err) + } + if note.Player != "Kulmi" { + t.Errorf("Expected player to be Kulmi, got %s", note.Player) + } + if note.Guild != "" { + t.Errorf("Expected guild to be empty, got %s", note.Guild) + } + if note.Date.Format(time.DateOnly) != "2024-10-30" { + t.Errorf("Expected date to be 2024-10-30, got %s", note.Date.Format(time.DateOnly)) + } +} + +func TestParseNoteNoDate(t *testing.T) { + data := `p:Ashripper +g:The Inferno +Came to orgrimmar causing trouble +This is Criminallad and probably Criminaldad +There's nothing I can do to stop him and he knows it +He is deeply rooted with THE guild` + note, err := ParseNote(data) + if err != nil { + t.Fatal(err) + } + if note.Player != "Ashripper" { + t.Errorf("Expected player to be Ashripper, got %s", note.Player) + } + if note.Guild != "The Inferno" { + t.Errorf("Expected guild to be The Inferno, got %s", note.Guild) + } + now := time.Now() + if note.Date.Format(time.DateOnly) != now.Format(time.DateOnly) { + t.Errorf("Expected date to be %s got %s", now.Format(time.DateOnly), note.Date.Format(time.DateOnly)) + } +} \ No newline at end of file