| 
 | 1 | +import SwiftFormat  | 
 | 2 | +import _SwiftFormatTestSupport  | 
 | 3 | + | 
 | 4 | +final class LineNumbersTests: PrettyPrintTestCase {  | 
 | 5 | +  func testLineNumbers() {  | 
 | 6 | +    let input =  | 
 | 7 | +      """  | 
 | 8 | +      final class A {  | 
 | 9 | +        @Test func b() throws {  | 
 | 10 | +          doSomethingInAFunctionWithAVeryLongName()  1️⃣// Here we have a very long comment that should not be here because it is far too long  | 
 | 11 | +        }  | 
 | 12 | +      }  | 
 | 13 | +      """  | 
 | 14 | + | 
 | 15 | +    let expected =  | 
 | 16 | +      """  | 
 | 17 | +      final class A {  | 
 | 18 | +        @Test func b() throws {  | 
 | 19 | +          doSomethingInAFunctionWithAVeryLongName()  // Here we have a very long comment that should not be here because it is far too long  | 
 | 20 | +        }  | 
 | 21 | +      }  | 
 | 22 | +
  | 
 | 23 | +      """  | 
 | 24 | + | 
 | 25 | +    assertPrettyPrintEqual(  | 
 | 26 | +      input: input,  | 
 | 27 | +      expected: expected,  | 
 | 28 | +      linelength: 120,  | 
 | 29 | +      whitespaceOnly: true,  | 
 | 30 | +      findings: [  | 
 | 31 | +        FindingSpec("1️⃣", message: "move end-of-line comment that exceeds the line length")  | 
 | 32 | +      ]  | 
 | 33 | +    )  | 
 | 34 | +  }  | 
 | 35 | + | 
 | 36 | +  func testLineNumbersWithComments() {  | 
 | 37 | +    let input =  | 
 | 38 | +      """  | 
 | 39 | +      // Copyright (C) 2024 My Coorp. All rights reserved.  | 
 | 40 | +      //  | 
 | 41 | +      // This document is the property of My Coorp.  | 
 | 42 | +      // It is considered confidential and proprietary.  | 
 | 43 | +      //  | 
 | 44 | +      // This document may not be reproduced or transmitted in any form,  | 
 | 45 | +      // in whole or in part, without the express written permission of  | 
 | 46 | +      // My Coorp.  | 
 | 47 | +
  | 
 | 48 | +      final class A {  | 
 | 49 | +        @Test func b() throws {  | 
 | 50 | +          doSomethingInAFunctionWithAVeryLongName()  1️⃣// Here we have a very long comment that should not be here because it is far too long  | 
 | 51 | +        }  | 
 | 52 | +      }  | 
 | 53 | +      """  | 
 | 54 | + | 
 | 55 | +    let expected =  | 
 | 56 | +      """  | 
 | 57 | +      // Copyright (C) 2024 My Coorp. All rights reserved.  | 
 | 58 | +      //  | 
 | 59 | +      // This document is the property of My Coorp.  | 
 | 60 | +      // It is considered confidential and proprietary.  | 
 | 61 | +      //  | 
 | 62 | +      // This document may not be reproduced or transmitted in any form,  | 
 | 63 | +      // in whole or in part, without the express written permission of  | 
 | 64 | +      // My Coorp.  | 
 | 65 | +
  | 
 | 66 | +      final class A {  | 
 | 67 | +        @Test func b() throws {  | 
 | 68 | +          doSomethingInAFunctionWithAVeryLongName()  // Here we have a very long comment that should not be here because it is far too long  | 
 | 69 | +        }  | 
 | 70 | +      }  | 
 | 71 | +
  | 
 | 72 | +      """  | 
 | 73 | + | 
 | 74 | +    assertPrettyPrintEqual(  | 
 | 75 | +      input: input,  | 
 | 76 | +      expected: expected,  | 
 | 77 | +      linelength: 120,  | 
 | 78 | +      whitespaceOnly: true,  | 
 | 79 | +      findings: [  | 
 | 80 | +        FindingSpec("1️⃣", message: "move end-of-line comment that exceeds the line length")  | 
 | 81 | +      ]  | 
 | 82 | +    )  | 
 | 83 | +  }  | 
 | 84 | +}  | 
0 commit comments