mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
compiler: Add a test for mapping offset to/from line/column
... in SourceFile. Let's hope that this will finally make sure that this works properly!
This commit is contained in:
parent
31147fecd7
commit
cf1984f544
1 changed files with 50 additions and 0 deletions
|
@ -520,3 +520,53 @@ impl BuildDiagnostics {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_source_file_offset_line_column_mapping() {
|
||||
let content = r#"import { LineEdit, Button, Slider, HorizontalBox, VerticalBox } from "std-widgets.slint";
|
||||
|
||||
component MainWindow inherits Window {
|
||||
property <duration> total-time: slider.value * 1s;
|
||||
|
||||
callback tick(duration);
|
||||
VerticalBox {
|
||||
HorizontalBox {
|
||||
padding-left: 0;
|
||||
Text { text: "Elapsed Time:"; }
|
||||
Rectangle {
|
||||
Rectangle {
|
||||
height: 100%;
|
||||
background: lightblue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
"#.to_string();
|
||||
let sf = SourceFileInner::new(PathBuf::from("foo.slint"), content.clone());
|
||||
|
||||
let mut line = 1;
|
||||
let mut column = 1;
|
||||
for offset in 0..content.len() {
|
||||
let b = *content.as_bytes().get(offset).unwrap();
|
||||
|
||||
assert_eq!(sf.offset(line, column), offset);
|
||||
assert_eq!(sf.line_column(offset), (line, column));
|
||||
|
||||
if b == b'\n' {
|
||||
line += 1;
|
||||
column = 1;
|
||||
} else {
|
||||
column += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue