github.com/arunkumar7540/cli@v6.45.0+incompatible/command/flag/locale_test.go (about)

     1  package flag_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/command/flag"
     5  	flags "github.com/jessevdk/go-flags"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/ginkgo/extensions/table"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("Locale", func() {
    12  	var locale Locale
    13  
    14  	Describe("Complete", func() {
    15  		DescribeTable("returns list of completions",
    16  			func(prefix string, matches []flags.Completion) {
    17  				completions := locale.Complete(prefix)
    18  				Expect(completions).To(ConsistOf(matches))
    19  			},
    20  			Entry("completes to 'en-US' and 'es-ES' when passed 'e'", "e",
    21  				[]flags.Completion{{Item: "es-ES"}, {Item: "en-US"}}),
    22  			Entry("completes to 'en-US' when passed 'en_'", "en_",
    23  				[]flags.Completion{{Item: "en-US"}}),
    24  			Entry("completes to 'en-US' when passed 'eN_'", "eN_",
    25  				[]flags.Completion{{Item: "en-US"}}),
    26  			Entry("returns CLEAR, de-DE, en-US, es-ES, fr-FR, it-IT, ja-JP, ko-KR, pt-BR, zh-Hans, zh-Hant when passed nothing", "",
    27  				[]flags.Completion{{Item: "CLEAR"}, {Item: "de-DE"}, {Item: "en-US"}, {Item: "es-ES"}, {Item: "fr-FR"}, {Item: "it-IT"}, {Item: "ja-JP"}, {Item: "ko-KR"}, {Item: "pt-BR"}, {Item: "zh-Hans"}, {Item: "zh-Hant"}}),
    28  			Entry("completes to nothing when passed 'wut'", "wut",
    29  				[]flags.Completion{}),
    30  		)
    31  	})
    32  
    33  	Describe("UnmarshalFlag", func() {
    34  		BeforeEach(func() {
    35  			locale = Locale{}
    36  		})
    37  
    38  		It("accepts en-us", func() {
    39  			err := locale.UnmarshalFlag("en-us")
    40  			Expect(err).ToNot(HaveOccurred())
    41  			Expect(locale.Locale).To(Equal("en-US"))
    42  		})
    43  
    44  		It("accepts en_us", func() {
    45  			err := locale.UnmarshalFlag("en_us")
    46  			Expect(err).ToNot(HaveOccurred())
    47  			Expect(locale.Locale).To(Equal("en-US"))
    48  		})
    49  
    50  		It("accepts ja-jp", func() {
    51  			err := locale.UnmarshalFlag("ja-jp")
    52  			Expect(err).ToNot(HaveOccurred())
    53  			Expect(locale.Locale).To(Equal("ja-JP"))
    54  		})
    55  
    56  		It("errors on anything else", func() {
    57  			err := locale.UnmarshalFlag("I AM A BANANANANANANANANAE")
    58  			Expect(err).To(MatchError(&flags.Error{
    59  				Type:    flags.ErrRequired,
    60  				Message: `LOCALE must be CLEAR, de-DE, en-US, es-ES, fr-FR, it-IT, ja-JP, ko-KR, pt-BR, zh-Hans, zh-Hant`,
    61  			}))
    62  			Expect(locale.Locale).To(BeEmpty())
    63  		})
    64  	})
    65  })