-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig_test.go
More file actions
98 lines (93 loc) · 4.55 KB
/
Copy pathconfig_test.go
File metadata and controls
98 lines (93 loc) · 4.55 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright 2023, Enguerrand de Rochefort
*
* This file is part of left.
*
* left is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* left is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with left. If not, see <http://www.gnu.org/licenses/>.
*
*/
package main
import (
"reflect"
"testing"
)
func TestReadMinimalConfigFromFile(t *testing.T) {
read := Config{}
var fontImport *FontImport = nil
var nilSlice []string
var nilStringPtr *string
_ = loadConfigFromFile("./test/config/valid_config_minimal.json", &read)
AssertEquals(t, read.FontName, "", "FontName")
AssertEquals(t, read.FontImport, fontImport, "FontImport")
AssertEquals(t, read.FontSize, float64(0), "FontSize")
AssertEquals(t, read.FontSizeSender, float64(0), "FontSizeSender")
AssertEquals(t, read.FontSizeAddress, float64(0), "FontSizeAddress")
AssertEquals(t, read.LineHeight, float64(0), "LineHeight")
AssertEquals(t, read.LineHeightAddress, float64(0), "LineHeightAddress")
AssertEquals(t, read.AddressSectionX, float64(0), "AddressSectionX")
AssertEquals(t, read.AddressSectionY, float64(0), "AddressSectionY")
AssertEquals(t, read.AddressSectionW, float64(0), "AddressSectionW")
AssertEquals(t, read.DateY, float64(0), "DateY")
AssertEquals(t, read.Margins, float64(0), "Margins")
AssertEquals(t, read.DatePrefix, "", "DatePrefix")
AssertEquals(t, read.Date, "", "Date")
AssertStringSliceEquals(t, nilSlice, read.Sender, "Sender")
AssertEquals(t, nilStringPtr, read.SenderName, "SenderName")
AssertEquals(t, nilStringPtr, read.Signature, "Signature")
}
func TestReadFullConfigFromFile(t *testing.T) {
read := Config{}
_ = loadConfigFromFile("./test/config/valid_config_full.json", &read)
AssertEquals(t, read.FontName, "someFontName", "FontName")
AssertEquals(t, read.FontImport.Name, "myfont", "FontImport.Name")
AssertEquals(t, read.FontImport.Directory, "/usr/share/fonts/myfont", "FontImport.Directory")
AssertEquals(t, read.FontImport.FontFileName, "MyFont-Condensed.ttf", "FontImport.FontFileName")
AssertEquals(t, read.FontImport.FontFileNameBold, "MyFont-CondensedBold.ttf", "FontImport.FontFileNameBold")
AssertEquals(t, read.FontSize, float64(42), "FontSize")
AssertEquals(t, read.FontSizeSender, float64(43), "FontSizeSender")
AssertEquals(t, read.FontSizeAddress, float64(44), "FontSizeAddress")
AssertEquals(t, read.LineHeight, float64(45), "LineHeight")
AssertEquals(t, read.LineHeightAddress, float64(46), "LineHeightAddress")
AssertEquals(t, read.AddressSectionX, float64(47), "AddressSectionX")
AssertEquals(t, read.AddressSectionY, float64(48), "AddressSectionY")
AssertEquals(t, read.AddressSectionW, float64(49), "AddressSectionW")
AssertEquals(t, read.DateY, float64(50), "DateY")
AssertEquals(t, read.Margins, float64(51), "Margins")
AssertEquals(t, read.DatePrefix, "My Hometown, ", "DatePrefix")
AssertEquals(t, read.Date, "24/05/2023", "Date")
AssertEquals(t, read.Sender[0], "Darth Vader", "read.Sender[0]")
AssertEquals(t, read.Sender[1], "Palace District with Special Chars äüößéç", "read.Sender[1]")
AssertEquals(t, read.Sender[2], "Coruscant", "read.Sender[2]")
AssertEquals(t, *read.SenderName, "Darth Vader", "read.SenderName")
AssertEquals(t, *read.Signature, "/home/dvader/documents/Signature.jpg", "read.Signature")
}
func TestReadConfigWithoutBoldFromFile(t *testing.T) {
read := Config{}
_ = loadConfigFromFile("./test/config/valid_config_full_no_bold_font.json", &read)
AssertEquals(t, read.FontName, "someFontName", "FontName")
AssertEquals(t, read.FontImport.Name, "myfont", "FontImport.Name")
AssertEquals(t, read.FontImport.Directory, "/usr/share/fonts/myfont", "FontImport.Directory")
AssertEquals(t, read.FontImport.FontFileName, "MyFont-Condensed.ttf", "FontImport.FontFileName")
AssertEquals(t, read.FontImport.FontFileNameBold, "", "FontImport.FontFileNameBold")
}
func AssertEquals(t *testing.T, got any, want any, description string) {
if got != want {
t.Errorf("%s: got %q, wanted %q", description, got, want)
}
}
func AssertStringSliceEquals(t *testing.T, got []string, want []string, description string) {
if !reflect.DeepEqual(got, want) {
t.Errorf("%s: got %q, wanted %q", description, got, want)
}
}