Skip to content

Commit 4da4051

Browse files
committed
fix: convert Bool:true/false to string "true"/"false"
1 parent c7d1eb4 commit 4da4051

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Sources/Lookup/Lookup.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ public extension Lookup {
475475
return "\(rawNumber)"
476476
case .string:
477477
return rawString
478+
case .bool:
479+
return rawBool ? "true" : "false"
478480
default:
479481
return nil
480482
}

Tests/LookupTests/LookupTests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,35 @@ struct LookupTests {
559559
""")
560560
}
561561
#endif
562+
563+
@Test("Test true/false to string")
564+
func testTrueFalseToString() throws {
565+
let json = """
566+
{
567+
"status": "success",
568+
"country": "新加坡",
569+
"countryCode": "SG",
570+
"region": "03",
571+
"regionName": "North West",
572+
"city": "新加坡",
573+
"zip": "858877",
574+
"timezone": "Asia/Singapore",
575+
"currency": "SGD",
576+
"isp": "Alibaba (US) Technology Co., Ltd.",
577+
"org": "Alibaba.com LLC",
578+
"as": "AS45102 Alibaba (US) Technology Co., Ltd.",
579+
"proxy": false,
580+
"hosting": true
581+
}
582+
"""
583+
let lookup = Lookup(json)
584+
#expect(lookup.proxy.string == "false")
585+
#expect(lookup.hosting.string == "true")
586+
587+
#expect(lookup.proxy.int == 0)
588+
#expect(lookup.hosting.int == 1)
589+
590+
#expect(lookup.proxy.bool == false)
591+
#expect(lookup.hosting.bool == true)
592+
}
562593
}

0 commit comments

Comments
 (0)