~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/chai2010/gettext-go/gettext/po/comment_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2013 ChaiShushan <chaishushan{AT}gmail.com>. All rights reserved.
2
 
// Use of this source code is governed by a BSD-style
3
 
// license that can be found in the LICENSE file.
4
 
 
5
 
package po
6
 
 
7
 
import (
8
 
        "reflect"
9
 
        "testing"
10
 
)
11
 
 
12
 
func TestPoComment(t *testing.T) {
13
 
        var x Comment
14
 
        for i := 0; i < len(testPoComments); i++ {
15
 
                if i != 2 {
16
 
                        continue
17
 
                }
18
 
                err := x.readPoComment(newLineReader(testPoComments[i].Data))
19
 
                if err != nil {
20
 
                        t.Fatalf("%d: %v", i, err)
21
 
                }
22
 
                x.StartLine = 0 // ingore comment line
23
 
                if !reflect.DeepEqual(&x, &testPoComments[i].PoComment) {
24
 
                        t.Logf("expect(%d):\n", i)
25
 
                        t.Logf("\n%v\n", &testPoComments[i].PoComment)
26
 
                        t.Logf("got(%d):\n", i)
27
 
                        t.Logf("\n%v\n", &x)
28
 
                        t.FailNow()
29
 
                }
30
 
                if testPoComments[i].CheckStringer {
31
 
                        s := testPoComments[i].PoComment.String()
32
 
                        if s != testPoComments[i].Data {
33
 
                                t.Logf("expect(%d):\n", i)
34
 
                                t.Logf("\n%s\n", testPoComments[i].Data)
35
 
                                t.Logf("got(%d):\n", i)
36
 
                                t.Logf("\n%s\n", testPoComments[i].PoComment.String())
37
 
                                t.FailNow()
38
 
                        }
39
 
                }
40
 
        }
41
 
}
42
 
 
43
 
type testPoComment struct {
44
 
        CheckStringer bool
45
 
        Data          string
46
 
        PoComment     Comment
47
 
}
48
 
 
49
 
