feat: add multiple buffers and file switching
This commit is contained in:
@@ -155,6 +155,67 @@ Vamp.command("healthy") { |editor, args| editor.replace "healthy #{args}" }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buffers_share_config_and_plugin_host_but_keep_history_and_protect_hidden_edits() {
|
||||
let fixture = Fixture::new();
|
||||
let first = fixture.file("buffer.txt", "alpha");
|
||||
let second = fixture.file("second.txt", "beta");
|
||||
fixture.file(
|
||||
"shared.rb",
|
||||
r##"
|
||||
Vamp.plugin "shared", requires: ["text"]
|
||||
calls = 0
|
||||
Vamp.command("stamp") do |editor, _|
|
||||
calls += 1
|
||||
editor.insert "#{calls}:#{File.basename(editor.path)}:"
|
||||
end
|
||||
Vamp.command("fail") { |_, _| raise "shared host failure" }
|
||||
"##,
|
||||
);
|
||||
let mut session = fixture.open(
|
||||
r#"
|
||||
Vamp.configure do |config|
|
||||
config.plugin "shared.rb"
|
||||
config.bind "g", "stamp"
|
||||
end
|
||||
"#,
|
||||
);
|
||||
session.handle(Input::Char('g'));
|
||||
assert_eq!(session.editor().lines(), &["1:buffer.txt:alpha"]);
|
||||
session.execute(&format!("edit {}", second.display()));
|
||||
assert_eq!(session.editor().buffer_id(), 2);
|
||||
session.handle(Input::Char('g'));
|
||||
assert_eq!(session.editor().lines(), &["2:second.txt:beta"]);
|
||||
session.execute("bdelete");
|
||||
assert_eq!(session.editor().buffer_id(), 2);
|
||||
assert_eq!(session.editor().buffer_count(), 2);
|
||||
session.handle(Input::Char('u'));
|
||||
assert_eq!(session.editor().lines(), &["beta"]);
|
||||
session.execute("q");
|
||||
assert!(!session.editor().should_quit());
|
||||
session.execute("wq");
|
||||
assert!(!session.editor().should_quit());
|
||||
assert_eq!(fs::read_to_string(&first).unwrap(), "alpha");
|
||||
assert_eq!(fs::read_to_string(&second).unwrap(), "beta");
|
||||
session.execute("buffer 1");
|
||||
assert_eq!(session.editor().lines(), &["1:buffer.txt:alpha"]);
|
||||
session.handle(Input::Char('u'));
|
||||
assert_eq!(session.editor().lines(), &["alpha"]);
|
||||
session.handle(Input::Char('g'));
|
||||
assert_eq!(session.editor().lines(), &["3:buffer.txt:alpha"]);
|
||||
session.execute("w");
|
||||
assert_eq!(fs::read_to_string(&first).unwrap(), "3:buffer.txt:alpha");
|
||||
session.execute("bnext");
|
||||
assert_eq!(session.editor().lines(), &["beta"]);
|
||||
session.execute("fail");
|
||||
assert!(session.editor().message().contains("disabled"));
|
||||
session.execute("buffer 1");
|
||||
session.handle(Input::Char('g'));
|
||||
assert_eq!(session.editor().lines(), &["3:buffer.txt:alpha"]);
|
||||
session.execute("q");
|
||||
assert!(session.editor().should_quit());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typed_palette_binding_prepares_arguments_and_retires_failed_plugin_commands() {
|
||||
let fixture = Fixture::new();
|
||||
|
||||
Reference in New Issue
Block a user