118
main_test.go
118
main_test.go
@ -54,6 +54,7 @@ func (s *xgettextTestSuite) SetUpTest(c *C) {
|
||||
opts.AddCommentsTag = "TRANSLATORS:"
|
||||
opts.Keyword = "i18n.G"
|
||||
opts.KeywordPlural = "i18n.NG"
|
||||
opts.KeywordContext = "i18n.GC"
|
||||
opts.SortOutput = true
|
||||
opts.PackageName = "snappy"
|
||||
opts.MsgIDBugsAddress = "snappy-devel@lists.ubuntu.com"
|
||||
@ -102,6 +103,29 @@ func main() {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *xgettextTestSuite) TestProcessFilesSimpleWithContext(c *C) {
|
||||
fname := makeGoSourceFile(c, []byte(`package main
|
||||
|
||||
func main() {
|
||||
// TRANSLATORS: foo comment
|
||||
i18n.GC("foo", "foo context")
|
||||
}
|
||||
`))
|
||||
err := processFiles([]string{fname})
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
c.Assert(msgIDs, DeepEquals, map[string][]msgID{
|
||||
"foo": {
|
||||
{
|
||||
comment: "#. TRANSLATORS: foo comment\n",
|
||||
context: "foo context",
|
||||
fname: fname,
|
||||
line: 5,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (s *xgettextTestSuite) TestProcessFilesMultiple(c *C) {
|
||||
fname := makeGoSourceFile(c, []byte(`package main
|
||||
|
||||
@ -132,6 +156,38 @@ func main() {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *xgettextTestSuite) TestProcessFilesMultipleWithContext(c *C) {
|
||||
fname := makeGoSourceFile(c, []byte(`package main
|
||||
|
||||
func main() {
|
||||
// TRANSLATORS: foo comment
|
||||
i18n.GC("foo", "foo context")
|
||||
|
||||
// TRANSLATORS: bar comment
|
||||
i18n.GC("foo", "foo context 2")
|
||||
}
|
||||
`))
|
||||
err := processFiles([]string{fname})
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
c.Assert(msgIDs, DeepEquals, map[string][]msgID{
|
||||
"foo": {
|
||||
{
|
||||
comment: "#. TRANSLATORS: foo comment\n",
|
||||
context: "foo context",
|
||||
fname: fname,
|
||||
line: 5,
|
||||
},
|
||||
{
|
||||
comment: "#. TRANSLATORS: bar comment\n",
|
||||
context: "foo context 2",
|
||||
fname: fname,
|
||||
line: 8,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const header = `# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
@ -174,6 +230,31 @@ msgstr ""
|
||||
c.Assert(out.String(), Equals, expected)
|
||||
}
|
||||
|
||||
func (s *xgettextTestSuite) TestWriteOutputSimpleWithContext(c *C) {
|
||||
msgIDs = map[string][]msgID{
|
||||
"foo": {
|
||||
{
|
||||
fname: "fname",
|
||||
line: 2,
|
||||
comment: "#. foo\n",
|
||||
context: "foo context",
|
||||
},
|
||||
},
|
||||
}
|
||||
out := bytes.NewBuffer([]byte(""))
|
||||
writePotFile(out)
|
||||
|
||||
expected := fmt.Sprintf(`%s
|
||||
#. foo
|
||||
#: fname:2
|
||||
msgctx "foo context"
|
||||
msgid "foo"
|
||||
msgstr ""
|
||||
|
||||
`, header)
|
||||
c.Assert(out.String(), Equals, expected)
|
||||
}
|
||||
|
||||
func (s *xgettextTestSuite) TestWriteOutputMultiple(c *C) {
|
||||
msgIDs = map[string][]msgID{
|
||||
"foo": {
|
||||
@ -203,6 +284,43 @@ msgstr ""
|
||||
c.Assert(out.String(), Equals, expected)
|
||||
}
|
||||
|
||||
func (s *xgettextTestSuite) TestWriteOutputMultipleWithContext(c *C) {
|
||||
msgIDs = map[string][]msgID{
|
||||
"foo": {
|
||||
{
|
||||
fname: "fname",
|
||||
context: "context1",
|
||||
line: 2,
|
||||
comment: "#. comment1\n",
|
||||
},
|
||||
{
|
||||
fname: "fname",
|
||||
context: "context2",
|
||||
line: 4,
|
||||
comment: "#. comment2\n",
|
||||
},
|
||||
},
|
||||
}
|
||||
out := bytes.NewBuffer([]byte(""))
|
||||
writePotFile(out)
|
||||
|
||||
expected := fmt.Sprintf(`%s
|
||||
#. comment1
|
||||
#: fname:2
|
||||
msgctx "context1"
|
||||
msgid "foo"
|
||||
msgstr ""
|
||||
|
||||
#. comment2
|
||||
#: fname:4
|
||||
msgctx "context2"
|
||||
msgid "foo"
|
||||
msgstr ""
|
||||
|
||||
`, header)
|
||||
c.Assert(out.String(), Equals, expected)
|
||||
}
|
||||
|
||||
func (s *xgettextTestSuite) TestWriteOutputNoComment(c *C) {
|
||||
msgIDs = map[string][]msgID{
|
||||
"foo": {
|
||||
|
Reference in New Issue
Block a user