(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestWithTerminalEnv(t *testing.T) { |
| 11 | t.Parallel() |
| 12 | |
| 13 | defaultLocale := "C.UTF-8" |
| 14 | if runtime.GOOS == "darwin" { |
| 15 | defaultLocale = "UTF-8" |
| 16 | } |
| 17 | |
| 18 | tests := []struct { |
| 19 | name string |
| 20 | env []string |
| 21 | wantLCCTYPE string |
| 22 | wantLCCTYPESet bool |
| 23 | }{ |
| 24 | { |
| 25 | name: "adds locale when missing", |
| 26 | env: []string{"PATH=/bin"}, |
| 27 | wantLCCTYPE: defaultLocale, |
| 28 | wantLCCTYPESet: true, |
| 29 | }, |
| 30 | { |
| 31 | name: "adds locale when lang is not utf8", |
| 32 | env: []string{"LANG=C"}, |
| 33 | wantLCCTYPE: defaultLocale, |
| 34 | wantLCCTYPESet: true, |
| 35 | }, |
| 36 | { |
| 37 | name: "keeps utf8 lang", |
| 38 | env: []string{"LANG=C.UTF-8"}, |
| 39 | }, |
| 40 | { |
| 41 | name: "keeps unhyphenated utf8 lang", |
| 42 | env: []string{"LANG=C.UTF8"}, |
| 43 | }, |
| 44 | { |
| 45 | name: "keeps utf8 ctype", |
| 46 | env: []string{"LC_CTYPE=C.UTF-8"}, |
| 47 | wantLCCTYPE: "C.UTF-8", |
| 48 | wantLCCTYPESet: true, |
| 49 | }, |
| 50 | { |
| 51 | name: "overrides non utf8 ctype", |
| 52 | env: []string{"LANG=C.UTF-8", "LC_CTYPE=C"}, |
| 53 | wantLCCTYPE: defaultLocale, |
| 54 | wantLCCTYPESet: true, |
| 55 | }, |
| 56 | { |
| 57 | name: "keeps utf8 lc all", |
| 58 | env: []string{"LC_ALL=C.UTF-8"}, |
| 59 | }, |
| 60 | { |
| 61 | name: "preserves non empty lc all", |
| 62 | env: []string{"LC_ALL=C"}, |
| 63 | }, |
| 64 | { |
| 65 | name: "ignores empty lc all", |
| 66 | env: []string{"LC_ALL="}, |
| 67 | wantLCCTYPE: defaultLocale, |
nothing calls this directly
no test coverage detected