mirror of
https://github.com/typst/typst
synced 2025-08-24 03:34:14 +08:00
test: also use TestWorld::lookup in text_for_range
This commit is contained in:
parent
80491a459c
commit
506b64e2cd
@ -8,7 +8,7 @@ use typst::diag::{SourceDiagnostic, Warned};
|
||||
use typst::html::HtmlDocument;
|
||||
use typst::layout::{Abs, Frame, FrameItem, PagedDocument, Transform};
|
||||
use typst::visualize::Color;
|
||||
use typst::{Document, World, WorldExt};
|
||||
use typst::{Document, WorldExt};
|
||||
use typst_pdf::PdfOptions;
|
||||
use typst_syntax::FileId;
|
||||
|
||||
@ -289,19 +289,11 @@ impl<'a> Runner<'a> {
|
||||
fn text_for_range(&self, file: FileId, range: &Option<Range<usize>>) -> String {
|
||||
let Some(range) = range else { return "No text".into() };
|
||||
if range.is_empty() {
|
||||
"(empty)".into()
|
||||
} else if file == self.test.source.id() {
|
||||
format!(
|
||||
"`{}`",
|
||||
self.test.source.text()[range.clone()]
|
||||
.replace('\n', "\\n")
|
||||
.replace('\r', "\\r")
|
||||
)
|
||||
} else {
|
||||
let bytes = self.world.file(file).unwrap();
|
||||
let text = std::str::from_utf8(&bytes).unwrap();
|
||||
format!("`{}`", text[range.clone()].replace('\n', "\\n").replace('\r', "\\r"))
|
||||
return "(empty)".into();
|
||||
}
|
||||
|
||||
let lines = self.world.lookup(file);
|
||||
lines.text()[range.clone()].replace('\n', "\\n").replace('\r', "\\r")
|
||||
}
|
||||
|
||||
/// Display a byte range as a line:column range.
|
||||
|
Loading…
x
Reference in New Issue
Block a user