diff --git a/src/protocol/input_source2.rs b/src/protocol/input_source2.rs index 025b86ddbfb0a0f77f8fd9f3dffe5a5cfad59218..54888d0e7e255ce861097b47abbf4503a7c3ae2e 100644 --- a/src/protocol/input_source2.rs +++ b/src/protocol/input_source2.rs @@ -28,7 +28,7 @@ pub struct InputSource2 { line: u32, offset: usize, // State tracking - had_error: Option, + pub(crate) had_error: Option, // The offset_lookup is built on-demand upon attempting to report an error. // As the compiler is currently not multithreaded, we simply put it in a // RefCell to allow interior mutability. @@ -47,6 +47,12 @@ impl InputSource2 { } } + #[cfg(test)] + pub fn new_test(input: &str) -> Self { + let bytes = Vec::from(input.as_bytes()); + return Self::new(String::from("test"), bytes) + } + #[inline] pub fn pos(&self) -> InputPosition2 { InputPosition2{ line: self.line, offset: self.offset as u32 } @@ -120,7 +126,7 @@ impl InputSource2 { // Build the line number (!) to offset lookup, so offset by 1. We // assume the entire source file is scanned (most common case) for // preallocation. - let lookup = self.offset_lookup.borrow_mut(); + let mut lookup = self.offset_lookup.borrow_mut(); lookup.reserve(self.line as usize + 2); lookup.push(0); // line 0: never used lookup.push(0); // first line: first character