Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions rivet-core/src/bazel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,20 @@
text: &source[start..pos],
});
}
b'\r' => {
pos += 1;
if pos < bytes.len() && bytes[pos] == b'\n' {
pos += 1;
}
// keep eating newlines
while pos < bytes.len() && (bytes[pos] == b'\n' || bytes[pos] == b'\r') {
pos += 1;
}
tokens.push(Token {
kind: SyntaxKind::Newline,
text: &source[start..pos],
});
}

Check warning on line 151 in rivet-core/src/bazel.rs

View workflow job for this annotation

GitHub Actions / Mutation Testing

Missed mutant

delete match arm b'\r' in lex
// Whitespace (no newlines)
b' ' | b'\t' => {
while pos < bytes.len() && (bytes[pos] == b' ' || bytes[pos] == b'\t') {
Expand Down Expand Up @@ -1153,4 +1153,40 @@
// The module call should still be extracted.
assert_eq!(module.name.as_deref(), Some("test"));
}

// rivet: verifies REQ-028
#[test]
fn lex_carriage_return_newlines() {
// Test \r\n (Windows) line endings produce Newline tokens
let src = "module(\r\n name = \"test\"\r\n)\r\n";
let tokens = lex(src);
let newline_count = tokens
.iter()
.filter(|t| t.kind == SyntaxKind::Newline)
.count();
assert!(
newline_count >= 2,
"expected at least 2 newline tokens from \\r\\n, got {newline_count}"
);
}

// rivet: verifies REQ-028
#[test]
fn lex_dot_token() {
// Test that dot (.) is lexed as its own token (used in method calls)
let src = "foo.bar";
let tokens = lex(src);
let dot_tokens: Vec<_> = tokens
.iter()
.filter(|t| t.kind == SyntaxKind::Dot)
.collect();
assert_eq!(
dot_tokens.len(),
1,
"expected exactly 1 Dot token, got {}: {:?}",
dot_tokens.len(),
tokens.iter().map(|t| (t.kind, t.text)).collect::<Vec<_>>()
);
assert_eq!(dot_tokens[0].text, ".");
}
}
Loading