Lua: allow to compare, show Citation values
Comparisons of Citation values are performed in Haskell; values are equal if they represent the same Haskell value. Converting a Citation value to a string now yields its native Haskell string representation.
This commit is contained in:
parent
3a0ac52f7b
commit
210e4c98b0
2 changed files with 28 additions and 1 deletions
|
@ -111,7 +111,18 @@ instance Pushable Block where
|
||||||
push = pushBlock
|
push = pushBlock
|
||||||
|
|
||||||
typeCitation :: LuaError e => DocumentedType e Citation
|
typeCitation :: LuaError e => DocumentedType e Citation
|
||||||
typeCitation = deftype "Citation" []
|
typeCitation = deftype "Citation"
|
||||||
|
[ operation Eq $ lambda
|
||||||
|
### liftPure2 (==)
|
||||||
|
<#> parameter (optional . peekCitation) "Citation" "a" ""
|
||||||
|
<#> parameter (optional . peekCitation) "Citation" "b" ""
|
||||||
|
=#> functionResult pushBool "boolean" "true iff the citations are equal"
|
||||||
|
|
||||||
|
, operation Tostring $ lambda
|
||||||
|
### liftPure show
|
||||||
|
<#> parameter peekCitation "Citation" "citation" ""
|
||||||
|
=#> functionResult pushString "string" "native Haskell representation"
|
||||||
|
]
|
||||||
[ property "id" "citation ID / key"
|
[ property "id" "citation ID / key"
|
||||||
(pushText, citationId)
|
(pushText, citationId)
|
||||||
(peekText, \citation cid -> citation{ citationId = cid })
|
(peekText, \citation cid -> citation{ citationId = cid })
|
||||||
|
|
|
@ -481,6 +481,22 @@ return {
|
||||||
end)
|
end)
|
||||||
},
|
},
|
||||||
group 'Other types' {
|
group 'Other types' {
|
||||||
|
group 'Citation' {
|
||||||
|
test('checks equality by comparing Haskell values', function()
|
||||||
|
assert.are_equal(
|
||||||
|
pandoc.Citation('a', pandoc.NormalCitation),
|
||||||
|
pandoc.Citation('a', pandoc.NormalCitation)
|
||||||
|
)
|
||||||
|
assert.is_falsy(
|
||||||
|
pandoc.Citation('a', pandoc.NormalCitation) ==
|
||||||
|
pandoc.Citation('a', pandoc.AuthorInText)
|
||||||
|
)
|
||||||
|
assert.is_falsy(
|
||||||
|
pandoc.Citation('a', pandoc.NormalCitation) ==
|
||||||
|
pandoc.Citation('b', pandoc.NormalCitation)
|
||||||
|
)
|
||||||
|
end),
|
||||||
|
},
|
||||||
group 'SimpleTable' {
|
group 'SimpleTable' {
|
||||||
test('can access properties', function ()
|
test('can access properties', function ()
|
||||||
local spc = pandoc.Space()
|
local spc = pandoc.Space()
|
||||||
|
|
Loading…
Add table
Reference in a new issue