import Foundation import Testing @testable import Ch03Kit @Suite("格式化与正则") struct FormatLabTests { @Test func groupingFollowsSimplifiedChineseLocale() { #expect(FormatLab.groupedInteger(1_234_567) == "1,234,567") } @Test func fixedFractionAlwaysPrintsRequestedDigits() { #expect(FormatLab.fixedDecimal(1234.5, fractionDigits: 2) == "1,234.50") // 0.125 恰好落在二进制可表示的中点,格式化采用「半数到偶数」,得到 0.12。 #expect(FormatLab.fixedDecimal(0.125, fractionDigits: 2) == "0.12") } @Test func percentUsesLocaleFormatting() { #expect(FormatLab.percent(0.256) == "25.6%") } @Test func interpolationAcceptsFormatStyle() { #expect(FormatLab.greeting(name: "Ada", score: 9.25) == "Ada:9.2") } @Test func hashtagsAreDeduplicatedAndSorted() { #expect(RegexLab.hashtags(in: "学 #Swift 和 #正则,再来一次 #Swift") == ["Swift", "正则"]) } @Test func regexReplacesEveryNumberRun() { #expect(RegexLab.redactedNumbers(in: "订单 1234 金额 56") == "订单 # 金额 #") } }