-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyprlang_parser_test.go
134 lines (104 loc) · 4.44 KB
/
hyprlang_parser_test.go
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package hyprlang_parser_test
import (
"fmt"
"reflect"
"testing"
"github.com/anotherhadi/hyprlang-parser"
)
const configPath = "test_config/example.conf"
func strShouldEqual(t *testing.T, str1 string, str2 string) {
if str1 != str2 {
t.Error("Strings '" + str1 + "' and '" + str2 + "' not equal")
}
}
func strsShouldEqual(t *testing.T, strs1 []string, strs2 []string) {
if !reflect.DeepEqual(strs1, strs2) {
t.Error("[]Strings '" + fmt.Sprint(strs1) + "' and '" + fmt.Sprint(strs2) + "' not equal")
}
}
func failOnError(t *testing.T, err error) {
if err != nil {
t.Error(err)
}
}
func TestLoadConfig(t *testing.T) {
_, err := hyprlang_parser.LoadConfig(configPath)
if err != nil {
t.Error(err)
}
}
func TestWriteConfig(t *testing.T) {
config, err := hyprlang_parser.LoadConfig(configPath)
if err != nil {
t.Error(err)
}
err = config.WriteConfig()
if err != nil {
t.Error(err)
}
}
func TestGetFirst(t *testing.T) {
config, _ := hyprlang_parser.LoadConfig(configPath)
strShouldEqual(t, config.GetFirst("", "exec-once"), "hyprlang_parser")
strShouldEqual(t, config.GetFirst("", "exec_once"), "")
strShouldEqual(t, config.GetFirst("input", "kb_layout"), "fr")
strShouldEqual(t, config.GetFirst("input/", "kb_layout"), "fr")
strShouldEqual(t, config.GetFirst("/input/", "kb_layout"), "fr")
strShouldEqual(t, config.GetFirst("", "kb_layout"), "")
strShouldEqual(t, config.GetFirst("input/touchpad/", "natural_scroll"), "yes")
strShouldEqual(t, config.GetFirst("/input/touchpad", "natural_scroll"), "yes")
// Sourced files
strShouldEqual(t, config.GetFirst("", "only-sourced-var"), "ok")
strShouldEqual(t, config.GetFirst("section/subsection", "does-it-work"), "true")
}
func TestGetAll(t *testing.T) {
config, _ := hyprlang_parser.LoadConfig(configPath)
strsShouldEqual(t, config.GetAll("", "monitor"), []string{"eDP-1,2240x1400@60,0x0,1", "eDP-2,2240x1400@60,0x0,1"})
}
func TestEditFirst(t *testing.T) {
config, _ := hyprlang_parser.LoadConfig(configPath)
strShouldEqual(t, config.GetFirst("input", "kb_layout"), "fr")
failOnError(t, config.EditFirst("input/", "kb_layout", "en"))
strShouldEqual(t, config.GetFirst("input", "kb_layout"), "en")
strShouldEqual(t, config.GetFirst("input/touchpad", "natural_scroll"), "yes")
failOnError(t, config.EditFirst("input/touchpad", "natural_scroll", "no"))
strShouldEqual(t, config.GetFirst("input/touchpad", "natural_scroll"), "no")
strShouldEqual(t, config.GetFirst("", "monitor"), "eDP-1,2240x1400@60,0x0,1")
failOnError(t, config.EditFirst("", "monitor", "no monitor here"))
strShouldEqual(t, config.GetFirst("", "monitor"), "no monitor here")
strShouldEqual(t, config.GetFirst("", "only-sourced-var"), "ok")
failOnError(t, config.EditFirst("", "only-sourced-var", "youpi"))
strShouldEqual(t, config.GetFirst("", "only-sourced-var"), "youpi")
}
func TestEditN(t *testing.T) {
config, _ := hyprlang_parser.LoadConfig(configPath)
strShouldEqual(t, config.GetAll("", "exec-once")[1], "hyprlang_parser_2")
failOnError(t, config.EditN("/", "exec-once", "hyprsettings", 1))
strShouldEqual(t, config.GetAll("", "exec-once")[1], "hyprsettings")
}
func TestAdd(t *testing.T) {
config, _ := hyprlang_parser.LoadConfig(configPath)
strShouldEqual(t, config.GetFirst("", "a-new-var"), "")
config.Add("", "a-new-var", "newvalue")
strShouldEqual(t, config.GetFirst("", "a-new-var"), "newvalue")
strShouldEqual(t, config.GetFirst("test", "a-new-var"), "")
config.Add("test", "a-new-var", "newvalue")
strShouldEqual(t, config.GetFirst("test", "a-new-var"), "newvalue")
strShouldEqual(t, config.GetFirst("test/subsections", "a-new-var"), "")
config.Add("test/subsections", "a-new-var", "newvalue")
strShouldEqual(t, config.GetFirst("test/subsections", "a-new-var"), "newvalue")
}
func TestRemoveFirst(t *testing.T) {
config, _ := hyprlang_parser.LoadConfig(configPath)
strShouldEqual(t, config.GetFirst("", "monitor"), "eDP-1,2240x1400@60,0x0,1")
failOnError(t, config.RemoveFirst("", "monitor"))
strShouldEqual(t, config.GetFirst("", "monitor"), "eDP-2,2240x1400@60,0x0,1")
failOnError(t, config.RemoveFirst("animations", "enabled"))
strShouldEqual(t, config.GetFirst("animations", "enabled"), "")
}
func TestRemoveN(t *testing.T) {
config, _ := hyprlang_parser.LoadConfig(configPath)
strShouldEqual(t, config.GetAll("animations", "animation")[1], "border,1,10,default")
failOnError(t, config.RemoveN("animations", "animation", 1))
strShouldEqual(t, config.GetAll("animations", "animation")[1], "fade,0,5,default")
}