Skip to content

Commit

Permalink
feat: Rust support
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Lewis <ianlewis@google.com>
  • Loading branch information
ianlewis committed Jul 21, 2023
1 parent eab1187 commit 865c37e
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions internal/scanner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ var (
},
}

// RustConfig is a config for Rust.
RustConfig = CConfig

// ScalaConfig is a config for Scala.
ScalaConfig = JavaConfig

Expand Down
148 changes: 145 additions & 3 deletions internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -126,7 +126,7 @@ var scannerTestCases = []*struct {
// TODO is a function.
` + "`" + `
func TODO() {
func TODO() string {
// Random comment
x := "\"// Random comment"
y := '\'// Random comment'
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 865c37e

Please sign in to comment.