diff --git a/Cargo.lock b/Cargo.lock index ff98c0e..c2bfd5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -80,7 +80,7 @@ checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" dependencies = [ "addr2line", "cc", - "cfg-if 1.0.0", + "cfg-if", "libc", "miniz_oxide", "object", @@ -165,12 +165,6 @@ version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -221,9 +215,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.1.1" +version = "4.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec7a4128863c188deefe750ac1d1dfe66c236909f845af04beed823638dc1b2" +checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5" dependencies = [ "bitflags", "clap_derive", @@ -236,18 +230,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.1.0" +version = "4.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce8955d4e8cd4f28f9a01c93a050194c4d131e73ca02f6636bcddbed867014d7" +checksum = "501ff0a401473ea1d4c3b125ff95506b62c5bc5768d818634195fbb7c4ad5ff4" dependencies = [ - "clap 4.1.1", + "clap 4.1.8", ] [[package]] name = "clap_derive" -version = "4.1.0" +version = "4.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" +checksum = "44bec8e5c9d09e439c4335b1af0abaab56dcf3b94999a936e1bb47b9134288f0" dependencies = [ "heck", "proc-macro-error", @@ -356,7 +350,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -365,22 +359,12 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" dependencies = [ - "cfg-if 1.0.0", - "crossbeam-channel 0.5.6", + "cfg-if", + "crossbeam-channel", "crossbeam-deque", "crossbeam-epoch", "crossbeam-queue", - "crossbeam-utils 0.8.11", -] - -[[package]] -name = "crossbeam-channel" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" -dependencies = [ - "crossbeam-utils 0.7.2", - "maybe-uninit", + "crossbeam-utils", ] [[package]] @@ -389,8 +373,8 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" dependencies = [ - "cfg-if 1.0.0", - "crossbeam-utils 0.8.11", + "cfg-if", + "crossbeam-utils", ] [[package]] @@ -399,9 +383,9 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "crossbeam-epoch", - "crossbeam-utils 0.8.11", + "crossbeam-utils", ] [[package]] @@ -411,8 +395,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" dependencies = [ "autocfg", - "cfg-if 1.0.0", - "crossbeam-utils 0.8.11", + "cfg-if", + "crossbeam-utils", "memoffset", "once_cell", "scopeguard", @@ -424,19 +408,8 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cd42583b04998a5363558e5f9291ee5a5ff6b49944332103f251e7479a82aa7" dependencies = [ - "cfg-if 1.0.0", - "crossbeam-utils 0.8.11", -] - -[[package]] -name = "crossbeam-utils" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" -dependencies = [ - "autocfg", - "cfg-if 0.1.10", - "lazy_static", + "cfg-if", + "crossbeam-utils", ] [[package]] @@ -445,7 +418,7 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "once_cell", ] @@ -486,11 +459,11 @@ dependencies = [ [[package]] name = "defer-drop" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "828aca0e5e4341b0320a319209cbc6255b8b06254849ce8a5f33d33f7f2fa0f0" +checksum = "f613ec9fa66a6b28cdb1842b27f9adf24f39f9afc4dcdd9fdecee4aca7945c57" dependencies = [ - "crossbeam-channel 0.4.4", + "crossbeam-channel", "once_cell", ] @@ -558,7 +531,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a28ccebc1239c5c57f0c55986e2ac03f49af0d0ca3dff29bfcad39d60a8be56" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "dirs-sys-next", ] @@ -568,7 +541,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "dirs-sys-next", ] @@ -756,7 +729,7 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi 0.11.0+wasi-snapshot-preview1", ] @@ -903,7 +876,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -1001,7 +974,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -1019,12 +992,6 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - [[package]] name = "memchr" version = "2.5.0" @@ -1057,7 +1024,7 @@ checksum = "5c3728fec49d363a50a8828a190b379a446cc5cf085c06259bbbeb34447e4ec7" dependencies = [ "bitflags", "cc", - "cfg-if 1.0.0", + "cfg-if", "libc", "memoffset", ] @@ -1069,7 +1036,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" dependencies = [ "bitflags", - "cfg-if 1.0.0", + "cfg-if", "libc", ] @@ -1081,7 +1048,7 @@ checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" dependencies = [ "autocfg", "bitflags", - "cfg-if 1.0.0", + "cfg-if", "libc", "memoffset", "pin-utils", @@ -1210,7 +1177,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "instant", "libc", "redox_syscall", @@ -1349,9 +1316,9 @@ version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" dependencies = [ - "crossbeam-channel 0.5.6", + "crossbeam-channel", "crossbeam-deque", - "crossbeam-utils 0.8.11", + "crossbeam-utils", "num_cpus", ] @@ -1398,15 +1365,6 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - [[package]] name = "ring" version = "0.16.20" @@ -1505,15 +1463,15 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.152" +version = "1.0.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "8cdd151213925e7f1ab45a9bbfb129316bd00799784b174b7cc7bcd16961c49e" [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "4fc80d722935453bcafdc2c9a73cd6fac4dc1938f0346035d84bf99fa9e33217" dependencies = [ "proc-macro2", "quote", @@ -1522,9 +1480,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.91" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" dependencies = [ "itoa", "ryu", @@ -1533,9 +1491,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.16" +version = "0.9.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92b5b431e8907b50339b51223b97d102db8d987ced36f6e4d03621db9316c834" +checksum = "f82e6c8c047aa50a7328632d067bcae6ef38772a79e28daf32f735e0e4f3dd10" dependencies = [ "indexmap", "itoa", @@ -1558,9 +1516,9 @@ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "skim" -version = "0.10.2" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cebed5f897cd6c0d80fbe30adb36c0abf7400e93043a63ae56458495642b3485" +checksum = "e5d28de0a6cb2cdd83a076f1de9d965b973ae08b244df1aa70b432946dda0f32" dependencies = [ "atty", "beef", @@ -1593,7 +1551,7 @@ checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935" dependencies = [ "crc32fast", "crossbeam-epoch", - "crossbeam-utils 0.8.11", + "crossbeam-utils", "fs2", "fxhash", "libc", @@ -1674,16 +1632,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "fastrand", - "libc", "redox_syscall", - "remove_dir_all", - "winapi", + "rustix", + "windows-sys", ] [[package]] @@ -1736,7 +1693,7 @@ dependencies = [ "bincode", "chrono", "chrono-english", - "clap 4.1.1", + "clap 4.1.8", "clap_complete", "clipboard", "color-eyre", @@ -1767,18 +1724,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" dependencies = [ "proc-macro2", "quote", @@ -1892,9 +1849,9 @@ checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unsafe-libyaml" -version = "0.2.4" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68" +checksum = "ad2024452afd3874bf539695e04af6732ba06517424dbf958fdb16a01f3bef6c" [[package]] name = "untrusted" @@ -2003,7 +1960,7 @@ version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen-macro", ] diff --git a/Cargo.toml b/Cargo.toml index 95cce29..df0121c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,8 +17,8 @@ exclude = [ [dependencies] # Argument parsing -clap = { version = "4.1.1", features = ["derive"] } -clap_complete = "4.1.0" +clap = { version = "4.1.8", features = ["derive"] } +clap_complete = "4.1.4" # Configuration management confy = "0.5.1" @@ -27,17 +27,17 @@ directories-next = "1.0.2" # Error management eyre = "0.6.8" color-eyre = { version = "0.6.2", default-features = false } -thiserror = "1.0.38" +thiserror = "1.0.39" # Database related sled = "0.34.7" bincode = "1.3.3" # Serializing -serde = "1.0.152" -serde_json = "1.0.91" -serde_derive = "1.0.152" -serde_yaml = "0.9.16" +serde = "1.0.154" +serde_json = "1.0.94" +serde_derive = "1.0.154" +serde_yaml = "0.9.19" # Parsing and manipulating dates chrono = { version = "0.4.23", features = ["serde"] } @@ -48,7 +48,7 @@ dialoguer = "0.10.3" indicatif = "0.17.3" # Fuzzy search -skim = "0.10.2" +skim = "0.10.4" # Terminal syntax highlighting syntect = { version = "5.0.0", default-features = false, features = ["default-fancy"] } @@ -67,7 +67,7 @@ regex = "1.7.1" [dev-dependencies] assert_cmd = "2.0.8" predicates = "2.1.5" -tempfile = "3.3.0" +tempfile = "3.4.0" expectrl = "0.6.0" [target.'cfg(target_os = "macos")'.dev-dependencies] diff --git a/src/the_way/gist.rs b/src/the_way/gist.rs index 8183447..1e24a8e 100644 --- a/src/the_way/gist.rs +++ b/src/the_way/gist.rs @@ -354,12 +354,13 @@ impl TheWay { ); SyncAction::Uploaded } else if source == SyncCommand::Gist - || (source == SyncCommand::Date && snippet.updated < gist.updated_at) + || (source == SyncCommand::Date && snippet.updated <= gist.updated_at) { // Snippet updated in Gist or source is Gist => update local snippet let index_key = gist_snippet.index.to_string(); let index_key = index_key.as_bytes(); self.add_to_snippet(index_key, &gist_snippet.to_bytes()?)?; + *snippet = gist_snippet.clone(); SyncAction::Downloaded } else { // Update dates match @@ -442,15 +443,15 @@ impl TheWay { }, )?; } - spinner.finish_with_message("Done!"); - let mut max_index = 0; + let mut max_index = self.get_current_snippet_index()?; for snippet in add_snippets { let index = self.add_snippet(snippet)?; if index > max_index { max_index = index; } } - self.modify_snippet_index(max_index + 1)?; + self.modify_snippet_index(max_index)?; + spinner.finish_with_message("Done!"); let delete = if delete_snippets.is_empty() || force { true } else { diff --git a/src/the_way/snippet.rs b/src/the_way/snippet.rs index 60d5775..ed4e9b3 100644 --- a/src/the_way/snippet.rs +++ b/src/the_way/snippet.rs @@ -59,7 +59,7 @@ impl Hash for Snippet { impl Snippet { /// New snippet #[allow(clippy::too_many_arguments)] - pub(crate) fn new( + pub fn new( index: usize, description: String, language: String, diff --git a/tests/cli.rs b/tests/cli.rs index 587cb72..2bbc88d 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -3,11 +3,14 @@ use std::fs; use std::path::{Path, PathBuf}; use assert_cmd::Command; +use chrono::Utc; use expectrl::repl::{spawn_bash, ReplSession}; +use expectrl::Regex; use predicates::prelude::*; use tempfile::{tempdir, TempDir}; use the_way::configuration::TheWayConfig; use the_way::gist::{Gist, GistClient, GistContent, UpdateGistPayload}; +use the_way::the_way::snippet::Snippet; fn setup_the_way() -> color_eyre::Result<(TempDir, PathBuf)> { let temp_dir = tempdir()?; @@ -96,30 +99,28 @@ fn change_theme() -> color_eyre::Result<()> { Ok(()) } -fn add_snippet_interactive(config_file: &Path) -> color_eyre::Result { - let mut p = spawn_bash()?; - p.send_line(&format!( - "export THE_WAY_CONFIG={}", - config_file.to_string_lossy() - ))?; - +fn add_snippet_interactive( + p: &mut ReplSession, + snippet: &Snippet, + index: usize, +) -> color_eyre::Result<()> { let executable = env!("CARGO_BIN_EXE_the-way"); - p.expect_prompt()?; - p.send_line(&format!("{executable} config get"))?; - p.expect(config_file.to_string_lossy().as_ref())?; - p.expect_prompt()?; p.send_line(&format!("{executable} new"))?; p.expect("Description")?; - p.send_line("test description 1")?; + p.send_line(&snippet.description)?; p.expect("Language")?; - p.send_line("rust")?; + p.send_line(&snippet.language)?; p.expect("Tags")?; - p.send_line("tag1 tag2")?; + p.send_line(snippet.tags.join(" "))?; p.expect("Code snippet")?; - p.send_line("code")?; - p.expect("Snippet #1 added")?; + p.send_line(&snippet.code)?; + let index_match = p.expect(Regex("Snippet #([0-9]+) added")).unwrap(); + assert_eq!( + index, + String::from_utf8(index_match.get(1).unwrap().to_vec())?.parse::()? + ); p.expect_prompt()?; - Ok(p) + Ok(()) } fn add_two_snippets_interactive(config_file: &Path) -> color_eyre::Result<()> { @@ -133,33 +134,61 @@ fn add_two_snippets_interactive(config_file: &Path) -> color_eyre::Result<()> { p.expect_prompt()?; p.send_line(&format!("{executable} config get"))?; p.expect(config_file.to_string_lossy().as_ref())?; - p.send_line(&format!("{executable} new"))?; - p.expect("Description")?; - p.send_line("test description 1")?; - p.expect("Language")?; - p.send_line("rust")?; - p.expect("Tags")?; - p.send_line("tag1 tag2")?; - p.expect("Code snippet")?; - p.send_line("code")?; - p.expect("Snippet #1 added")?; - p.expect_prompt()?; - p.send_line(&format!("{executable} new"))?; - p.expect("Description")?; - p.send_line("test description 2")?; - p.expect("Language")?; - p.send_line("python")?; - p.expect("Tags")?; - p.send_line("tag1 tag2")?; - p.expect("Code snippet")?; - p.send_line("code")?; - p.expect("Snippet #2 added")?; + add_snippet_interactive( + &mut p, + &Snippet::new( + 1, + "test description 1".to_string(), + "rust".to_string(), + "rs".to_string(), + "tag1 tag2", + Utc::now(), + Utc::now(), + "code".to_string(), + ), + 1, + )?; + add_snippet_interactive( + &mut p, + &Snippet::new( + 2, + "test description 2".to_string(), + "python".to_string(), + "py".to_string(), + "tag1 tag2", + Utc::now(), + Utc::now(), + "code".to_string(), + ), + 2, + )?; Ok(()) } fn change_snippet_interactive(config_file: &Path) -> color_eyre::Result<()> { - let mut p = add_snippet_interactive(config_file)?; + let mut p = spawn_bash()?; + p.send_line(&format!( + "export THE_WAY_CONFIG={}", + config_file.to_string_lossy() + ))?; let executable = env!("CARGO_BIN_EXE_the-way"); + p.expect_prompt()?; + p.send_line(&format!("{executable} config get"))?; + p.expect(config_file.to_string_lossy().as_ref())?; + add_snippet_interactive( + &mut p, + &Snippet::new( + 1, + "test description 1".to_string(), + "rust".to_string(), + "rs".to_string(), + "tag1 tag2", + Utc::now(), + Utc::now(), + "code".to_string(), + ), + 1, + )?; p.send_line(&format!("{executable} edit 1"))?; p.expect("Description")?; p.send_line("test description 2")?; @@ -211,16 +240,6 @@ fn add_two_cmd_snippets_interactive(config_file: &Path) -> color_eyre::Result<() Ok(()) } -#[ignore] // expensive, and change_snippet tests both -#[test] -fn add_snippet() -> color_eyre::Result<()> { - let (temp_dir, config_file) = setup_the_way()?; - assert!(add_snippet_interactive(&config_file).is_ok()); - drop(config_file); - temp_dir.close()?; - Ok(()) -} - #[test] fn add_two_snippets() -> color_eyre::Result<()> { let (temp_dir, config_file) = setup_the_way()?; @@ -763,6 +782,38 @@ fn sync_date() -> color_eyre::Result<()> { .assert() .failure(); + // check adding new snippet locally has index 4 + let mut p = spawn_bash()?; + p.send_line(&format!( + "export THE_WAY_CONFIG={}", + config_file.to_string_lossy() + ))?; + let executable = env!("CARGO_BIN_EXE_the-way"); + p.expect_prompt()?; + p.send_line(&format!("{executable} config get"))?; + p.expect(config_file.to_string_lossy().as_ref())?; + add_snippet_interactive( + &mut p, + &Snippet::new( + 4, + "test description 1".to_string(), + "rust".to_string(), + "rs".to_string(), + "tag1 tag2", + Utc::now(), + Utc::now(), + "code".to_string(), + ), + 4, + )?; + let mut cmd = Command::cargo_bin("the-way")?; + cmd.env("THE_WAY_CONFIG", &config_file) + .env("THE_WAY_GITHUB_TOKEN", token) + .arg("view") + .arg("4") + .assert() + .success(); + // delete Gist assert!(client.delete_gist(&gist.id).is_ok()); assert!(client.get_gist(&gist.id).is_err()); @@ -843,6 +894,38 @@ fn sync_local() -> color_eyre::Result<()> { .assert() .failure(); + // check adding new snippet locally has index 4 + let mut p = spawn_bash()?; + p.send_line(&format!( + "export THE_WAY_CONFIG={}", + config_file.to_string_lossy() + ))?; + let executable = env!("CARGO_BIN_EXE_the-way"); + p.expect_prompt()?; + p.send_line(&format!("{executable} config get"))?; + p.expect(config_file.to_string_lossy().as_ref())?; + add_snippet_interactive( + &mut p, + &Snippet::new( + 4, + "test description 1".to_string(), + "rust".to_string(), + "rs".to_string(), + "tag1 tag2", + Utc::now(), + Utc::now(), + "code".to_string(), + ), + 4, + )?; + let mut cmd = Command::cargo_bin("the-way")?; + cmd.env("THE_WAY_CONFIG", &config_file) + .env("THE_WAY_GITHUB_TOKEN", token) + .arg("view") + .arg("4") + .assert() + .success(); + // delete Gist assert!(client.delete_gist(&gist.id).is_ok()); assert!(client.get_gist(&gist.id).is_err()); @@ -941,6 +1024,38 @@ fn sync_gist() -> color_eyre::Result<()> { .assert() .stdout(predicate::str::contains("fourth")); + // check adding new snippet locally has index 5 + let mut p = spawn_bash()?; + p.send_line(&format!( + "export THE_WAY_CONFIG={}", + config_file.to_string_lossy() + ))?; + let executable = env!("CARGO_BIN_EXE_the-way"); + p.expect_prompt()?; + p.send_line(&format!("{executable} config get"))?; + p.expect(config_file.to_string_lossy().as_ref())?; + add_snippet_interactive( + &mut p, + &Snippet::new( + 5, + "test description 1".to_string(), + "rust".to_string(), + "rs".to_string(), + "tag1 tag2", + Utc::now(), + Utc::now(), + "code".to_string(), + ), + 5, + )?; + let mut cmd = Command::cargo_bin("the-way")?; + cmd.env("THE_WAY_CONFIG", &config_file) + .env("THE_WAY_GITHUB_TOKEN", token) + .arg("view") + .arg("5") + .assert() + .success(); + // delete Gist assert!(client.delete_gist(&gist.id).is_ok()); assert!(client.get_gist(&gist.id).is_err());