File: encoder_test.go

package info (click to toggle)
golang-github-chai2010-gettext-go 0.0~git20191225.6b9f4b1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 3,256 kB
  • sloc: makefile: 23
file content (55 lines) | stat: -rw-r--r-- 1,288 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2013 ChaiShushan <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package mo

import (
	"reflect"
	"sort"
	"testing"
)

func TestFile_Data(t *testing.T) {
	f, err := LoadData(testMoFile.Data())
	if err != nil {
		t.Fatal(err)
	}
	if a, b := len(f.Messages), len(testMoFile.Messages); a != b {
		t.Logf("size not equal: expect = %d, got = %d", b, a)
	}
	for i, v := range f.Messages {
		if !reflect.DeepEqual(&v, &testMoFile.Messages[i]) {
			t.Fatalf("%d: expect = %v, got = %v", i, testMoFile.Messages[i], v)
		}
	}
}

func init() {
	sort.Sort(byMessages(testMoFile.Messages))
}

var testMoFile = &File{
	Messages: []Message{
		Message{
			MsgContext: "main.init",
			MsgId:      "Gettext in init.",
			MsgStr:     "Init函数中的Gettext.",
		},
		Message{
			MsgContext: "main.main",
			MsgId:      "Hello, world!",
			MsgStr:     "你好, 世界!",
		},
		Message{
			MsgContext: "main.func",
			MsgId:      "Gettext in func.",
			MsgStr:     "闭包函数中的Gettext.",
		},
		Message{
			MsgContext: "code.google.com/p/gettext-go/examples/hi.SayHi",
			MsgId:      "pkg hi: Hello, world!",
			MsgStr:     "来自\"Hi\"包的问候: 你好, 世界!",
		},
	},
}