residentsleeper/parser_test.go

49 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
"bufio"
"os"
"regexp"
"testing"
)
type regexpTest struct {
input string
re *regexp.Regexp
}
func Test_Regexp(t *testing.T) {
inputs := map[string]regexpTest{
"join": {"[19:22:13] [Server thread/INFO]: notch joined the game", joinedRegexp},
"leave": {"[19:16:13] [Server thread/INFO]: notch left the game", leftRegexp},
"message": {"[19:37:13] [Server thread/INFO]: <notch> hello", messageRegexp},
"spigotMessage": {"[23:32:42] [Async Chat Thread - #2/INFO]: <ccatss> zzz", messageRegexp},
"rcon": {"[16:46:42] [RCON Listener #1/INFO]: RCON running on 0.0.0.0:25575", rconRegexp},
}
for key, re := range inputs {
if !re.re.MatchString(re.input) {
t.Fatal("Regexp for", key, "did not match")
}
}
}
func Test_EndCharacters(t *testing.T) {
f, err := os.Open("latest.log")
if err != nil {
t.Fatal("Log file not found")
}
defer f.Close()
scanner := bufio.NewScanner(f)
if !scanner.Scan() {
t.Fatal("Log empty")
}
t.Log(scanner.Text())
t.Log(scanner.Bytes())
}