1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-02 15:06:23 -07:00
gochan/pkg/posting/post_test.go

67 lines
1.3 KiB
Go

package posting
import (
"testing"
"github.com/gochan-org/gochan/pkg/config"
"github.com/stretchr/testify/assert"
)
type parseNameTestCase struct {
nameAndTrip string
expectedName string
expectedTripcode string
}
func TestParseName(t *testing.T) {
config.SetVersion("4.1")
boardConfig := config.GetBoardConfig("test")
boardConfig.ReservedTrips = map[string]string{
"reserved": "TripOut",
}
config.SetBoardConfig("test", boardConfig)
config.SetRandomSeed("lol")
testCases := []parseNameTestCase{
{
nameAndTrip: "Name#Trip",
expectedName: "Name",
expectedTripcode: "piec1MorXg",
},
{
nameAndTrip: "#Trip",
expectedName: "",
expectedTripcode: "piec1MorXg",
},
{
nameAndTrip: "Name",
expectedName: "Name",
},
{
nameAndTrip: "Name#",
expectedName: "Name",
},
{
nameAndTrip: "#",
expectedName: "",
},
{
nameAndTrip: "Name##reserved",
expectedName: "Name",
expectedTripcode: "TripOut",
},
{
nameAndTrip: "Name##notReserved",
expectedName: "Name",
expectedTripcode: "MDlhNmNmYj",
},
}
for _, tC := range testCases {
t.Run(tC.nameAndTrip, func(t *testing.T) {
name, trip := ParseName(tC.nameAndTrip, boardConfig)
assert.Equal(t, tC.expectedName, name)
assert.Equal(t, tC.expectedTripcode, trip)
})
}
}