Skip to content

Commit

Permalink
Merged origin/master into ensure-project-settings-button-goes-to-corr…
Browse files Browse the repository at this point in the history
…ect-project
  • Loading branch information
Caleb-T-Owens committed Mar 29, 2024
2 parents fcfd212 + fe36d83 commit 4c24cc1
Show file tree
Hide file tree
Showing 76 changed files with 4,595 additions and 4,497 deletions.
2 changes: 2 additions & 0 deletions .github/actions/check-crate/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ runs:
- run: cargo test --locked -p ${{ inputs.crate }} --all-targets $(cat /tmp/features)
if: inputs.action == 'test'
env:
GITBUTLER_TESTS_NO_CLEANUP: "1"
shell: bash

- run: cargo clippy -p ${{ inputs.crate }} --all-targets $(cat /tmp/features) -- -D warnings
Expand Down
6 changes: 6 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ You'll have to re-run this occasionally when our deps change.

### Run the app

First, run cargo build such that supplementary bins such as `gitbutler-git-askpass` and `gitbutler-git-setsid` are created:

```bash
$ cargo build
```

Now you should be able to run the app in development mode:

```bash
Expand Down
2 changes: 1 addition & 1 deletion gitbutler-app/src/analytics/posthog/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod tests {
}

#[tokio::test]
async fn test_retry() {
async fn retry() {
let inner_client = MockClient::new();
let retry_client = super::Client::new(inner_client.clone());

Expand Down
6 changes: 3 additions & 3 deletions gitbutler-app/src/dedup.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub fn dedup(existing: &[&str], new: &str) -> String {
pub(crate) fn dedup(existing: &[&str], new: &str) -> String {
dedup_fmt(existing, new, " ")
}

/// Makes sure that _new_ is not in _existing_ by adding a number to it.
/// the number is increased until the name is unique.
pub fn dedup_fmt(existing: &[&str], new: &str, separator: &str) -> String {
pub(crate) fn dedup_fmt(existing: &[&str], new: &str, separator: &str) -> String {
existing
.iter()
.filter_map(|x| {
Expand All @@ -26,7 +26,7 @@ pub fn dedup_fmt(existing: &[&str], new: &str, separator: &str) -> String {
}

#[test]
fn test_dedup() {
fn tests() {
for (existing, new, expected) in [
(vec!["bar", "baz"], "foo", "foo"),
(vec!["foo", "bar", "baz"], "foo", "foo 1"),
Expand Down
267 changes: 0 additions & 267 deletions gitbutler-app/src/deltas/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,270 +83,3 @@ impl Display for Document {
write!(f, "{}", self.doc.iter().collect::<String>())
}
}

#[cfg(test)]
mod tests {
use self::{delta::Delta, operations::Operation};

use super::*;

#[test]
fn test_new() {
let document = Document::new(
Some(&reader::Content::UTF8("hello world".to_string())),
vec![],
);
assert!(document.is_ok());
let document = document.unwrap();
assert_eq!(document.to_string(), "hello world");
assert_eq!(document.get_deltas().len(), 0);
}

#[test]
fn test_update() {
let document = Document::new(
Some(&reader::Content::UTF8("hello world".to_string())),
vec![],
);
assert!(document.is_ok());
let mut document = document.unwrap();
document
.update(Some(&reader::Content::UTF8("hello world!".to_string())))
.unwrap();
assert_eq!(document.to_string(), "hello world!");
assert_eq!(document.get_deltas().len(), 1);
assert_eq!(document.get_deltas()[0].operations.len(), 1);
assert_eq!(
document.get_deltas()[0].operations[0],
Operation::Insert((11, "!".to_string()))
);
}

#[test]
fn test_empty() {
let document = Document::new(None, vec![]);
assert!(document.is_ok());
let mut document = document.unwrap();
document
.update(Some(&reader::Content::UTF8("hello world!".to_string())))
.unwrap();
assert_eq!(document.to_string(), "hello world!");
assert_eq!(document.get_deltas().len(), 1);
assert_eq!(document.get_deltas()[0].operations.len(), 1);
assert_eq!(
document.get_deltas()[0].operations[0],
Operation::Insert((0, "hello world!".to_string()))
);
}

#[test]
fn test_from_deltas() {
let document = Document::new(
None,
vec![
Delta {
timestamp_ms: 0,
operations: vec![Operation::Insert((0, "hello".to_string()))],
},
Delta {
timestamp_ms: 1,
operations: vec![Operation::Insert((5, " world".to_string()))],
},
Delta {
timestamp_ms: 2,
operations: vec![
Operation::Delete((3, 7)),
Operation::Insert((4, "!".to_string())),
],
},
],
);
assert!(document.is_ok());
let document = document.unwrap();
assert_eq!(document.to_string(), "held!");
}

#[test]
fn test_complex_line() {
let document = Document::new(None, vec![]);
assert!(document.is_ok());
let mut document = document.unwrap();

document
.update(Some(&reader::Content::UTF8("hello".to_string())))
.unwrap();
assert_eq!(document.to_string(), "hello");
assert_eq!(document.get_deltas().len(), 1);
assert_eq!(document.get_deltas()[0].operations.len(), 1);
assert_eq!(
document.get_deltas()[0].operations[0],
Operation::Insert((0, "hello".to_string()))
);

document
.update(Some(&reader::Content::UTF8("hello world".to_string())))
.unwrap();
assert_eq!(document.to_string(), "hello world");
assert_eq!(document.get_deltas().len(), 2);
assert_eq!(document.get_deltas()[1].operations.len(), 1);
assert_eq!(
document.get_deltas()[1].operations[0],
Operation::Insert((5, " world".to_string()))
);

document
.update(Some(&reader::Content::UTF8("held!".to_string())))
.unwrap();
assert_eq!(document.to_string(), "held!");
assert_eq!(document.get_deltas().len(), 3);
assert_eq!(document.get_deltas()[2].operations.len(), 2);
assert_eq!(
document.get_deltas()[2].operations[0],
Operation::Delete((3, 7))
);
assert_eq!(
document.get_deltas()[2].operations[1],
Operation::Insert((4, "!".to_string())),
);
}

#[test]
fn test_multiline_add() {
let document = Document::new(None, vec![]);
assert!(document.is_ok());
let mut document = document.unwrap();

document
.update(Some(&reader::Content::UTF8("first".to_string())))
.unwrap();
assert_eq!(document.to_string(), "first");
assert_eq!(document.get_deltas().len(), 1);
assert_eq!(document.get_deltas()[0].operations.len(), 1);
assert_eq!(
document.get_deltas()[0].operations[0],
Operation::Insert((0, "first".to_string()))
);

document
.update(Some(&reader::Content::UTF8("first\ntwo".to_string())))
.unwrap();
assert_eq!(document.to_string(), "first\ntwo");
assert_eq!(document.get_deltas().len(), 2);
assert_eq!(document.get_deltas()[1].operations.len(), 1);
assert_eq!(
document.get_deltas()[1].operations[0],
Operation::Insert((5, "\ntwo".to_string()))
);

document
.update(Some(&reader::Content::UTF8(
"first line\nline two".to_string(),
)))
.unwrap();
assert_eq!(document.to_string(), "first line\nline two");
assert_eq!(document.get_deltas().len(), 3);
assert_eq!(document.get_deltas()[2].operations.len(), 2);
assert_eq!(
document.get_deltas()[2].operations[0],
Operation::Insert((5, " line".to_string()))
);
assert_eq!(
document.get_deltas()[2].operations[1],
Operation::Insert((11, "line ".to_string()))
);
}

#[test]
fn test_multiline_remove() {
let document = Document::new(None, vec![]);
assert!(document.is_ok());
let mut document = document.unwrap();

document
.update(Some(&reader::Content::UTF8(
"first line\nline two".to_string(),
)))
.unwrap();
assert_eq!(document.to_string(), "first line\nline two");
assert_eq!(document.get_deltas().len(), 1);
assert_eq!(document.get_deltas()[0].operations.len(), 1);
assert_eq!(
document.get_deltas()[0].operations[0],
Operation::Insert((0, "first line\nline two".to_string()))
);

document
.update(Some(&reader::Content::UTF8("first\ntwo".to_string())))
.unwrap();
assert_eq!(document.to_string(), "first\ntwo");
assert_eq!(document.get_deltas().len(), 2);
assert_eq!(document.get_deltas()[1].operations.len(), 2);
assert_eq!(
document.get_deltas()[1].operations[0],
Operation::Delete((5, 5))
);
assert_eq!(
document.get_deltas()[1].operations[1],
Operation::Delete((6, 5))
);

document
.update(Some(&reader::Content::UTF8("first".to_string())))
.unwrap();
assert_eq!(document.to_string(), "first");
assert_eq!(document.get_deltas().len(), 3);
assert_eq!(document.get_deltas()[2].operations.len(), 1);
assert_eq!(
document.get_deltas()[2].operations[0],
Operation::Delete((5, 4))
);

document.update(None).unwrap();
assert_eq!(document.to_string(), "");
assert_eq!(document.get_deltas().len(), 4);
assert_eq!(document.get_deltas()[3].operations.len(), 1);
assert_eq!(
document.get_deltas()[3].operations[0],
Operation::Delete((0, 5))
);
}

#[test]
fn test_binary_to_text() {
let latest = reader::Content::Binary;
let current = reader::Content::UTF8("test".to_string());
let mut document = Document::new(Some(&latest), vec![]).unwrap();
let new_deltas = document.update(Some(&current)).unwrap();
assert!(new_deltas.is_some());
assert_eq!(document.to_string(), "test");
}

#[test]
fn test_binary_to_binary() {
let latest = reader::Content::Binary;
let current = reader::Content::Binary;
let mut document = Document::new(Some(&latest), vec![]).unwrap();
let new_deltas = document.update(Some(&current)).unwrap();
assert!(new_deltas.is_some());
assert_eq!(document.to_string(), "");
}

#[test]
fn test_text_to_binary() {
let latest = reader::Content::UTF8("text".to_string());
let current = reader::Content::Binary;
let mut document = Document::new(Some(&latest), vec![]).unwrap();
let new_deltas = document.update(Some(&current)).unwrap();
assert!(new_deltas.is_some());
assert_eq!(document.to_string(), "");
}

#[test]
fn test_unicode() {
let latest = reader::Content::UTF8("\u{1f31a}".to_string());
let current = reader::Content::UTF8("\u{1f31d}".to_string());
let mut document = Document::new(Some(&latest), vec![]).unwrap();
document.update(Some(&current)).unwrap();
assert_eq!(document.to_string(), "\u{1f31d}");
}
}
59 changes: 0 additions & 59 deletions gitbutler-app/src/deltas/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,62 +114,3 @@ pub fn get_delta_operations(initial_text: &str, final_text: &str) -> Vec<Operati

merge_touching(&deltas)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_get_delta_operations_insert_end() {
let initial_text = "hello";
let final_text = "hello world!";
let operations = get_delta_operations(initial_text, final_text);
assert_eq!(operations.len(), 1);
assert_eq!(operations[0], Operation::Insert((5, " world!".to_string())));
}

#[test]
fn test_get_delta_operations_insert_middle() {
let initial_text = "helloworld";
let final_text = "hello, world";
let operations = get_delta_operations(initial_text, final_text);
assert_eq!(operations.len(), 1);
assert_eq!(operations[0], Operation::Insert((5, ", ".to_string())));
}

#[test]
fn test_get_delta_operations_insert_begin() {
let initial_text = "world";
let final_text = "hello world";
let operations = get_delta_operations(initial_text, final_text);
assert_eq!(operations.len(), 1);
assert_eq!(operations[0], Operation::Insert((0, "hello ".to_string())));
}

#[test]
fn test_get_delta_operations_delete_end() {
let initial_text = "hello world!";
let final_text = "hello";
let operations = get_delta_operations(initial_text, final_text);
assert_eq!(operations.len(), 1);
assert_eq!(operations[0], Operation::Delete((5, 7)));
}

#[test]
fn test_get_delta_operations_delete_middle() {
let initial_text = "hello, world";
let final_text = "helloworld";
let operations = get_delta_operations(initial_text, final_text);
assert_eq!(operations.len(), 1);
assert_eq!(operations[0], Operation::Delete((5, 2)));
}

#[test]
fn test_get_delta_operations_delete_begin() {
let initial_text = "hello world";
let final_text = "world";
let operations = get_delta_operations(initial_text, final_text);
assert_eq!(operations.len(), 1);
assert_eq!(operations[0], Operation::Delete((0, 6)));
}
}
2 changes: 1 addition & 1 deletion gitbutler-app/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub mod gb {
use super::*;

#[test]
fn test_error_context() {
fn error_context() {
fn low_level_io() -> std::result::Result<(), std::io::Error> {
Err(std::io::Error::new(std::io::ErrorKind::Other, "oh no!"))
}
Expand Down
Loading

0 comments on commit 4c24cc1

Please sign in to comment.