Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 13 additions & 11 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ impl<'src> Lexer<'src> {
self.token_end.offset += len_utf8;
self.token_end.column += len_utf8;

if c == '\n' {
self.next = self.chars.next();

if c == '\n' && self.next.is_some() {
self.token_end.column = 0;
self.token_end.line += 1;
}

self.next = self.chars.next();

Ok(())
}
None => Err(self.internal_error("Lexer advanced past end of text")),
Expand Down Expand Up @@ -974,29 +974,31 @@ mod tests {

let have_lexemes = have.iter().map(Token::lexeme).collect::<Vec<&str>>();

assert_eq!(have_kinds, want_kinds, "Token kind mismatch");
assert_eq!(have_lexemes, want_lexemes, "Token lexeme mismatch");
assert_eq!(have_kinds, want_kinds, "token kind mismatch");
assert_eq!(have_lexemes, want_lexemes, "token lexeme mismatch");

let mut roundtrip = String::new();

for lexeme in have_lexemes {
roundtrip.push_str(lexeme);
}

assert_eq!(roundtrip, text, "Roundtrip mismatch");
assert_eq!(roundtrip, text, "roundtrip mismatch");

let lines = text.lines().count();

let mut offset = 0;
let mut line = 0;
let mut column = 0;

for token in have {
assert_eq!(token.offset, offset);
assert_eq!(token.line, line);
assert_eq!(token.lexeme().len(), token.length);
assert_eq!(token.column, column);
assert_eq!(token.offset, offset, "offset mismatch");
assert_eq!(token.line, line, "line mismatch");
assert_eq!(token.lexeme().len(), token.length, "length mismatch");
assert_eq!(token.column, column, "column mismatch");

for c in token.lexeme().chars() {
if c == '\n' {
if c == '\n' && line + 1 < lines {
line += 1;
column = 0;
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl<'run, 'src> Parser<'run, 'src> {

self.accept(ByteOrderMark)?;

loop {
while !self.accepted(Eof)? {
let mut attributes = self.parse_attributes()?;
let mut take_attributes = || {
attributes
Expand All @@ -408,8 +408,6 @@ impl<'run, 'src> Parser<'run, 'src> {
eol_since_last_comment = false;
} else if self.accepted(Eol)? {
eol_since_last_comment = true;
} else if self.accepted(Eof)? {
break;
} else if self.next_is(Identifier) {
match Keyword::from_lexeme(next.lexeme()) {
Some(Keyword::Alias) if self.next_are(&[Identifier, Identifier, ColonEquals]) => {
Expand Down
18 changes: 3 additions & 15 deletions tests/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,10 @@ fn working_directory_is_correct() {

#[test]
fn command_not_found() {
let tmp = tempdir();

fs::write(tmp.path().join("justfile"), "").unwrap();

let output = Command::new(JUST)
Test::new()
.args(["--command", "asdfasdfasdfasdfadfsadsfadsf", "bar"])
.output()
.unwrap();

assert!(
str::from_utf8(&output.stderr)
.unwrap()
.starts_with("error: Failed to invoke `asdfasdfasdfasdfadfsadsfadsf` `bar`:"),
);

assert!(!output.status.success());
.stderr_regex("error: Failed to invoke `asdfasdfasdfasdfadfsadsfadsf` `bar`: .*")
.failure();
}

#[test]
Expand Down
20 changes: 20 additions & 0 deletions tests/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,23 @@ fn comment_after_unexport() {
)
.success();
}

#[test]
fn attribute_without_item() {
Test::new()
.justfile(
"
[confirm]
",
)
.stderr(
"
error: Expected '@', '[', comment, end of line, or identifier, but found end of file
——▶ justfile:1:11
1 │ [confirm]
│ ^
",
)
.failure();
}