| 
 | 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(input: input,  | 
 | 26 | +                             expected: expected,  | 
 | 27 | +                             linelength: 120,  | 
 | 28 | +                             whitespaceOnly: true,  | 
 | 29 | +                             findings: [  | 
 | 30 | +                                FindingSpec("1️⃣", message: "move end-of-line comment that exceeds the line length")  | 
 | 31 | +                             ])  | 
 | 32 | +  }  | 
 | 33 | + | 
 | 34 | +  func testLineNumbersWithComments() {  | 
 | 35 | +    let input =  | 
 | 36 | +    """  | 
 | 37 | +    // Copyright (C) 2024 My Coorp. All rights reserved.  | 
 | 38 | +    //  | 
 | 39 | +    // This document is the property of My Coorp.  | 
 | 40 | +    // It is considered confidential and proprietary.  | 
 | 41 | +    //  | 
 | 42 | +    // This document may not be reproduced or transmitted in any form,  | 
 | 43 | +    // in whole or in part, without the express written permission of  | 
 | 44 | +    // My Coorp.  | 
 | 45 | +      | 
 | 46 | +    final class A {  | 
 | 47 | +      @Test func b() throws {  | 
 | 48 | +        doSomethingInAFunctionWithAVeryLongName()  1️⃣// Here we have a very long comment that should not be here because it is far too long  | 
 | 49 | +      }  | 
 | 50 | +    }  | 
 | 51 | +    """  | 
 | 52 | + | 
 | 53 | +    let expected =  | 
 | 54 | +    """  | 
 | 55 | +    // Copyright (C) 2024 My Coorp. All rights reserved.  | 
 | 56 | +    //  | 
 | 57 | +    // This document is the property of My Coorp.  | 
 | 58 | +    // It is considered confidential and proprietary.  | 
 | 59 | +    //  | 
 | 60 | +    // This document may not be reproduced or transmitted in any form,  | 
 | 61 | +    // in whole or in part, without the express written permission of  | 
 | 62 | +    // My Coorp.  | 
 | 63 | +      | 
 | 64 | +    final class A {  | 
 | 65 | +      @Test func b() throws {  | 
 | 66 | +        doSomethingInAFunctionWithAVeryLongName()  // Here we have a very long comment that should not be here because it is far too long  | 
 | 67 | +      }  | 
 | 68 | +    }  | 
 | 69 | +      | 
 | 70 | +    """  | 
 | 71 | + | 
 | 72 | +    assertPrettyPrintEqual(input: input,  | 
 | 73 | +                           expected: expected,  | 
 | 74 | +                           linelength: 120,  | 
 | 75 | +                           whitespaceOnly: true,  | 
 | 76 | +                           findings: [  | 
 | 77 | +                              FindingSpec("1️⃣", message: "move end-of-line comment that exceeds the line length")  | 
 | 78 | +                           ])  | 
 | 79 | +  }  | 
 | 80 | +}  | 
0 commit comments