-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0824a31
commit 3a2bcdc
Showing
5 changed files
with
72 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package adapter | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/reearth/reearthx/log" | ||
"github.com/stretchr/testify/assert" | ||
"golang.org/x/text/language" | ||
) | ||
|
||
func TestLang(t *testing.T) { | ||
|
||
// Default language for testing | ||
defaultLang := language.English // or set it to whatever your defaultLang is | ||
|
||
t.Run("Lang is provided and valid", func(t *testing.T) { | ||
lang := language.Japanese | ||
result := Lang(context.Background(), &lang) | ||
assert.Equal(t, "ja", result) | ||
}) | ||
|
||
t.Run("Lang is nil, context has valid lang", func(t *testing.T) { | ||
lang := language.French | ||
ctx := context.WithValue(context.Background(), contextLang, lang) | ||
result := Lang(ctx, nil) | ||
log.Infofc(ctx, "result: %s", result) | ||
assert.Equal(t, "fr", result) | ||
}) | ||
|
||
t.Run("Lang is nil, context lang is empty", func(t *testing.T) { | ||
ctx := context.WithValue(context.Background(), contextLang, language.Make("")) | ||
result := Lang(ctx, nil) | ||
assert.Equal(t, defaultLang.String(), result) | ||
}) | ||
|
||
t.Run("Lang is nil, context has no lang", func(t *testing.T) { | ||
result := Lang(context.Background(), nil) | ||
assert.Equal(t, defaultLang.String(), result) | ||
}) | ||
|
||
t.Run("Lang is root, context has no lang", func(t *testing.T) { | ||
rootLang := language.Und | ||
result := Lang(context.Background(), &rootLang) | ||
assert.Equal(t, defaultLang.String(), result) | ||
}) | ||
|
||
t.Run("Lang is french, context has no lang", func(t *testing.T) { | ||
lang := language.French | ||
result := Lang(context.Background(), &lang) | ||
assert.Equal(t, lang.String(), result) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters