File: String%2BHashingTests.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (37 lines) | stat: -rw-r--r-- 1,957 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 This source file is part of the Swift.org open source project

 Copyright (c) 2021 Apple Inc. and the Swift project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See https://swift.org/LICENSE.txt for license information
 See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import XCTest
@testable import SwiftDocC

class String_HashingTests: XCTestCase {
    
    func testFNV1aHash() {
        // Test that the results are stable for the given inputs
        (0...100).forEach { _ in
            XCTAssertEqual("146ys", "".stableHashString)
            XCTAssertEqual("1if00", "Hello".stableHashString)
            XCTAssertEqual("3c6o6", "Lorem ipsum dolor sit amet, consectetur adipiscing elit.".stableHashString)
            XCTAssertEqual("4y7c", "/mykit/myclass/myfunc".stableHashString)
        }
    }
    
    func testUSRHash() {
        // Test that the results are stable for the given inputs
        (0...100).forEach { _ in
            XCTAssertEqual("ztntfp", ExternalIdentifier.usr("").hash)
            XCTAssertEqual("1kf2iw4", ExternalIdentifier.usr("s:5SideKit0A5ClassC10elementT").hash)
            XCTAssertEqual("n3jy95", ExternalIdentifier.usr("s:5SideKit0A5ClassC10value_int").hash)
            XCTAssertEqual("1m0yasz", ExternalIdentifier.usr(veryLongUSR).hash)
        }
    }
}

fileprivate let veryLongUSR = "s:So8CQDProcsV8textProc04lineC004rectC005rRectC004ovalC003arcC004polyC003rgnC004bitsC007commentC006txMeasC006getPicC003putpC006opcodeC08newProc106glyphsC0013printerStatusC00S5Proc40S5Proc50S5Proc6ABys5Int16V_SVSgSo5PointVA_tXCSg_yA_XCSgys4Int8V_SPySo0F0VGSgtXCSgyA3__A7_A2XtXCSgA8_A9_yA3__SpySpySo10MacPolygonVGSgGSgtXCSgyA3__s13OpaquePointerVSgtXCSgySPySo6BitMapVGSg_A7_A7_AXA19_tXCSgyAX_AXSpySpyA3_GSgGSgtXCSgA2X_AYSpyA_GSgA32_SpySo8FontInfoVGSgtXCSgySvSg_AXtXCSgyAY_AXtXCSgyA7__A7_s6UInt16VAXtXCSgSiyXCSgs5Int32VA38__SitXCSgA46_A46__A19_A38_tXCSgA44_A44_A44_tcfc"