Add test for note parsing

This commit is contained in:
2024-11-04 18:49:04 +01:00
parent 8346e8cd3a
commit c7db2be6d0

76
backend/utils_test.go Normal file
View File

@@ -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))
}
}