diff options
author | Dario Vladović <d.vladimyr@gmail.com> | 2021-05-03 21:48:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-03 21:48:58 +0200 |
commit | dead06ba14e30803f0027be8d46cc1f395d5d87e (patch) | |
tree | f1e9dc3ae2c0fb2aa36768332c2e969ca87e92a8 | |
parent | c60ddf76f699b46da1f44bf9c7715523672cf4ca (diff) |
test(ocaml): test custom switch indicators (#2657)
-rw-r--r-- | src/modules/ocaml.rs | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/modules/ocaml.rs b/src/modules/ocaml.rs index 6b33442e1..474983ba5 100644 --- a/src/modules/ocaml.rs +++ b/src/modules/ocaml.rs @@ -174,7 +174,7 @@ mod tests { File::create(dir.path().join("package.json"))?.sync_all()?; fs::write( dir.path().join("package.lock"), - "{\"dependencies\": {\"ocaml\": \"4.8.1000\"}}", + r#"{"dependencies": {"ocaml": "4.8.1000"}}"#, )?; let actual = ModuleRenderer::new("ocaml").path(dir.path()).collect(); let expected = Some(format!( @@ -357,6 +357,35 @@ mod tests { } #[test] + fn with_global_opam_switch_custom_indicator() -> io::Result<()> { + let dir = tempfile::tempdir()?; + File::create(dir.path().join("any.ml"))?.sync_all()?; + + let actual = ModuleRenderer::new("ocaml") + .config(toml::toml! { + [ocaml] + global_switch_indicator = "g/" + }) + .cmd( + "opam switch show --safe", + Some(CommandOutput { + stdout: String::from("ocaml-base-compiler.4.10.0\n"), + stderr: String::default(), + }), + ) + .path(dir.path()) + .collect(); + let expected = Some(format!( + "via {}", + Color::Yellow + .bold() + .paint("🐫 v4.10.0 (g/ocaml-base-compiler.4.10.0) ") + )); + assert_eq!(expected, actual); + dir.close() + } + + #[test] fn with_local_opam_switch() -> io::Result<()> { let dir = tempfile::tempdir()?; File::create(dir.path().join("any.ml"))?.sync_all()?; @@ -378,4 +407,31 @@ mod tests { assert_eq!(expected, actual); dir.close() } + + #[test] + fn with_local_opam_switch_custom_indicator() -> io::Result<()> { + let dir = tempfile::tempdir()?; + File::create(dir.path().join("any.ml"))?.sync_all()?; + + let actual = ModuleRenderer::new("ocaml") + .config(toml::toml! { + [ocaml] + local_switch_indicator = "^" + }) + .cmd( + "opam switch show --safe", + Some(CommandOutput { + stdout: String::from("/path/to/my-project\n"), + stderr: String::default(), + }), + ) + .path(dir.path()) + .collect(); + let expected = Some(format!( + "via {}", + Color::Yellow.bold().paint("🐫 v4.10.0 (^my-project) ") + )); + assert_eq!(expected, actual); + dir.close() + } } |