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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public struct DefaultTypeConverter {
if try converter.hasDecode() {
return true
}
if try converter.hasEncode() {
return true
}
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,40 @@ export type S = {
)
}

func testCustomDecode() throws {
func testCustomDecodeSimple() throws {
var typeMap = TypeMap.default
typeMap.table["Date"] = .init(name: "Date", decode: "Date_decode")

try assertGenerate(
source: """
struct S {
var a: Date
}
""",
typeMap: typeMap,
expecteds: ["""
export type S = {
a: Date;
};
""", """
export type S_JSON = {
a: Date_JSON;
};
""", """
export function S_decode(json: S_JSON): S {
return {
a: Date_decode(json.a)
};
}
"""
],
unexpecteds: ["""
export function S_encode
"""]
)
}

func testCustomDecodeComplex() throws {
var typeMap = TypeMap.default
typeMap.table["Date"] = .init(name: "Date", decode: "Date_decode")

Expand Down Expand Up @@ -68,6 +101,39 @@ export function S_decode(json: S_JSON): S {
)
}

func testCustomEncode() throws {
var typeMap = TypeMap.default
typeMap.table["Date"] = .init(name: "Date", encode: "Date_encode")

try assertGenerate(
source: """
struct S {
var a: Date
}
""",
typeMap: typeMap,
expecteds: ["""
export type S = {
a: Date;
};
""", """
export type S_JSON = {
a: Date_JSON;
};
""", """
export function S_encode(entity: S): S_JSON {
return {
a: Date_encode(entity.a)
};
}
"""
],
unexpecteds: ["""
export function S_decode
"""]
)
}

func testCustomCoding() throws {
var typeMap = TypeMap.default
typeMap.table["Date"] = .init(
Expand Down