File: GroupNumericLiteralsTests.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 (60 lines) | stat: -rw-r--r-- 2,285 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import _SwiftFormatTestSupport

@_spi(Rules) import SwiftFormat

final class GroupNumericLiteralsTests: LintOrFormatRuleTestCase {
  func testNumericGrouping() {
    assertFormatting(
      GroupNumericLiterals.self,
      input: """
        let a = 1️⃣9876543210
        let b = 1234
        let c = 2️⃣0x34950309233
        let d = -0x34242
        let e = 3️⃣0b10010010101
        let f = 0b101
        let g = 11_15_1999
        let h = 0o21743
        let i = -4️⃣53096828347
        let j = 5️⃣0000123
        let k = 6️⃣0x00000012
        let l = 0x0000012
        let m = 7️⃣0b00010010101
        let n = [
          8️⃣0xff00ff00,  // comment
          9️⃣0x00ff00ff,  // comment
        ]
        """,
      expected: """
        let a = 9_876_543_210
        let b = 1234
        let c = 0x349_5030_9233
        let d = -0x34242
        let e = 0b100_10010101
        let f = 0b101
        let g = 11_15_1999
        let h = 0o21743
        let i = -53_096_828_347
        let j = 0_000_123
        let k = 0x0000_0012
        let l = 0x0000012
        let m = 0b000_10010101
        let n = [
          0xff00_ff00,  // comment
          0x00ff_00ff,  // comment
        ]
        """,
      findings: [
        FindingSpec("1️⃣", message: "group every 3 digits in this decimal literal using a '_' separator"),
        FindingSpec("2️⃣", message: "group every 4 digits in this hexadecimal literal using a '_' separator"),
        FindingSpec("3️⃣", message: "group every 8 digits in this binary literal using a '_' separator"),
        FindingSpec("4️⃣", message: "group every 3 digits in this decimal literal using a '_' separator"),
        FindingSpec("5️⃣", message: "group every 3 digits in this decimal literal using a '_' separator"),
        FindingSpec("6️⃣", message: "group every 4 digits in this hexadecimal literal using a '_' separator"),
        FindingSpec("7️⃣", message: "group every 8 digits in this binary literal using a '_' separator"),
        FindingSpec("8️⃣", message: "group every 4 digits in this hexadecimal literal using a '_' separator"),
        FindingSpec("9️⃣", message: "group every 4 digits in this hexadecimal literal using a '_' separator"),
      ]
    )
  }
}