Skip to content

Commit 19a277f

Browse files
authored
Merge pull request #1987 from Urgau/note_until_new_line
Take everything until new-line as the summary in the note command
2 parents 8909a42 + f1184b9 commit 19a277f

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

parser/src/command/note.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl NoteCommand {
3434
false
3535
};
3636

37-
let title = toks.take_line_until_punc()?.trim();
37+
let title = toks.take_line()?.trim();
3838

3939
// For backwards compatibility we also trim " at the start and end
4040
let title = title.trim_matches('"');

parser/src/token.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ impl<'a> Tokenizer<'a> {
169169
self.cur_pos()
170170
}
171171

172-
pub fn take_line_until_punc(&mut self) -> Result<&'a str, Error<'a>> {
172+
pub fn take_line(&mut self) -> Result<&'a str, Error<'a>> {
173173
let start = self.cur_pos();
174-
while self.cur_punct().is_none() && !self.at_end() {
174+
while !matches!(self.cur_punct(), Some(Token::EndOfLine)) && !self.at_end() {
175175
self.advance();
176176
}
177177
Ok(self.str_from(start))
@@ -359,22 +359,30 @@ fn tokenize_raw_string_prohibit_1() {
359359
}
360360

361361
#[test]
362-
fn take_line_until_punc() {
362+
fn tokennize_take_line() {
363363
assert_eq!(
364-
Tokenizer::new("this is a text. this another one.").take_line_until_punc(),
365-
Ok("this is a text")
364+
Tokenizer::new("this is a text. this another one.").take_line(),
365+
Ok("this is a text. this another one.")
366366
);
367367
}
368368

369369
#[test]
370-
fn take_line_until_punc_2() {
370+
fn tokennize_take_line_2() {
371371
assert_eq!(
372-
Tokenizer::new("punc is \nnewline").take_line_until_punc(),
372+
Tokenizer::new("punc is \nnewline").take_line(),
373373
Ok("punc is ")
374374
);
375375
}
376376

377377
#[test]
378-
fn take_line_until_punc_3() {
379-
assert_eq!(Tokenizer::new("").take_line_until_punc(), Ok(""));
378+
fn tokennize_take_line_3() {
379+
assert_eq!(Tokenizer::new("").take_line(), Ok(""));
380+
}
381+
382+
#[test]
383+
fn tokennize_take_line_4() {
384+
assert_eq!(
385+
Tokenizer::new("To be used in 1.84. Another string.").take_line(),
386+
Ok("To be used in 1.84. Another string.")
387+
);
380388
}

0 commit comments

Comments
 (0)