summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Makefile15
-rw-r--r--go.mod2
-rw-r--r--src/cmd/main.go4
-rw-r--r--src/lib.go16
-rw-r--r--tests/lib_test.go139
6 files changed, 102 insertions, 77 deletions
diff --git a/.gitignore b/.gitignore
index b03deb3..07707d5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
/*.bin
/tests/*.bin
-/doc/*.[0-9]
-/doc/*.3go
+/papod.db
diff --git a/Makefile b/Makefile
index be54efe..24efb25 100644
--- a/Makefile
+++ b/Makefile
@@ -42,8 +42,9 @@ derived-assets = \
tests/lib_test.bin \
side-assets = \
- papo.public.socket \
- papo.command.socket \
+ papod.public.socket \
+ papod.command.socket \
+ papod.db \
wscat.socket \
glaze.socket \
@@ -116,13 +117,13 @@ uninstall:
'$(DESTDIR)$(SRCDIR)' \
-run-papo: all
- rm -f papo.public.socket papo.command.socket
+run-papod: $(NAME).bin
+ rm -f papod.public.socket papod.command.socket
./$(NAME).bin
run-wscat:
rm -f wscat.socket
- wscat wscat.socket papo.public.socket
+ wscat wscat.socket papod.public.socket
run-glaze:
rm -f glaze.socket
@@ -132,11 +133,11 @@ run-binder-web:
binder localhost:4443 glaze.socket
run-binder-ircd:
- binder localhost:6667 papo.public.socket
+ binder localhost:6667 papod.public.socket
## Run it locally, alongside its helper programs.
run: all
- for c in wscat papo binder-web binder-ircd glaze; do \
+ for c in wscat papod binder-web binder-ircd glaze; do \
$(MAKE) run-$$c & \
done; \
wait
diff --git a/go.mod b/go.mod
index d593373..36de052 100644
--- a/go.mod
+++ b/go.mod
@@ -1,4 +1,4 @@
-module euandre.org/papo
+module euandre.org/papod
go 1.21.5
diff --git a/src/cmd/main.go b/src/cmd/main.go
index 2f78c4d..8e80599 100644
--- a/src/cmd/main.go
+++ b/src/cmd/main.go
@@ -1,7 +1,7 @@
package main
-import "euandre.org/papo/src"
+import "euandre.org/papod/src"
func main() {
- papo.Main()
+ papod.Main()
}
diff --git a/src/lib.go b/src/lib.go
index 8b41da0..cc4b2ea 100644
--- a/src/lib.go
+++ b/src/lib.go
@@ -1,4 +1,4 @@
-package papo
+package papod
import (
"bufio"
@@ -259,14 +259,14 @@ func SetHostname() {
}
func SetEnvironmentVariables() {
- Version = os.Getenv("PAPO_VERSION")
+ Version = os.Getenv("PAPOD_VERSION")
if Version == "" {
- Version = "PAPO-VERSION-UNKNOWN"
+ Version = "PAPOD-VERSION-UNKNOWN"
}
- Colour = os.Getenv("PAPO_COLOUR")
+ Colour = os.Getenv("PAPOD_COLOUR")
if Colour == "" {
- Colour = "PAPO-COLOUR-UNKNOWN"
+ Colour = "PAPOD-COLOUR-UNKNOWN"
}
}
@@ -324,17 +324,17 @@ func BuildContext(databasePath string) *Context {
var (
databasePath = flag.String(
"f",
- "papo.db",
+ "papod.db",
"The path to the database file",
)
publicSocketPath = flag.String(
"s",
- "papo.public.socket",
+ "papod.public.socket",
"The path to the socket that handles the public traffic",
)
commandSocketPath = flag.String(
"S",
- "papo.command.socket",
+ "papod.command.socket",
"The path to the private IPC commands socket",
)
)
diff --git a/tests/lib_test.go b/tests/lib_test.go
index fdc663b..1ec2208 100644
--- a/tests/lib_test.go
+++ b/tests/lib_test.go
@@ -1,4 +1,4 @@
-package papo_test
+package papod_test
import (
"bufio"
@@ -6,7 +6,7 @@ import (
"strings"
"testing"
- "euandre.org/papo/src"
+ "euandre.org/papod/src"
)
@@ -67,7 +67,7 @@ func TestSplitOnCRLF(t *testing.T) {
for i, entry := range table {
var given []string
scanner := bufio.NewScanner(strings.NewReader(entry.input))
- scanner.Split(papo.SplitOnCRLF)
+ scanner.Split(papod.SplitOnCRLF)
for scanner.Scan() {
given = append(given, scanner.Text())
}
@@ -98,7 +98,7 @@ func TestSplitOnRawMessage(t *testing.T) {
for i, entry := range table {
var given []string
scanner := bufio.NewScanner(strings.NewReader(entry.input))
- scanner.Split(papo.SplitOnRawMessage)
+ scanner.Split(papod.SplitOnRawMessage)
for scanner.Scan() {
given = append(given, scanner.Text())
}
@@ -112,180 +112,180 @@ func TestSplitOnRawMessage(t *testing.T) {
func TestParseMessageParams(t *testing.T) {
type tableT struct {
input string
- expected papo.MessageParams
+ expected papod.MessageParams
}
table := []tableT {
{
"",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { },
Trailing: "",
},
},
{
" ",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { },
Trailing: "",
},
},
{
" :",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { },
Trailing: "",
},
},
{
" : ",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { },
Trailing: " ",
},
},
{
": ",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { ":" },
Trailing: "",
},
},
{
": ",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { ":" },
Trailing: "",
},
},
{
" : ",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { },
Trailing: " ",
},
},
{
" :",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { },
Trailing: "",
},
},
{
" :",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { },
Trailing: "",
},
},
{
"a",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a" },
Trailing: "",
},
},
{
"ab",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "ab" },
Trailing: "",
},
},
{
"a b",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b" },
Trailing: "",
},
},
{
"a b c",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b", "c" },
Trailing: "",
},
},
{
"a b:c",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b:c" },
Trailing: "",
},
},
{
"a b:c:",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b:c:" },
Trailing: "",
},
},
{
"a b :c",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b" },
Trailing: "c",
},
},
{
"a b :c:",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b" },
Trailing: "c:",
},
},
{
"a b :c ",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b" },
Trailing: "c ",
},
},
{
"a b : c",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b" },
Trailing: " c",
},
},
{
"a b : c ",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b" },
Trailing: " c ",
},
},
{
"a b : c :",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b" },
Trailing: " c :",
},
},
{
"a b : c : ",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b" },
Trailing: " c : ",
},
},
{
"a b : c :d",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b" },
Trailing: " c :d",
},
},
{
"a b : c :d ",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b" },
Trailing: " c :d ",
},
},
{
"a b : c : d ",
- papo.MessageParams {
+ papod.MessageParams {
Middle: []string { "a", "b" },
Trailing: " c : d ",
},
@@ -293,23 +293,23 @@ func TestParseMessageParams(t *testing.T) {
}
for i, entry := range table {
- given := papo.ParseMessageParams(entry.input)
+ given := papod.ParseMessageParams(entry.input)
assertEqualI(t, i, given, entry.expected)
}
}
func TestParseMessage(t *testing.T) {
- type tableT struct {
+ type tableTOK struct {
input string
- expected papo.Message
+ expected papod.Message
}
- table := []tableT {
+ tableOK := []tableTOK {
{
"NICK joebloe ",
- papo.Message {
+ papod.Message {
Prefix: "",
Command: "NICK",
- Params: papo.MessageParams {
+ Params: papod.MessageParams {
Middle: []string { "joebloe" },
Trailing: "",
},
@@ -318,10 +318,10 @@ func TestParseMessage(t *testing.T) {
},
{
"USER joebloe 0.0.0.0 joe :Joe Bloe",
- papo.Message {
+ papod.Message {
Prefix: "",
Command: "USER",
- Params: papo.MessageParams {
+ Params: papod.MessageParams {
Middle: []string {
"joebloe", "0.0.0.0", "joe",
},
@@ -332,10 +332,10 @@ func TestParseMessage(t *testing.T) {
},
{
":pre USER joebloe 0.0.0.0 joe :Joe Bloe",
- papo.Message {
+ papod.Message {
Prefix: "pre",
Command: "USER",
- Params: papo.MessageParams {
+ Params: papod.MessageParams {
Middle: []string {
"joebloe", "0.0.0.0", "joe",
},
@@ -346,10 +346,10 @@ func TestParseMessage(t *testing.T) {
},
{
":pre USER joebloe 0.0.0.0 joe : Joe Bloe ",
- papo.Message {
+ papod.Message {
Prefix: "pre",
Command: "USER",
- Params: papo.MessageParams {
+ Params: papod.MessageParams {
Middle: []string {
"joebloe", "0.0.0.0", "joe",
},
@@ -360,10 +360,10 @@ func TestParseMessage(t *testing.T) {
},
{
":pre USER joebloe: 0:0:0:0 joe::a: : Joe Bloe ",
- papo.Message {
+ papod.Message {
Prefix: "pre",
Command: "USER",
- Params: papo.MessageParams {
+ Params: papod.MessageParams {
Middle: []string {
"joebloe:", "0:0:0:0", "joe::a:",
},
@@ -374,10 +374,10 @@ func TestParseMessage(t *testing.T) {
},
{
":pre USER :Joe Bloe",
- papo.Message {
+ papod.Message {
Prefix: "pre",
Command: "USER",
- Params: papo.MessageParams {
+ Params: papod.MessageParams {
Middle: []string { },
Trailing: "Joe Bloe",
},
@@ -386,10 +386,10 @@ func TestParseMessage(t *testing.T) {
},
{
":pre USER : Joe Bloe",
- papo.Message {
+ papod.Message {
Prefix: "pre",
Command: "USER",
- Params: papo.MessageParams {
+ Params: papod.MessageParams {
Middle: []string { },
Trailing: " Joe Bloe",
},
@@ -398,10 +398,10 @@ func TestParseMessage(t *testing.T) {
},
{
":pre USER : Joe Bloe",
- papo.Message {
+ papod.Message {
Prefix: "pre",
Command: "USER",
- Params: papo.MessageParams {
+ Params: papod.MessageParams {
Middle: []string { },
Trailing: " Joe Bloe",
},
@@ -410,10 +410,10 @@ func TestParseMessage(t *testing.T) {
},
{
":pre USER : ",
- papo.Message {
+ papod.Message {
Prefix: "pre",
Command: "USER",
- Params: papo.MessageParams {
+ Params: papod.MessageParams {
Middle: []string { },
Trailing: " ",
},
@@ -422,10 +422,10 @@ func TestParseMessage(t *testing.T) {
},
{
":pre USER :",
- papo.Message {
+ papod.Message {
Prefix: "pre",
Command: "USER",
- Params: papo.MessageParams {
+ Params: papod.MessageParams {
Middle: []string { },
Trailing: "",
},
@@ -434,10 +434,35 @@ func TestParseMessage(t *testing.T) {
},
}
- for i, entry := range table {
- parsed, err := papo.ParseMessage(entry.input)
+ for i, entry := range tableOK {
+ given, err := papod.ParseMessage(entry.input)
errorIf(t, err)
- given := parsed
+ assertEqualI(t, i, given, entry.expected)
+ }
+
+
+ type tableErrorT struct {
+ input string
+ expected error
+ }
+ parseErr := errors.New("Can't parse message")
+ tableError := []tableErrorT {
+ {
+ ":pre",
+ parseErr,
+ },
+ {
+ ": pre",
+ parseErr,
+ },
+ {
+ ":pre N1CK",
+ parseErr,
+ },
+ }
+
+ for i, entry := range tableError {
+ _, given := papod.ParseMessage(entry.input)
assertEqualI(t, i, given, entry.expected)
}
}