Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
SILE = require("core.sile") | ||
|
||
describe("The settings handler", function() | ||
|
||
it("should trigger callbacks on set", function() | ||
local private = "foo" | ||
local function callback (value) | ||
private = value .. " hooked" | ||
end | ||
SILE.settings:declare({ | ||
parameter = "test.callback", | ||
type = "string", | ||
default = "bar", | ||
hook = callback | ||
}) | ||
SILE.settings:set("test.callback", "baz") | ||
assert.is.equal("baz hooked", private) | ||
end) | ||
|
||
it("should trigger callbacks on push/pop events", function() | ||
local mystate = "foo" | ||
local function callback2 (value) | ||
mystate = value .. " stack" | ||
end | ||
SILE.settings:declare({ | ||
parameter = "test.callback2", | ||
type = "string", | ||
default = "bar", | ||
hook = callback2 | ||
}) | ||
SILE.settings:pushState() | ||
SILE.settings:set("test.callback2", "baz1") | ||
SILE.settings:pushState() | ||
SILE.settings:set("test.callback2", "baz2") | ||
assert.is.equal("baz2 stack", mystate) | ||
SILE.settings:popState() | ||
assert.is.equal("baz1 stack", mystate) | ||
SILE.settings:popState() | ||
assert.is.equal("bar stack", mystate) | ||
end) | ||
|
||
end) |