summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/cloudfoundry/jibber_jabber/jibber_jabber_unix_test.go
blob: a5e3074a2ec3e79f7f38c62aa943d08d934ed787 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// +build darwin freebsd linux netbsd openbsd

package jibber_jabber_test

import (
	"os"

	. "github.com/cloudfoundry/jibber_jabber"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Unix", func() {
	AfterEach(func() {
		os.Setenv("LC_ALL", "")
		os.Setenv("LANG", "en_US.UTF-8")
	})

	Describe("#DetectIETF", func() {
		Context("Returns IETF encoded locale", func() {
			It("should return the locale set to LC_ALL", func() {
				os.Setenv("LC_ALL", "fr_FR.UTF-8")
				result, _ := DetectIETF()
				Ω(result).Should(Equal("fr-FR"))
			})

			It("should return the locale set to LANG if LC_ALL isn't set", func() {
				os.Setenv("LANG", "fr_FR.UTF-8")

				result, _ := DetectIETF()
				Ω(result).Should(Equal("fr-FR"))
			})

			It("should return an error if it cannot detect a locale", func() {
				os.Setenv("LANG", "")

				_, err := DetectIETF()
				Ω(err.Error()).Should(Equal(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE))
			})
		})

		Context("when the locale is simply 'fr'", func() {
			BeforeEach(func() {
				os.Setenv("LANG", "fr")
			})

			It("should return the locale without a territory", func() {
				language, err := DetectIETF()
				Ω(err).ShouldNot(HaveOccurred())
				Ω(language).Should(Equal("fr"))
			})
		})
	})

	Describe("#DetectLanguage", func() {
		Context("Returns encoded language", func() {
			It("should return the language set to LC_ALL", func() {
				os.Setenv("LC_ALL", "fr_FR.UTF-8")
				result, _ := DetectLanguage()
				Ω(result).Should(Equal("fr"))
			})

			It("should return the language set to LANG if LC_ALL isn't set", func() {
				os.Setenv("LANG", "fr_FR.UTF-8")

				result, _ := DetectLanguage()
				Ω(result).Should(Equal("fr"))
			})

			It("should return an error if it cannot detect a language", func() {
				os.Setenv("LANG", "")

				_, err := DetectLanguage()
				Ω(err.Error()).Should(Equal(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE))
			})
		})
	})

	Describe("#DetectTerritory", func() {
		Context("Returns encoded territory", func() {
			It("should return the territory set to LC_ALL", func() {
				os.Setenv("LC_ALL", "fr_FR.UTF-8")
				result, _ := DetectTerritory()
				Ω(result).Should(Equal("FR"))
			})

			It("should return the territory set to LANG if LC_ALL isn't set", func() {
				os.Setenv("LANG", "fr_FR.UTF-8")

				result, _ := DetectTerritory()
				Ω(result).Should(Equal("FR"))
			})

			It("should return an error if it cannot detect a territory", func() {
				os.Setenv("LANG", "")

				_, err := DetectTerritory()
				Ω(err.Error()).Should(Equal(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE))
			})
		})
	})

})