This repository has been archived on 2024-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
core-old/internal/tw/server_config_test.go
Dawid Wysokiński 95641c8513
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
fix: strconv.ParseInt: parsing "On": invalid syntax - ServerConfigGame
2022-12-25 11:48:33 +01:00

66 lines
1.2 KiB
Go

package tw_test
import (
"encoding/xml"
"errors"
"testing"
"gitea.dwysokinski.me/twhelp/core/internal/tw"
"github.com/stretchr/testify/assert"
)
func TestKnightNewItems_UnmarshalXML(t *testing.T) {
t.Parallel()
tests := []struct {
v string
expected tw.KnightNewItems
expectedErr error
}{
{
v: "<knight_new_items/>",
expected: 0,
},
{
v: "<knight_new_items>Off</knight_new_items>",
expected: 0,
},
{
v: "<knight_new_items>0</knight_new_items>",
expected: 0,
},
{
v: "<knight_new_items>On</knight_new_items>",
expected: 1,
},
{
v: "<knight_new_items>ON</knight_new_items>",
expected: 1,
},
{
v: "<knight_new_items>on</knight_new_items>",
expected: 1,
},
{
v: "<knight_new_items>1</knight_new_items>",
expected: 1,
},
{
v: "<knight_new_items>invalid value</knight_new_items>",
expectedErr: errors.New(`KnightNewItems: parsing "invalid value": invalid syntax`),
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.v, func(t *testing.T) {
t.Parallel()
var res tw.KnightNewItems
assert.Equal(t, xml.Unmarshal([]byte(tt.v), &res), tt.expectedErr)
assert.Equal(t, tt.expected, res)
})
}
}