Add OrgInlineBlock equalizers
This commit is contained in:
@@ -6,8 +6,11 @@ import std/[
|
|||||||
import fp/[
|
import fp/[
|
||||||
option,
|
option,
|
||||||
]
|
]
|
||||||
|
import fusion/matching
|
||||||
import ../utils/printers
|
import ../utils/printers
|
||||||
|
|
||||||
|
{.experimental: "caseStmtMacros".}
|
||||||
|
|
||||||
# -- OrgInlineBlock.Type
|
# -- OrgInlineBlock.Type
|
||||||
|
|
||||||
type
|
type
|
||||||
@@ -47,6 +50,21 @@ type
|
|||||||
linkUrl*: string
|
linkUrl*: string
|
||||||
linkDescription*: Option[string]
|
linkDescription*: Option[string]
|
||||||
|
|
||||||
|
|
||||||
|
# OrgInlineBlock.Equals
|
||||||
|
|
||||||
|
func `==`*(a: OrgInlineBlock, b: OrgInlineBlock): bool =
|
||||||
|
## Compare two `OrgInlineBlock` objects.
|
||||||
|
## TODO Compare children
|
||||||
|
|
||||||
|
if (a.kind != b.kind): return false
|
||||||
|
|
||||||
|
case ((a.kind, b.kind)):
|
||||||
|
of((orgLink, orgLink)):
|
||||||
|
a.linkUrl == b.linkUrl and a.linkDescription == b.linkDescription
|
||||||
|
|
||||||
|
else: a.content == b.content
|
||||||
|
|
||||||
# -- OrgInlineBlock.PrettyPrinters
|
# -- OrgInlineBlock.PrettyPrinters
|
||||||
|
|
||||||
proc `$`*(x: orgInlineBlockKind): string =
|
proc `$`*(x: orgInlineBlockKind): string =
|
||||||
@@ -182,28 +200,38 @@ func pprint*(x: OrgDocument, indent = 0): string =
|
|||||||
func `$`*(xs: OrgDocument): string = pprint(xs)
|
func `$`*(xs: OrgDocument): string = pprint(xs)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
let doc = OrgDocument(
|
|
||||||
children: @[
|
block testOrgInlineBlockEquals:
|
||||||
OrgBlock(
|
assert OrgInlineBlock(kind: orgRawText) == OrgInlineBlock(kind: orgRawText)
|
||||||
kind: orgHeading,
|
assert OrgInlineBlock(kind: orgRawText, content: "") == OrgInlineBlock(kind: orgRawText, content: "")
|
||||||
children: @[
|
assert OrgInlineBlock(kind: orgRawText, content: "a") != OrgInlineBlock(kind: orgRawText, content: "b")
|
||||||
OrgInlineBlock(
|
assert OrgInlineBlock(kind: orgRawText) != OrgInlineBlock(kind: orgBoldText)
|
||||||
kind: orgLink,
|
# Link
|
||||||
linkUrl: "https://placeholder.com",
|
assert OrgInlineBlock(kind: orgLink, linkDescription: "desc".some(), linkUrl: "url") == OrgInlineBlock(kind: orgLink, linkDescription: "desc".some(), linkUrl: "url")
|
||||||
linkDescription: "Placeholder".some(),
|
assert OrgInlineBlock(kind: orgLink, linkUrl: "url") != OrgInlineBlock(kind: orgLink, linkDescription: "desc".some(), linkUrl: "url")
|
||||||
),
|
|
||||||
],
|
# let doc = OrgDocument(
|
||||||
content: @[
|
# children: @[
|
||||||
OrgBlock(
|
# OrgBlock(
|
||||||
kind: orgNewline,
|
# kind: orgHeading,
|
||||||
),
|
# children: @[
|
||||||
OrgBlock(
|
# OrgInlineBlock(
|
||||||
kind: orgNewline,
|
# kind: orgLink,
|
||||||
)
|
# linkUrl: "https://placeholder.com",
|
||||||
],
|
# linkDescription: "Placeholder".some(),
|
||||||
),
|
# ),
|
||||||
OrgBlock(kind: orgHeading, level: 1),
|
# ],
|
||||||
OrgBlock(kind: orgHeading),
|
# content: @[
|
||||||
]
|
# OrgBlock(
|
||||||
)
|
# kind: orgNewline,
|
||||||
echo doc
|
# ),
|
||||||
|
# OrgBlock(
|
||||||
|
# kind: orgNewline,
|
||||||
|
# )
|
||||||
|
# ],
|
||||||
|
# ),
|
||||||
|
# OrgBlock(kind: orgHeading, level: 1),
|
||||||
|
# OrgBlock(kind: orgHeading),
|
||||||
|
# ]
|
||||||
|
# )
|
||||||
|
# echo doc
|
||||||
|
|||||||
Reference in New Issue
Block a user