2018-09-22 03:53:29 +02:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package locale // import "miniflux.app/locale"
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestParserWithInvalidData(t *testing.T) {
|
2018-09-23 00:04:55 +02:00
|
|
|
_, err := parseTranslationDict(`{`)
|
2018-09-22 03:53:29 +02:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal(`An error should be returned when parsing invalid data`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParser(t *testing.T) {
|
2018-09-23 00:04:55 +02:00
|
|
|
translations, err := parseTranslationDict(`{"k": "v"}`)
|
2018-09-22 03:53:29 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(`Unexpected parsing error: %v`, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if translations == nil {
|
|
|
|
t.Fatal(`Translations should not be nil`)
|
|
|
|
}
|
|
|
|
|
|
|
|
value, found := translations["k"]
|
|
|
|
if !found {
|
|
|
|
t.Fatal(`The translation should contains the defined key`)
|
|
|
|
}
|
|
|
|
|
|
|
|
if value.(string) != "v" {
|
|
|
|
t.Fatal(`The translation key should contains the defined value`)
|
|
|
|
}
|
|
|
|
}
|