github.com/everlongproject/i18n4go@v0.2.7-0.20201028180611-670cbaceaa6b/integration/merge_strings/d_option_test.go (about) 1 package merge_strings_test 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 8 . "github.com/Liam-Williams/i18n4go/integration/test_helpers" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("merge-strings -d dirName", func() { 14 var ( 15 fixturesPath string 16 inputFilesPath string 17 expectedFilesPath string 18 ) 19 20 BeforeEach(func() { 21 _, err := os.Getwd() 22 Ω(err).ShouldNot(HaveOccurred()) 23 24 fixturesPath = filepath.Join("..", "..", "test_fixtures", "merge_strings") 25 inputFilesPath = filepath.Join(fixturesPath, "d_option", "input_files") 26 expectedFilesPath = filepath.Join(fixturesPath, "d_option", "expected_output") 27 }) 28 29 Context("can combine multiple language files", func() { 30 Context("merging en files in input_files path", func() { 31 BeforeEach(func() { 32 session := Runi18n("-c", "merge-strings", "-v", "-d", filepath.Join(inputFilesPath), "--source-language", "en") 33 Ω(session.ExitCode()).Should(Equal(0)) 34 }) 35 36 AfterEach(func() { 37 RemoveAllFiles( 38 GetFilePath(inputFilesPath, "en.all.json"), 39 ) 40 }) 41 42 It("creates an en.all.json that contains translations from both files", func() { 43 CompareExpectedToGeneratedTraslationJson( 44 GetFilePath(expectedFilesPath, "en.all.json"), 45 GetFilePath(inputFilesPath, "en.all.json"), 46 ) 47 }) 48 49 It("creates an en.all.json for which the translation strings order are stable", func() { 50 expectedFilePath := GetFilePath(expectedFilesPath, "en.all.json") 51 actualFilePath := GetFilePath(inputFilesPath, "en.all.json") 52 53 expectedBytes, err := ioutil.ReadFile(expectedFilePath) 54 Ω(err).Should(BeNil()) 55 Ω(expectedBytes).ShouldNot(BeNil()) 56 57 actualBytes, err := ioutil.ReadFile(actualFilePath) 58 Ω(err).Should(BeNil()) 59 Ω(actualBytes).ShouldNot(BeNil()) 60 61 Ω(string(expectedBytes)).Should(Equal(string(actualBytes))) 62 }) 63 }) 64 65 Context("merging en files in input_files/reordered path", func() { 66 BeforeEach(func() { 67 session := Runi18n("-c", "merge-strings", "-v", "-d", filepath.Join(inputFilesPath, "reordered"), "--source-language", "en") 68 Ω(session.ExitCode()).Should(Equal(0)) 69 }) 70 71 AfterEach(func() { 72 RemoveAllFiles( 73 GetFilePath(filepath.Join(inputFilesPath, "reordered"), "en.all.json"), 74 ) 75 }) 76 77 It("creates an en.all.json keeping the stable order", func() { 78 expectedFilePath := GetFilePath(expectedFilesPath, "en.all.json") 79 actualFilePath := GetFilePath(filepath.Join(inputFilesPath, "reordered"), "en.all.json") 80 81 expectedBytes, err := ioutil.ReadFile(expectedFilePath) 82 Ω(err).Should(BeNil()) 83 Ω(expectedBytes).ShouldNot(BeNil()) 84 85 actualBytes, err := ioutil.ReadFile(actualFilePath) 86 Ω(err).Should(BeNil()) 87 Ω(actualBytes).ShouldNot(BeNil()) 88 89 Ω(string(expectedBytes)).Should(Equal(string(actualBytes))) 90 }) 91 }) 92 }) 93 })