File: GroupNumericLiteralsTests.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (59 lines) | stat: -rw-r--r-- 2,284 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
@_spi(Rules) import SwiftFormat
import _SwiftFormatTestSupport

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"),
      ]
    )
  }
}