var testPoComments = []testPoComment{
50
 
 
51
 
        // --------------------------------------------------------------
52
 
        // CheckStringer: true
53
 
        // --------------------------------------------------------------
54
 
 
55
 
        testPoComment{
56
 
                CheckStringer: true,
57
 
                Data: `# translator comments
58
 
`,
59
 
                PoComment: Comment{
60
 
                        TranslatorComment: `translator comments`,
61
 
                },
62
 
        },
63
 
        testPoComment{
64
 
                CheckStringer: true,
65
 
                Data: `# translator comments
66
 
`,
67
 
                PoComment: Comment{
68
 
                        TranslatorComment: `translator comments`,
69
 
                },
70
 
        },
71
 
 
72
 
        testPoComment{
73
 
                CheckStringer: true,
74
 
                Data: `# translator-comments
75
 
# bad comment
76
 
#. extracted-comments
77
 
#: src/msgcmp.c:338 src/po-lex.c:699 src/msg.c:123
78
 
#, fuzzy, c-format, range:0..10
79
 
#| msgctxt ""
80
 
#| "previous-context1\n"
81
 
#| "previous-context2"
82
 
#| msgid ""
83
 
#| "previous-untranslated-string1\n"
84
 
#| "previous-untranslated-string2"
85
 
`,
86
 
                PoComment: Comment{
87
 
                        TranslatorComment: "translator-comments\nbad comment",
88
 
                        ExtractedComment:  "extracted-comments",
89
 
                        ReferenceFile:     []string{"src/msgcmp.c", "src/po-lex.c", "src/msg.c"},
90
 
                        ReferenceLine:     []int{338, 699, 123},
91
 
                        Flags:             []string{"fuzzy", "c-format", "range:0..10"},
92
 
                        PrevMsgContext:    "previous-context1\nprevious-context2",
93
 
                        PrevMsgId:         "previous-untranslated-string1\nprevious-untranslated-string2",
94
 
                },
95
 
        },
96
 
 
97
 
        // --------------------------------------------------------------
98
 
        // CheckStringer: false
99
 
        // --------------------------------------------------------------
100
 
 
101
 
        testPoComment{
102
 
                CheckStringer: false,
103
 
                Data: `
104
 
#  translator-comments
105
 
#bad comment
106
 
#. extracted-comments
107
 
#: src/msgcmp.c:338 src/po-lex.c:699
108
 
#: src/msg.c:123
109
 
#, fuzzy,c-format,range:0..10
110
 
#| msgctxt ""
111
 
#| "previous-context1\n"
112
 
#| "previous-context2"
113
 
#| msgid ""
114
 
#| "previous-untranslated-string1\n"
115
 
#| "previous-untranslated-string2"
116
 
`,
117
 
                PoComment: Comment{
118
 
                        TranslatorComment: "translator-comments\nbad comment",
119
 
                        ExtractedComment:  "extracted-comments",
120
 
                        ReferenceFile:     []string{"src/msgcmp.c", "src/po-lex.c", "src/msg.c"},
121
 
                        ReferenceLine:     []int{338, 699, 123},
122
 
                        Flags:             []string{"fuzzy", "c-format", "range:0..10"},
123
 
                        PrevMsgContext:    "previous-context1\nprevious-context2",
124
 
                        PrevMsgId:         "previous-untranslated-string1\nprevious-untranslated-string2",
125
 
                },
126
 
        },
127
 
        testPoComment{
128
 
                CheckStringer: false,
129
 
                Data: `
130
 
# SOME DESCRIPTIVE TITLE.
131
 
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
132
 
# This file is distributed under the same license as the PACKAGE package.
133
 
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
134
 
#
135
 
msgid ""
136
 
msgstr ""
137
 
"Project-Id-Version: Poedit 1.5\n"
138
 
"Report-Msgid-Bugs-To: poedit@googlegroups.com\n"
139
 
"POT-Creation-Date: 2012-07-30 10:34+0200\n"
140
 
"PO-Revision-Date: 2013-12-25 09:32+0800\n"
141
 
"Last-Translator: chai2010 <chaishushan@gmail.com>\n"
142
 
"Language-Team: \n"
143
 
"MIME-Version: 1.0\n"
144
 
"Content-Type: text/plain; charset=UTF-8\n"
145
 
"Content-Transfer-Encoding: 8bit\n"
146
 
"Plural-Forms: nplurals=1; plural=0;\n"
147
 
"X-Generator: Poedit 1.5.7\n"
148
 
`,
149
 
                PoComment: Comment{
150
 
                        TranslatorComment: `SOME DESCRIPTIVE TITLE.
151
 
Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
152
 
This file is distributed under the same license as the PACKAGE package.
153
 
FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
154
 
`,
155
 
                },
156
 
        },
157
 
        testPoComment{
158
 
                CheckStringer: false,
159
 
                Data: `
160
 
#. TRANSLATORS: This is version information in about dialog, it is followed
161
 
#. by version number when used (wxWidgets 2.8)
162
 
#: ../src/edframe.cpp:2431
163
 
#| msgctxt "previous-context asdasd"
164
 
"asdad \n asdsad"
165
 
msgstr ""
166
 
`,
167
 
                PoComment: Comment{
168
 
                        ExtractedComment: `TRANSLATORS: This is version information in about dialog, it is followed
169
 
by version number when used (wxWidgets 2.8)`,
170
 
                        ReferenceFile:  []string{"../src/edframe.cpp"},
171
 
                        ReferenceLine:  []int{2431},
172
 
                        PrevMsgContext: "previous-context asdasd",
173
 
                },
174
 
        },
175
 
        testPoComment{
176
 
                CheckStringer: false,
177
 
                Data: `
178
 
#: tst-gettext2.c:33
179
 
msgid "First string for testing."
180
 
msgstr "Lang1: 1st string"
181
 
`,
182
 
                PoComment: Comment{
183
 
                        ReferenceFile: []string{"tst-gettext2.c"},
184
 
                        ReferenceLine: []int{33},
185
 
                },
186
 
        },
187
 
        testPoComment{
188
 
                CheckStringer: false,
189
 
                Data: `
190
 
#: app/app_procs.c:307
191
 
#, fuzzy, c-format
192
 
msgid "Can't find output format %s\n"
193
 
msgstr ""
194
 
"敲矾弊牢 '%s'甫 佬阑荐 绝嚼聪促\n"
195
 
"%s"
196
 
`,
197
 
                PoComment: Comment{
198
 
                        ReferenceFile: []string{"app/app_procs.c"},
199
 
                        ReferenceLine: []int{307},
200
 
                        Flags:         []string{"fuzzy", "c-format"},
201
 
                },
202
 
        },
203
 
 
204
 
        // --------------------------------------------------------------
205
 
        // END
206
 
        // --------------------------------------------------------------
207
 
}