Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aeacba7
commit c358d4f
Showing
6 changed files
with
132 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
id: rust | ||
title: Rust | ||
sidebar_label: Rust | ||
--- | ||
|
||
## What | ||
|
||
Display the currently active rust version. | ||
|
||
## Sample Configuration | ||
|
||
```json | ||
{ | ||
"type": "rust", | ||
"style": "powerline", | ||
"powerline_symbol": "\uE0B0", | ||
"foreground": "#193549", | ||
"background": "#99908a", | ||
"properties": { | ||
"prefix": " \uE7a8 " | ||
} | ||
} | ||
``` | ||
|
||
## Properties | ||
|
||
- display_version: `boolean` - display the rust version (`rustc --version`) - defaults to `true` | ||
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` | ||
- missing_command_text: `string` - text to display when the command is missing - defaults to empty | ||
- display_mode: `string` - determines when the segment is displayed | ||
- `always`: the segment is always displayed | ||
- `files`: the segment is only displayed when `*.rs`, `Cargo.toml` or `Cargo.lock` files are present (default) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
type rust struct { | ||
language *language | ||
} | ||
|
||
func (r *rust) string() string { | ||
return r.language.string() | ||
} | ||
|
||
func (r *rust) init(props *properties, env environmentInfo) { | ||
r.language = &language{ | ||
env: env, | ||
props: props, | ||
extensions: []string{"*.rs", "Cargo.toml", "Cargo.lock"}, | ||
commands: []*cmd{ | ||
{ | ||
executable: "rustc", | ||
args: []string{"--version"}, | ||
regex: `rustc (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (r *rust) enabled() bool { | ||
return r.language.enabled() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRust(t *testing.T) { | ||
cases := []struct { | ||
Case string | ||
ExpectedString string | ||
Version string | ||
}{ | ||
{Case: "Rust 1.53.0", ExpectedString: "1.53.0", Version: "rustc 1.53.0 (4369396ce 2021-04-27)"}, | ||
} | ||
for _, tc := range cases { | ||
params := &mockedLanguageParams{ | ||
cmd: "rustc", | ||
versionParam: "--version", | ||
versionOutput: tc.Version, | ||
extension: "*.rs", | ||
} | ||
env, props := getMockedLanguageEnv(params) | ||
r := &rust{} | ||
r.init(props, env) | ||
assert.True(t, r.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case)) | ||
assert.Equal(t, tc.ExpectedString, r.string(), fmt.Sprintf("Failed in case: %s", tc.Case)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters