Skip to content

Commit

Permalink
Fix 'multiline' truncating last character of each line.
Browse files Browse the repository at this point in the history
  Fixes #987.
  • Loading branch information
KtorZ committed Aug 1, 2024
1 parent b8bb480 commit 91aa435
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## v1.1.0 - UNRELEASED

### Added


### Changed

- **aiken-project**: fix blueprint's apply truncating last character of outputs. See [#987](https://github.com/aiken-lang/aiken/issues/987). @KtorZ

### Removed


## v1.0.30-alpha - 2024-07-25

### Added
Expand Down
25 changes: 24 additions & 1 deletion crates/aiken-project/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub fn multiline(max_len: usize, s: String) -> Vec<String> {
let len = s.len();
loop {
let lo = i * max_len;
let hi = cmp::min(len - 1, lo + max_len - 1);
let hi = cmp::min(len, lo + max_len);

if lo >= len {
break;
Expand All @@ -179,3 +179,26 @@ pub fn multiline(max_len: usize, s: String) -> Vec<String> {
}
xs
}

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

#[test]
fn multiline_empty_string() {
assert_eq!(multiline(10, "".to_string()), Vec::<String>::new());
}

#[test]
fn multiline_single_line() {
assert_eq!(multiline(10, "foo".to_string()), vec!["foo".to_string()]);
}

#[test]
fn multiline_many_lines() {
assert_eq!(
multiline(3, "foobar".to_string()),
vec!["foo".to_string(), "bar".to_string()]
);
}
}

0 comments on commit 91aa435

Please sign in to comment.