1
1
local mock = require " deftest.mock.mock"
2
2
local mock_fs = require " deftest.mock.fs"
3
+ local unload = require " deftest.util.unload"
3
4
4
5
return function ()
5
- local settings = require " ludobits.m.settings "
6
+ local settings
6
7
7
8
describe (" settings" , function ()
8
9
before (function ()
10
+ unload .unload (" ludobits." )
9
11
mock_fs .mock ()
12
+ settings = require " ludobits.m.settings"
10
13
end )
11
14
12
15
after (function ()
13
16
mock_fs .unmock ()
14
17
end )
15
18
16
19
it (" should start empty" , function ()
17
- assert (settings .foo == nil )
20
+ assert (settings .is_empty () )
18
21
end )
19
22
20
23
it (" should be possible to set and get values" , function ()
@@ -24,6 +27,7 @@ return function()
24
27
settings .boo = " car"
25
28
assert (settings .foo == " bar" )
26
29
assert (settings .boo == " car" )
30
+ assert (not settings .is_empty ())
27
31
end )
28
32
29
33
it (" should be possible to set, save and later load values" , function ()
@@ -39,5 +43,31 @@ return function()
39
43
assert (newsettings .foo == " bar" )
40
44
assert (newsettings .boo == " car" )
41
45
end )
46
+
47
+ it (" should be possible to load and save to multiple files" , function ()
48
+ -- set and save to default file
49
+ assert (settings .is_empty ())
50
+ settings .foo = " foodefault"
51
+ settings .save ()
52
+
53
+ -- set and save to file1
54
+ settings .load (" file1" )
55
+ assert (settings .filename () == " file1" )
56
+ assert (settings .is_empty ())
57
+ settings .foo = " foofile1"
58
+ settings .save ()
59
+
60
+ -- load default file again and save it to a file2
61
+ settings .load ()
62
+ assert (settings .foo == " foodefault" )
63
+ settings .foo = " foofile2"
64
+ settings .save (" file2" )
65
+ assert (settings .filename () == " file2" )
66
+
67
+ -- load file1 and make sure it is unchanged
68
+ settings .load (" file1" )
69
+ assert (settings .filename () == " file1" )
70
+ assert (settings .foo == " foofile1" )
71
+ end )
42
72
end )
43
73
end
0 commit comments