fix minor thing with string literal spans (and add a test)

This commit is contained in:
Niko Matsakis 2015-07-19 14:14:40 -04:00
parent 09f00f7a56
commit d5b2603bcb
2 changed files with 11 additions and 2 deletions

View File

@ -224,8 +224,8 @@ impl<'input> Tokenizer<'input> {
match self.take_until(terminate) {
Some(idx1) => {
self.bump(); // consume the '"'
let text = &self.text[idx0+1..idx1]; // do not include the `` in the str
Ok((idx0, StringLiteral(text), idx1))
let text = &self.text[idx0+1..idx1]; // do not include the "" in the str
Ok((idx0, StringLiteral(text), idx1+1))
}
None => {
Err(UnterminatedStringLiteral(idx0))

View File

@ -78,3 +78,12 @@ fn various_kinds_of_ids() {
(" ~", GreaterThan),
]);
}
#[test]
fn string_literals() {
test(r#"foo "bar\"\n" baz"#, vec![
(r#"~~~ "#, Id("foo")),
(r#" ~~~~~~~~~ "#, StringLiteral(r#"bar\"\n"#)),
(r#" ~~~"#, Id("baz")),
]);
}