// Part of the Carbon Language project, under the Apache License v2.0 with LLVM // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // // AUTOUPDATE // TIP: To test this file alone, run: // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/format/testdata/basics/comments.carbon // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/format/testdata/basics/comments.carbon // --- test.carbon // A comment fn F() {} // Another comment // Block // comment class C { // Internal comment } // Another // Block // // Comment // A trailing comment may follow a variable, a function call, or a closing // brace, and the formatter keeps it on the line it annotates. var count: i32 = 0; // a) A local variable, fn Render(frame: Frame) { Draw(frame); // b) A function call, Flush(); } // c) And a closing brace. // A trailing comment on a block string literal's introducer line is carried // within the literal token and is preserved, with or without a file type // indicator. A trailing comment after the literal's closing line stays // attached to that line. var query: String = '''sql // TODO: switch to a prepared statement SELECT * FROM t '''; var poem: String = ''' // No file type indicator, just a comment. Roses are red. '''; // A trailing comment after the closing line. // --- AUTOUPDATE-SPLIT // CHECK:STDOUT: // A comment // CHECK:STDOUT: fn F() {} // CHECK:STDOUT: // CHECK:STDOUT: // Another comment // CHECK:STDOUT: // Block // CHECK:STDOUT: // comment // CHECK:STDOUT: class C { // CHECK:STDOUT: // Internal comment // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: // Another // CHECK:STDOUT: // Block // CHECK:STDOUT: // // CHECK:STDOUT: // Comment // CHECK:STDOUT: // A trailing comment may follow a variable, a function call, or a closing // CHECK:STDOUT: // brace, and the formatter keeps it on the line it annotates. // CHECK:STDOUT: var count: i32 = 0; // a) A local variable, // CHECK:STDOUT: fn Render(frame: Frame) { // CHECK:STDOUT: Draw(frame); // b) A function call, // CHECK:STDOUT: Flush(); // CHECK:STDOUT: } // c) And a closing brace. // CHECK:STDOUT: // A trailing comment on a block string literal's introducer line is carried // CHECK:STDOUT: // within the literal token and is preserved, with or without a file type // CHECK:STDOUT: // indicator. A trailing comment after the literal's closing line stays // CHECK:STDOUT: // attached to that line. // CHECK:STDOUT: var query: String = '''sql // TODO: switch to a prepared statement // CHECK:STDOUT: SELECT * FROM t // CHECK:STDOUT: '''; // CHECK:STDOUT: // CHECK:STDOUT: var poem: String = ''' // No file type indicator, just a comment. // CHECK:STDOUT: Roses are red. // CHECK:STDOUT: '''; // A trailing comment after the closing line.