2018-08-20 08:53:13 +02:00
|
|
|
package i18n
|
|
|
|
|
|
|
|
import (
|
2018-08-20 21:04:04 +02:00
|
|
|
"fmt"
|
2018-08-20 08:53:13 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2018-11-30 02:47:14 +02:00
|
|
|
// TestDetectLanguage is a function.
|
2018-08-20 21:04:04 +02:00
|
|
|
func TestDetectLanguage(t *testing.T) {
|
2018-08-20 08:53:13 +02:00
|
|
|
type scenario struct {
|
2018-08-20 21:04:04 +02:00
|
|
|
langDetector func() (string, error)
|
|
|
|
expected string
|
2018-08-20 08:53:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
scenarios := []scenario{
|
|
|
|
{
|
2018-08-20 21:04:04 +02:00
|
|
|
func() (string, error) {
|
|
|
|
return "", fmt.Errorf("An error occurred")
|
2018-08-20 08:53:13 +02:00
|
|
|
},
|
2018-08-20 21:04:04 +02:00
|
|
|
"C",
|
2018-08-20 08:53:13 +02:00
|
|
|
},
|
|
|
|
{
|
2018-08-20 21:04:04 +02:00
|
|
|
func() (string, error) {
|
|
|
|
return "en", nil
|
2018-08-20 08:53:13 +02:00
|
|
|
},
|
2018-08-20 21:04:04 +02:00
|
|
|
"en",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range scenarios {
|
|
|
|
assert.EqualValues(t, s.expected, detectLanguage(s.langDetector))
|
|
|
|
}
|
|
|
|
}
|