use crate::common::TestEnvironment;
#[test]
fn test_cat() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
std::fs::write(repo_path.join("file1"), "a\n").unwrap();
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "b\n").unwrap();
std::fs::create_dir(repo_path.join("dir")).unwrap();
std::fs::write(repo_path.join("dir").join("file2"), "c\n").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "file1", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
a
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "file1"]);
insta::assert_snapshot!(stdout, @r###"
b
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["print", "file1"]);
insta::assert_snapshot!(stdout, @r###"
b
"###);
let subdir_file = if cfg!(unix) {
"dir/file2"
} else {
"dir\\file2"
};
let stdout = test_env.jj_cmd_success(&repo_path, &["cat", subdir_file]);
insta::assert_snapshot!(stdout, @r###"
c
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["cat", "nonexistent"]);
insta::assert_snapshot!(stderr, @r###"
Error: No such path
"###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["cat", "dir"]);
insta::assert_snapshot!(stderr, @r###"
Error: Path exists but is not a file
"###);
test_env.jj_cmd_ok(&repo_path, &["new"]);
std::fs::write(repo_path.join("file1"), "c\n").unwrap();
test_env.jj_cmd_ok(&repo_path, &["rebase", "-r", "@", "-d", "@--"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["cat", "file1"]);
insta::assert_snapshot!(stdout, @r###"
<<<<<<<
%%%%%%%
-b
+a
+++++++
c
>>>>>>>
"###);
}