diff options
author | Jovansonlee Cesar <ivanceras@gmail.com> | 2021-08-17 02:04:31 +0800 |
---|---|---|
committer | Jovansonlee Cesar <ivanceras@gmail.com> | 2021-08-17 02:04:31 +0800 |
commit | 5a2eae141b9c7139ff59fe8e7823cb531cc7d363 (patch) | |
tree | 93239a316b34f9e8acc2ff3a0111beba347d9c92 | |
parent | c9dcea32e6510707ce9228d3bca94d0238f01ac1 (diff) |
Fix issue#38
-rw-r--r-- | svgbob/src/buffer/cell_buffer.rs | 34 | ||||
-rw-r--r-- | svgbob/tests/issue38.rs | 41 |
2 files changed, 30 insertions, 45 deletions
diff --git a/svgbob/src/buffer/cell_buffer.rs b/svgbob/src/buffer/cell_buffer.rs index de09bc2..338b461 100644 --- a/svgbob/src/buffer/cell_buffer.rs +++ b/svgbob/src/buffer/cell_buffer.rs @@ -538,8 +538,6 @@ impl CellBuffer { if char_locs.is_empty() { no_escaped_text = raw.to_string(); } else { - println!("raw: {}", raw); - dbg!(&input_chars); for (start, end) in char_locs.iter() { let escaped = input_chars[*start + 1..*end].iter().fold( String::new(), @@ -563,8 +561,14 @@ impl CellBuffer { no_escaped_text += &" ".repeat(escaped_unicode_width + 2); index = end + 1; } - // the rest of the text - no_escaped_text.push_str(&raw[index..raw.len()]); + // include the rest of the text + no_escaped_text += &input_chars[index..].iter().fold( + String::new(), + |mut acc, c| { + acc.push(*c); + acc + }, + ); } (escaped_text, no_escaped_text) } @@ -668,6 +672,28 @@ mod tests { } #[test] + fn test_issue38_escaped_german_umlauts() { + let raw = r#"This is some german character "ÖÄÜ" and was escaped"#; + let ex2 = r#"This is some german character and was escaped"#; + let (escaped, unescaped) = CellBuffer::escape_line(0, raw); + println!("escaped: {:#?}", escaped); + println!("unescaped: {}", unescaped); + assert_eq!(vec![(Cell::new(30, 0), "ÖÄÜ".to_string())], escaped); + assert_eq!(ex2, unescaped); + } + + #[test] + fn test_issue38_escape_cjk() { + let raw = r#"This is some CJK "一" and was escaped"#; + let ex2 = r#"This is some CJK and was escaped"#; + let (escaped, unescaped) = CellBuffer::escape_line(0, raw); + println!("escaped: {:#?}", escaped); + println!("unescaped: {}", unescaped); + assert_eq!(vec![(Cell::new(17, 0), r#"一"#.to_string())], escaped); + assert_eq!(ex2, unescaped); + } + + #[test] fn test_simple_adjacents() { let art = r#" .. ._. diff --git a/svgbob/tests/issue38.rs b/svgbob/tests/issue38.rs deleted file mode 100644 index 936e552..0000000 --- a/svgbob/tests/issue38.rs +++ /dev/null @@ -1,41 +0,0 @@ -#[test] -fn cjk_errors() { - let input = r#" - +----+ - | 一 | - +----+ - - +--------+ - |"""一"""| - +--------+ - "#; - - let out = svgbob::to_svg_string_compressed(input); - println!("\n{}\n", out); - dbg!(&out); - - panic!(); -} - -#[test] -fn german_umlauts() { - let input = r#" -+----------+ -| ÖÄÜ | -+----------+ - -+----------+ -| "ÖÄÜ" | -+----------+ - -+----------+ -| "ÖÄÜ" | -+----------+ - "#; - - let out = svgbob::to_svg_string_compressed(input); - println!("\n{}\n", out); - dbg!(&out); - - panic!(); -} |