// All the input starting at cur_start fits on the current line
if graphemes.len() - cur_start <= cur_max_chars {
for (i, grapheme) in graphemes[cur_start..].iter().enumerate() {
- if is_line_feed(grapheme) {
+ if is_new_line(grapheme) {
// take care of blank lines
result = trim_end_but_line_feed(fmt.trim_end, result);
result.push_str("\n");
}
fn not_whitespace_except_line_feed(g: &str) -> bool {
- is_line_feed(g) || !is_whitespace(g)
+ is_new_line(g) || !is_whitespace(g)
}
/// Break the input string at a boundary character around the offset `max_chars`. A boundary
// line. If there is one, then text after it could be rewritten in a way that the available
// space is fully used.
for (i, grapheme) in input[0..=index].iter().enumerate() {
- if is_line_feed(grapheme) {
+ if is_new_line(grapheme) {
if i <= index_minus_ws {
let mut line = &input[0..i].concat()[..];
if trim_end {
let mut index_plus_ws = index;
for (i, grapheme) in input[index + 1..].iter().enumerate() {
- if !trim_end && is_line_feed(grapheme) {
+ if !trim_end && is_new_line(grapheme) {
return SnippetState::EndWithLineFeed(
input[0..=index + 1 + i].concat(),
index + 2 + i,
}
}
-fn is_line_feed(grapheme: &str) -> bool {
- grapheme.as_bytes()[0] == b'\n'
+fn is_new_line(grapheme: &str) -> bool {
+ let bytes = grapheme.as_bytes();
+ bytes.starts_with(b"\n") || bytes.starts_with(b"\r\n")
}
fn is_whitespace(grapheme: &str) -> bool {
--- /dev/null
+// rustfmt-format_strings: true
+// rustfmt-newline_style: Windows
+
+#[test]
+fn compile_empty_program() {
+ let result = get_result();
+ let expected = "; ModuleID = \'foo\'
+
+; Function Attrs: nounwind
+declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) #0
+
+declare i32 @write(i32, i8*, i32)
+
+declare i32 @putchar(i32)
+
+declare i32 @getchar()
+
+define i32 @main() {
+entry:
+ ret i32 0
+}
+
+attributes #0 = { nounwind }
+";
+ assert_eq!(result, CString::new(expected).unwrap());
+}