gitee.com/Aodao/i18n4go.git@v0.2.7-0.20160826202043-6224c7d27921/integration/verify_strings/f_option_test.go (about)

     1  package verify_strings_test
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	. "github.com/maximilien/i18n4go/integration/test_helpers"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("verify-strings -f fileName --languages \"[lang,?]+\"", func() {
    13  	var (
    14  		inputFilesPath    string
    15  		expectedFilesPath string
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		fixturesPath := filepath.Join("..", "..", "test_fixtures", "verify_strings")
    20  		inputFilesPath = filepath.Join(fixturesPath, "f_option", "input_files")
    21  		expectedFilesPath = filepath.Join(fixturesPath, "f_option", "expected_output")
    22  	})
    23  
    24  	Context("valid input file provided", func() {
    25  		Context("using --source-language", func() {
    26  			Context("passes verifications", func() {
    27  				BeforeEach(func() {
    28  					session := Runi18n("-c", "verify-strings", "-v", "-f", filepath.Join(inputFilesPath, "quota.go.en.json"), "--languages", "\"fr,zh_CN\"", "-o", expectedFilesPath, "--source-language", "en")
    29  					Ω(session.ExitCode()).Should(Equal(0))
    30  				})
    31  
    32  				It("with language file with valid keys", func() {
    33  					_, err := os.Stat(GetFilePath(inputFilesPath, "quota.go.en.json.missing.diff"))
    34  					Ω(os.IsNotExist(err)).Should(Equal(true))
    35  
    36  					_, err = os.Stat(GetFilePath(inputFilesPath, "quota.go.en.json.extra.diff"))
    37  					Ω(os.IsNotExist(err)).Should(Equal(true))
    38  				})
    39  			})
    40  		})
    41  
    42  		Context("not using --source-language", func() {
    43  			Context("passes verifications", func() {
    44  				BeforeEach(func() {
    45  					session := Runi18n("-c", "verify-strings", "-v", "-f", filepath.Join(inputFilesPath, "quota.go.en.json"), "--languages", "\"fr,zh_CN\"", "-o", expectedFilesPath)
    46  					Ω(session.ExitCode()).Should(Equal(0))
    47  				})
    48  
    49  				It("with language file with valid keys", func() {
    50  					_, err := os.Stat(GetFilePath(inputFilesPath, "quota.go.fr.json.missing.diff.json"))
    51  					Ω(os.IsNotExist(err)).Should(Equal(true))
    52  
    53  					_, err = os.Stat(GetFilePath(inputFilesPath, "quota.go.fr.json.missing.diff.json"))
    54  					Ω(os.IsNotExist(err)).Should(Equal(true))
    55  
    56  					_, err = os.Stat(GetFilePath(inputFilesPath, "quota.go.zh_CN.json.extra.diff.json"))
    57  					Ω(os.IsNotExist(err)).Should(Equal(true))
    58  
    59  					_, err = os.Stat(GetFilePath(inputFilesPath, "quota.go.zh_CN.json.extra.diff.json"))
    60  					Ω(os.IsNotExist(err)).Should(Equal(true))
    61  				})
    62  			})
    63  		})
    64  
    65  		Context("fails verification", func() {
    66  			Context("with one language file", func() {
    67  				Context("with missing keys", func() {
    68  					BeforeEach(func() {
    69  						session := Runi18n("-c", "verify-strings", "-v", "-f", filepath.Join(inputFilesPath, "quota.go.en.json"), "--languages", "\"de\"", "-o", expectedFilesPath, "--source-language", "en")
    70  						Ω(session.ExitCode()).Should(Equal(1))
    71  					})
    72  
    73  					AfterEach(func() {
    74  						RemoveAllFiles(
    75  							GetFilePath(expectedFilesPath, "quota.go.de.json.missing.diff.json"),
    76  						)
    77  					})
    78  
    79  					It("generates missing diff file", func() {
    80  						fileInfo, err := os.Stat(GetFilePath(expectedFilesPath, "quota.go.de.json.missing.diff.json"))
    81  						Ω(err).Should(BeNil())
    82  						Ω(fileInfo.Name()).Should(Equal("quota.go.de.json.missing.diff.json"))
    83  					})
    84  				})
    85  
    86  				Context("with missing and extra keys", func() {
    87  					BeforeEach(func() {
    88  						session := Runi18n("-c", "verify-strings", "-v", "-f", filepath.Join(inputFilesPath, "quota.go.en.json"), "--languages", "\"af\"", "-o", expectedFilesPath, "--source-language", "en")
    89  						Ω(session.ExitCode()).Should(Equal(1))
    90  					})
    91  
    92  					AfterEach(func() {
    93  						RemoveAllFiles(
    94  							GetFilePath(expectedFilesPath, "quota.go.af.json.missing.diff.json"),
    95  							GetFilePath(expectedFilesPath, "quota.go.af.json.extra.diff.json"),
    96  						)
    97  					})
    98  
    99  					It("generates missing and extra diff file", func() {
   100  						fileInfo, err := os.Stat(GetFilePath(expectedFilesPath, "quota.go.af.json.missing.diff.json"))
   101  						Ω(err).Should(BeNil())
   102  						Ω(fileInfo.Name()).Should(Equal("quota.go.af.json.missing.diff.json"))
   103  
   104  						fileInfo, err = os.Stat(GetFilePath(expectedFilesPath, "quota.go.af.json.extra.diff.json"))
   105  						Ω(err).Should(BeNil())
   106  						Ω(fileInfo.Name()).Should(Equal("quota.go.af.json.extra.diff.json"))
   107  					})
   108  				})
   109  
   110  				Context("with templated keys whose translation does not contain same arguments", func() {
   111  					BeforeEach(func() {
   112  						session := Runi18n("-c", "verify-strings", "-v", "-f", filepath.Join(inputFilesPath, "quota.go.en.json"), "--languages", "\"es\"", "-o", expectedFilesPath, "--source-language", "en")
   113  						Ω(session.ExitCode()).Should(Equal(1))
   114  					})
   115  
   116  					AfterEach(func() {
   117  						RemoveAllFiles(
   118  							GetFilePath(expectedFilesPath, "quota.go.es.json.invalid.diff.json"),
   119  						)
   120  					})
   121  
   122  					It("generates invalid diff file", func() {
   123  						fileInfo, err := os.Stat(GetFilePath(expectedFilesPath, "quota.go.es.json.invalid.diff.json"))
   124  						Ω(err).Should(BeNil())
   125  						Ω(fileInfo.Name()).Should(Equal("quota.go.es.json.invalid.diff.json"))
   126  					})
   127  				})
   128  			})
   129  
   130  			Context("with multiple language files", func() {
   131  				BeforeEach(func() {
   132  					session := Runi18n("-c", "verify-strings", "-v", "-f", filepath.Join(inputFilesPath, "quota.go.en.json"), "--languages", "\"de,it\"", "-o", expectedFilesPath, "--source-language", "en")
   133  					Ω(session.ExitCode()).Should(Equal(1))
   134  				})
   135  
   136  				AfterEach(func() {
   137  					RemoveAllFiles(
   138  						GetFilePath(expectedFilesPath, "quota.go.de.json.missing.diff.json"),
   139  						GetFilePath(expectedFilesPath, "quota.go.it.json.missing.diff.json"),
   140  					)
   141  				})
   142  
   143  				It("with invalid keys", func() {
   144  					fileInfo, err := os.Stat(GetFilePath(expectedFilesPath, "quota.go.de.json.missing.diff.json"))
   145  					Ω(err).Should(BeNil())
   146  					Ω(fileInfo.Name()).Should(Equal("quota.go.de.json.missing.diff.json"))
   147  
   148  					fileInfo, err = os.Stat(GetFilePath(expectedFilesPath, "quota.go.it.json.missing.diff.json"))
   149  					Ω(err).Should(BeNil())
   150  					Ω(fileInfo.Name()).Should(Equal("quota.go.it.json.missing.diff.json"))
   151  				})
   152  			})
   153  		})
   154  
   155  		Context("with language file", func() {
   156  			BeforeEach(func() {
   157  				session := Runi18n("-c", "verify-strings", "-v", "-f", filepath.Join(inputFilesPath, "quota.go.en.json"), "--languages", "\"ja\"", "-o", expectedFilesPath)
   158  				Ω(session.ExitCode()).Should(Equal(1))
   159  			})
   160  
   161  			AfterEach(func() {
   162  				RemoveAllFiles(
   163  					GetFilePath(expectedFilesPath, "quota.go.ja.json.extra.diff.json"),
   164  				)
   165  			})
   166  
   167  			It("with additional keys", func() {
   168  				fileInfo, err := os.Stat(GetFilePath(expectedFilesPath, "quota.go.ja.json.extra.diff.json"))
   169  				Ω(err).Should(BeNil())
   170  				Ω(fileInfo.Name()).Should(Equal("quota.go.ja.json.extra.diff.json"))
   171  			})
   172  		})
   173  
   174  		Context("with multiple language file", func() {
   175  			BeforeEach(func() {
   176  				session := Runi18n("-c", "verify-strings", "-v", "-f", filepath.Join(inputFilesPath, "quota.go.en.json"), "--languages", "\"ja,cs\"", "-o", expectedFilesPath)
   177  				Ω(session.ExitCode()).Should(Equal(1))
   178  			})
   179  
   180  			AfterEach(func() {
   181  				RemoveAllFiles(
   182  					GetFilePath(expectedFilesPath, "quota.go.ja.json.extra.diff.json"),
   183  					GetFilePath(expectedFilesPath, "quota.go.cs.json.extra.diff.json"),
   184  				)
   185  			})
   186  
   187  			It("with additional keys", func() {
   188  				fileInfo, err := os.Stat(GetFilePath(expectedFilesPath, "quota.go.ja.json.extra.diff.json"))
   189  				Ω(err).Should(BeNil())
   190  				Ω(fileInfo.Name()).Should(Equal("quota.go.ja.json.extra.diff.json"))
   191  
   192  				fileInfo, err = os.Stat(GetFilePath(expectedFilesPath, "quota.go.cs.json.extra.diff.json"))
   193  				Ω(err).Should(BeNil())
   194  				Ω(fileInfo.Name()).Should(Equal("quota.go.cs.json.extra.diff.json"))
   195  			})
   196  		})
   197  
   198  		Context("when missing a language file", func() {
   199  			BeforeEach(func() {
   200  				session := Runi18n("-c", "verify-strings", "-v", "-f", filepath.Join(inputFilesPath, "quota.go.en.json"), "--languages", "\"ja,ht\"", "-o", expectedFilesPath)
   201  				Ω(session.ExitCode()).Should(Equal(1))
   202  			})
   203  
   204  			AfterEach(func() {
   205  				RemoveAllFiles(
   206  					GetFilePath(expectedFilesPath, "quota.go.ja.json.extra.diff.json"),
   207  				)
   208  			})
   209  
   210  			It("with additional keys", func() {
   211  				fileInfo, err := os.Stat(GetFilePath(expectedFilesPath, "quota.go.ja.json.extra.diff.json"))
   212  				Ω(err).Should(BeNil())
   213  				Ω(fileInfo.Name()).Should(Equal("quota.go.ja.json.extra.diff.json"))
   214  			})
   215  		})
   216  	})
   217  
   218  	Context("invalid input file provided", func() {
   219  		Context("does not exist", func() {
   220  			BeforeEach(func() {
   221  				session := Runi18n("-c", "verify-strings", "-v", "-f", filepath.Join(inputFilesPath, "quota.go.ht.json"), "--languages", "\"fr\"", "-o", expectedFilesPath, "--source-language", "en")
   222  				Ω(session.ExitCode()).Should(Equal(1))
   223  			})
   224  
   225  			It("fails verification", func() {
   226  				_, err := os.Stat(GetFilePath(expectedFilesPath, "quota.go.ht.json"))
   227  				Ω(os.IsNotExist(err)).Should(Equal(true))
   228  			})
   229  		})
   230  
   231  		Context("does not have any keys", func() {
   232  			BeforeEach(func() {
   233  				session := Runi18n("-c", "verify-strings", "-v", "-f", filepath.Join(inputFilesPath, "quota.go.vi.json"), "--languages", "\"fr\"", "-o", expectedFilesPath, "--source-language", "en")
   234  				Ω(session.ExitCode()).Should(Equal(1))
   235  			})
   236  
   237  			It("fails verification", func() {
   238  				fileInfo, err := os.Stat(GetFilePath(inputFilesPath, "quota.go.vi.json"))
   239  				Ω(err).Should(BeNil())
   240  				Ω(fileInfo.Name()).Should(Equal("quota.go.vi.json"))
   241  			})
   242  		})
   243  	})
   244  })