diff --git a/CHANGELOG.md b/CHANGELOG.md index 991baef..ea49497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- Support for [Rust](https://www.rust-lang.org/) was added. + ## [0.2.0] - 2023-06-30 ### Changed in 0.2.0 diff --git a/internal/scanner/config.go b/internal/scanner/config.go index 5cbac45..8d09f85 100644 --- a/internal/scanner/config.go +++ b/internal/scanner/config.go @@ -183,6 +183,9 @@ var ( }, } + // RustConfig is a config for Rust. + RustConfig = CConfig + // ScalaConfig is a config for Scala. ScalaConfig = JavaConfig diff --git a/internal/scanner/scanner_test.go b/internal/scanner/scanner_test.go index d4ebad3..dc7c65b 100644 --- a/internal/scanner/scanner_test.go +++ b/internal/scanner/scanner_test.go @@ -71,7 +71,7 @@ var scannerTestCases = []*struct { // package comment // TODO is a function. - func TODO() { + func TODO() string { x := "// Random comment" y := '// Random comment' return x + y @@ -97,7 +97,7 @@ var scannerTestCases = []*struct { // package comment // TODO is a function. - func TODO() { + func TODO() string { x := "\"// Random comment" y := '\'// Random comment' return x + y @@ -126,7 +126,7 @@ var scannerTestCases = []*struct { // TODO is a function. ` + "`" + ` - func TODO() { + func TODO() string { // Random comment x := "\"// Random comment" y := '\'// Random comment' @@ -416,6 +416,148 @@ var scannerTestCases = []*struct { }, }, + // Rust + { + name: "line_comments.rs", + src: `// file comment + + // TODO is a function. + fn TODO() { + println!("fizzbuzz"); // Random comment + }`, + config: RustConfig, + comments: []struct { + text string + line int + }{ + { + text: "// file comment", + line: 1, + }, + { + text: "// TODO is a function.", + line: 3, + }, + { + text: "// Random comment", + line: 5, + }, + }, + }, + { + name: "comments_in_string.rs", + src: `// file comment + + // TODO is a function. + fn TODO() { + let x: String = "// Random comment"; + let y: String = '// Random comment'; + x + y + }`, + config: RustConfig, + comments: []struct { + text string + line int + }{ + { + text: "// file comment", + line: 1, + }, + { + text: "// TODO is a function.", + line: 3, + }, + }, + }, + { + name: "escaped_string.rs", + src: `// file comment + + // TODO is a function. + fn TODO() { + let x: String "\"// Random comment"; + let y: String '\'// Random comment'; + x + y + }`, + config: RustConfig, + comments: []struct { + text string + line int + }{ + { + text: "// file comment", + line: 1, + }, + { + text: "// TODO is a function.", + line: 3, + }, + }, + }, + { + name: "multi_line_string.rs", + src: `// file comment + + let z: String = " + // TODO is a function. + "; + + fn TODO() -> String { + // Random comment + let x: String = "\"// Random comment"; + let y: String = '\'// Random comment'; + x + y + }`, + config: RustConfig, + comments: []struct { + text string + line int + }{ + { + text: "// file comment", + line: 1, + }, + { + text: "// Random comment", + line: 8, + }, + }, + }, + { + name: "multi_line.rs", + src: `// file comment + + /* + TODO is a function. + */ + fn TODO() { + println!("fizzbuzz"); // Random comment + } + /* extra comment */`, + config: GoConfig, + comments: []struct { + text string + line int + }{ + { + text: "// file comment", + line: 1, + }, + { + text: "/*\n\t\t\tTODO is a function.\n\t\t\t*/", + line: 3, + }, + { + text: "// Random comment", + line: 7, + }, + { + text: "/* extra comment */", + line: 9, + }, + }, + }, + // Shell { name: "line_comments.sh",