示例工程 03-strings-unicode

另有 1 个文件未随站点发布(平台工程、二进制或超过 200KB)。

03-strings-unicode/Tests/Ch03KitTests/SubstringTests.swift

swift · 0.5 KB

import Testing
 
@testable import Ch03Kit
 
@Suite("Substring 与拆分")
struct SubstringTests {
    @Test func csvKeepsEmptyFieldsAndTrimsSpaces() {
        #expect(SubstringLab.csvFields(" a, b , ,c") == ["a", "b", "", "c"])
    }
 
    @Test func firstWordSkipsLeadingSpaces() {
        #expect(SubstringLab.firstWord("  hello world") == "hello")
        #expect(SubstringLab.firstWord("   ") == "")
    }
 
    @Test func stringLayoutIsSixteenBytes() {
        #expect(MemoryLayout<String>.size == 16)
        #expect(MemoryLayout<Substring>.size == 32)
    }
}