diff options
author | Shu Kutsuzawa <cappyzawa@yahoo.ne.jp> | 2020-04-04 04:02:28 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 21:02:28 +0200 |
commit | bd016b6ce2648d66c0d1db7aeed158e769f03383 (patch) | |
tree | 47a0a0e75a42753a0649eb83699194da9af05360 /src | |
parent | e38be5073fd09ec1b199c6d542d34a7f76e3d5fd (diff) |
feat: Enable to display language version when `.<lang>-version` file exists. (#1028)
* adjust https://github.com/sonnym/elmenv
* adjust https://github.com/syndbg/goenv
* adjust https://github.com/jenv/jenv
* adjust https://github.com/nodenv/nodenv
* adjust https://github.com/phpenv/phpenv
* adjust https://github.com/rbenv/rbenv
* add description
* golang.rs is executed rustfmt
* add testcases
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/elm.rs | 13 | ||||
-rw-r--r-- | src/modules/golang.rs | 20 | ||||
-rw-r--r-- | src/modules/java.rs | 4 | ||||
-rw-r--r-- | src/modules/nodejs.rs | 15 | ||||
-rw-r--r-- | src/modules/php.rs | 19 | ||||
-rw-r--r-- | src/modules/ruby.rs | 16 |
6 files changed, 77 insertions, 10 deletions
diff --git a/src/modules/elm.rs b/src/modules/elm.rs index 8cfadfaa8..b6c1da4f9 100644 --- a/src/modules/elm.rs +++ b/src/modules/elm.rs @@ -8,12 +8,13 @@ use crate::utils; /// Will display the Elm version if any of the following criteria are met: /// - The current directory contains a `elm.json` file /// - The current directory contains a `elm-package.json` file +/// - The current directory contains a `.elm-version` file /// - The current directory contains a `elm-stuff` folder /// - The current directory contains a `*.elm` files pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { let is_elm_project = context .try_begin_scan()? - .set_files(&["elm.json", "elm-package.json"]) + .set_files(&["elm.json", "elm-package.json", ".elm-version"]) .set_extensions(&["elm"]) .set_folders(&["elm-stuff"]) .is_match(); @@ -73,6 +74,16 @@ mod tests { } #[test] + fn folder_with_elm_version() -> io::Result<()> { + let dir = tempfile::tempdir()?; + File::create(dir.path().join(".elm-version"))?.sync_all()?; + let actual = render_module("elm", dir.path()); + let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🌳 v0.19.1"))); + assert_eq!(expected, actual); + dir.close() + } + + #[test] fn folder_with_elm_stuff_directory() -> io::Result<()> { let dir = tempfile::tempdir()?; let elmstuff = dir.path().join("elm-stuff"); diff --git a/src/modules/golang.rs b/src/modules/golang.rs index 4bfc17c67..809b9b1c9 100644 --- a/src/modules/golang.rs +++ b/src/modules/golang.rs @@ -11,12 +11,20 @@ use crate::utils; /// - Current directory contains a `glide.yaml` file /// - Current directory contains a `Gopkg.yml` file /// - Current directory contains a `Gopkg.lock` file +/// - Current directory contains a `.go-version` file /// - Current directory contains a `Godeps` directory /// - Current directory contains a file with the `.go` extension pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { let is_go_project = context .try_begin_scan()? - .set_files(&["go.mod", "go.sum", "glide.yaml", "Gopkg.yml", "Gopkg.lock"]) + .set_files(&[ + "go.mod", + "go.sum", + "glide.yaml", + "Gopkg.yml", + "Gopkg.lock", + ".go-version", + ]) .set_extensions(&["go"]) .set_folders(&["Godeps"]) .is_match(); @@ -157,6 +165,16 @@ mod tests { assert_eq!(expected, actual); dir.close() } + #[test] + fn folder_with_go_version() -> io::Result<()> { + let dir = tempfile::tempdir()?; + File::create(dir.path().join(".go-version"))?.sync_all()?; + + let actual = render_module("golang", dir.path()); + let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🐹 v1.12.1"))); + assert_eq!(expected, actual); + dir.close() + } #[test] fn test_format_go_version() { diff --git a/src/modules/java.rs b/src/modules/java.rs index 1b9e709b1..177e95451 100644 --- a/src/modules/java.rs +++ b/src/modules/java.rs @@ -9,11 +9,11 @@ use crate::utils; /// /// Will display the Java version if any of the following criteria are met: /// - Current directory contains a file with a `.java`, `.class`, `.gradle` or `.jar` extension -/// - Current directory contains a `pom.xml`, `build.gradle.kts` or `build.sbt` file +/// - Current directory contains a `pom.xml`, `build.gradle.kts`, `build.sbt` or `.java-version` file pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { let is_java_project = context .try_begin_scan()? - .set_files(&["pom.xml", "build.gradle.kts", "build.sbt"]) + .set_files(&["pom.xml", "build.gradle.kts", "build.sbt", ".java-version"]) .set_extensions(&["java", "class", "jar", "gradle"]) .is_match(); diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs index d78ea5236..bc8c2c36f 100644 --- a/src/modules/nodejs.rs +++ b/src/modules/nodejs.rs @@ -7,12 +7,12 @@ use crate::utils; /// /// Will display the Node.js version if any of the following criteria are met: /// - Current directory contains a `.js` file -/// - Current directory contains a `package.json` file +/// - Current directory contains a `package.json` or `.node-version` file /// - Current directory contains a `node_modules` directory pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { let is_js_project = context .try_begin_scan()? - .set_files(&["package.json"]) + .set_files(&["package.json", ".node-version"]) .set_extensions(&["js"]) .set_folders(&["node_modules"]) .is_match(); @@ -64,6 +64,17 @@ mod tests { } #[test] + fn folder_with_node_version() -> io::Result<()> { + let dir = tempfile::tempdir()?; + File::create(dir.path().join(".node-version"))?.sync_all()?; + + let actual = render_module("nodejs", dir.path()); + let expected = Some(format!("via {} ", Color::Green.bold().paint("⬢ v12.0.0"))); + assert_eq!(expected, actual); + dir.close() + } + + #[test] fn folder_with_js_file() -> io::Result<()> { let dir = tempfile::tempdir()?; File::create(dir.path().join("index.js"))?.sync_all()?; diff --git a/src/modules/php.rs b/src/modules/php.rs index 878cdb2ae..59ee4c26e 100644 --- a/src/modules/php.rs +++ b/src/modules/php.rs @@ -7,11 +7,11 @@ use crate::utils; /// /// Will display the PHP version if any of the following criteria are met: /// - Current directory contains a `.php` file -/// - Current directory contains a `composer.json` file +/// - Current directory contains a `composer.json` or `.php-version` file pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { let is_php_project = context .try_begin_scan()? - .set_files(&["composer.json"]) + .set_files(&["composer.json", ".php-version"]) .set_extensions(&["php"]) .is_match(); @@ -93,6 +93,21 @@ mod tests { } #[test] + fn folder_with_php_version() -> io::Result<()> { + let dir = tempfile::tempdir()?; + File::create(dir.path().join(".php-version"))?.sync_all()?; + + let actual = render_module("php", dir.path()); + + let expected = Some(format!( + "via {} ", + Color::Fixed(147).bold().paint("🐘 v7.3.8") + )); + assert_eq!(expected, actual); + dir.close() + } + + #[test] fn folder_with_php_file() -> io::Result<()> { let dir = tempfile::tempdir()?; File::create(dir.path().join("any.php"))?.sync_all()?; diff --git a/src/modules/ruby.rs b/src/modules/ruby.rs index f50e80256..152a72f0d 100644 --- a/src/modules/ruby.rs +++ b/src/modules/ruby.rs @@ -7,11 +7,11 @@ use crate::utils; /// /// Will display the Ruby version if any of the following criteria are met: /// - Current directory contains a `.rb` file -/// - Current directory contains a `Gemfile` file +/// - Current directory contains a `Gemfile` or `.ruby-version` file pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { let is_rb_project = context .try_begin_scan()? - .set_files(&["Gemfile"]) + .set_files(&["Gemfile", ".ruby-version"]) .set_extensions(&["rb"]) .is_match(); @@ -79,6 +79,18 @@ mod tests { } #[test] + fn folder_with_ruby_version() -> io::Result<()> { + let dir = tempfile::tempdir()?; + File::create(dir.path().join(".ruby-version"))?.sync_all()?; + + let actual = render_module("ruby", dir.path()); + + let expected = Some(format!("via {} ", Color::Red.bold().paint("💎 v2.5.1"))); + assert_eq!(expected, actual); + dir.close() + } + + #[test] fn folder_with_rb_file() -> io::Result<()> { let dir = tempfile::tempdir()?; File::create(dir.path().join("any.rb"))?.sync_all()?; |