Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Sources/BinaryParsingMacros/MagicNumberStringMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ public struct MagicNumberStringMacro: ExpressionMacro {
return ""
}

var parsingExpr = "input"
if let parsingArg = node.arguments.first(where: {
$0.label?.text == "parsing"
}) {
parsingExpr = parsingArg.expression.description
}

return """
_loadAndCheckDirectBytes(\
parsing: &input, \
parsing: \(raw: parsingExpr), \
bigEndianValue: 0x\(raw: String(integerValue, radix: 16)) as \(raw: integerType))
"""
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/BinaryParsingMacrosTests/ParserMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ struct StringifyMacroSwiftTestingTests {
@Test
func magicNumberString() {
assertMacro {
#"try #magicNumber("qoif", parsing: &input)"#
#"try #magicNumber("qoif", parsing: &data)"#
} expansion: {
"try _loadAndCheckDirectBytes(parsing: &input, bigEndianValue: 0x716f6966 as UInt32)"
"try _loadAndCheckDirectBytes(parsing: &data, bigEndianValue: 0x716f6966 as UInt32)"
}
}
}