github.com/blp1526/goa@v1.4.0/goagen/codegen/helpers_test.go (about) 1 package codegen_test 2 3 import ( 4 "os" 5 6 "github.com/goadesign/goa/goagen/codegen" 7 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("Helpers", func() { 13 Describe("KebabCase", func() { 14 It("should change uppercase letters to lowercase letters", func() { 15 Expect(codegen.KebabCase("test-B")).To(Equal("test-b")) 16 Expect(codegen.KebabCase("teste")).To(Equal("teste")) 17 }) 18 19 It("should not add a dash before an abbreviation or acronym", func() { 20 Expect(codegen.KebabCase("testABC")).To(Equal("testabc")) 21 }) 22 23 It("should add a dash before a title", func() { 24 Expect(codegen.KebabCase("testAa")).To(Equal("test-aa")) 25 Expect(codegen.KebabCase("testAbc")).To(Equal("test-abc")) 26 }) 27 28 It("should replace underscores to dashes", func() { 29 Expect(codegen.KebabCase("test_cA")).To(Equal("test-ca")) 30 Expect(codegen.KebabCase("test_D")).To(Equal("test-d")) 31 }) 32 }) 33 34 Describe("CommandLine", func() { 35 oldGOPATH, oldArgs := os.Getenv("GOPATH"), os.Args 36 BeforeEach(func() { 37 os.Setenv("GOPATH", "/xx") 38 }) 39 AfterEach(func() { 40 os.Setenv("GOPATH", oldGOPATH) 41 os.Args = oldArgs 42 }) 43 44 It("should not touch free arguments", func() { 45 os.Args = []string{"foo", "/xx/bar/xx/42"} 46 47 Expect(codegen.CommandLine()).To(Equal("$ foo /xx/bar/xx/42")) 48 }) 49 50 It("should replace GOPATH one match only in a long option", func() { 51 os.Args = []string{"foo", "--opt=/xx/bar/xx/42"} 52 53 Expect(codegen.CommandLine()).To(Equal("$ foo\n\t--opt=$(GOPATH)/bar/xx/42")) 54 }) 55 56 It("should not replace GOPATH if a match is not at the beginning of a long option", func() { 57 os.Args = []string{"foo", "--opt=/bar/xx/42"} 58 59 Expect(codegen.CommandLine()).To(Equal("$ foo\n\t--opt=/bar/xx/42")) 60 }) 61 }) 62 })