diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
commit | b09c6d56832eb1718c07d74abf3bc6ae3fe4e030 (patch) | |
tree | d2caec2610d4ea887803ec9e9c3cd77136c448ba /dependencies/pkg/mod/github.com/mattn/go-runewidth@v0.0.12/runewidth_posix_test.go | |
parent | Initial commit. (diff) | |
download | icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.tar.xz icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.zip |
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dependencies/pkg/mod/github.com/mattn/go-runewidth@v0.0.12/runewidth_posix_test.go')
-rw-r--r-- | dependencies/pkg/mod/github.com/mattn/go-runewidth@v0.0.12/runewidth_posix_test.go | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/github.com/mattn/go-runewidth@v0.0.12/runewidth_posix_test.go b/dependencies/pkg/mod/github.com/mattn/go-runewidth@v0.0.12/runewidth_posix_test.go new file mode 100644 index 0000000..3c21c7e --- /dev/null +++ b/dependencies/pkg/mod/github.com/mattn/go-runewidth@v0.0.12/runewidth_posix_test.go @@ -0,0 +1,98 @@ +// +build !windows +// +build !js +// +build !appengine + +package runewidth + +import ( + "os" + "testing" +) + +type envVars struct { + lang string + lc_all string + lc_ctype string +} + +func saveEnv() envVars { + return envVars{ + lang: os.Getenv("LANG"), + lc_all: os.Getenv("LC_ALL"), + lc_ctype: os.Getenv("LC_CTYPE"), + } +} +func restoreEnv(env *envVars) { + os.Setenv("LANG", env.lang) + os.Setenv("LC_ALL", env.lc_all) + os.Setenv("LC_CTYPE", env.lc_ctype) +} + +func TestIsEastAsian(t *testing.T) { + testcases := []struct { + locale string + want bool + }{ + {"foo@cjk_narrow", false}, + {"foo@cjk", false}, + {"utf-8@cjk", false}, + {"ja_JP.CP932", true}, + } + + for _, tt := range testcases { + got := isEastAsian(tt.locale) + if got != tt.want { + t.Fatalf("isEastAsian(%q) should be %v", tt.locale, tt.want) + } + } +} + +func TestIsEastAsianLCCTYPE(t *testing.T) { + env := saveEnv() + defer restoreEnv(&env) + os.Setenv("LC_ALL", "") + + testcases := []struct { + lcctype string + want bool + }{ + {"ja_JP.UTF-8", true}, + {"C", false}, + {"POSIX", false}, + {"en_US.UTF-8", false}, + } + + for _, tt := range testcases { + os.Setenv("LC_CTYPE", tt.lcctype) + got := IsEastAsian() + if got != tt.want { + t.Fatalf("IsEastAsian() for LC_CTYPE=%v should be %v", tt.lcctype, tt.want) + } + } +} + +func TestIsEastAsianLANG(t *testing.T) { + env := saveEnv() + defer restoreEnv(&env) + os.Setenv("LC_ALL", "") + os.Setenv("LC_CTYPE", "") + + testcases := []struct { + lcctype string + want bool + }{ + {"ja_JP.UTF-8", true}, + {"C", false}, + {"POSIX", false}, + {"en_US.UTF-8", false}, + {"C.UTF-8", false}, + } + + for _, tt := range testcases { + os.Setenv("LANG", tt.lcctype) + got := IsEastAsian() + if got != tt.want { + t.Fatalf("IsEastAsian() for LANG=%v should be %v", tt.lcctype, tt.want) + } + } +} |