From dead06ba14e30803f0027be8d46cc1f395d5d87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dario=20Vladovi=C4=87?= Date: Mon, 3 May 2021 21:48:58 +0200 Subject: test(ocaml): test custom switch indicators (#2657) --- src/modules/ocaml.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) 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!( @@ -356,6 +356,35 @@ mod tests { dir.close() } + #[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()?; @@ -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() + } } -- cgit v1.2.3