plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
480466e
— Peter John
2026-11-10T23:12:53+05:30
std_bounds_test: Grid get and set off the grid crash with the cell and the size
compiler/cli/tests/cli/std_bounds_test.rs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#![allow(non_snake_case)]
|
|
2
|
-
//! std's checked indexing: `Slice.at`, `Deque.at`, `Str.byteAt`
|
|
2
|
+
//! std's checked indexing: `Slice.at`, `Deque.at`, `Str.byteAt`, `Str.get` and `Grid.get`/`set`
|
|
3
|
-
//! stop the program with the index and the length, instead of reading another slot.
|
|
3
|
+
//! out of range stop the program with the index and the length, instead of reading another slot.
|
|
4
4
|
use std::process::Command;
|
|
5
5
|
|
|
6
6
|
fn plumBin() -> std::path::PathBuf {
|
|
@@ -18,7 +18,7 @@ fn run(name: &str, body: &str) -> (bool, String) {
|
|
|
18
18
|
let dir = crate::common::Scratch::new(&format!("bounds_{name}"));
|
|
19
19
|
let src = dir.join(format!("{name}.plum"));
|
|
20
20
|
let text = format!(
|
|
21
|
-
"import std/Int\nimport std/Str\nimport std/Io\nimport std/Option\nimport std/Slice\nimport std/collections/Deque\n\nfun main(io: Io) =\n{body}"
|
|
21
|
+
"import std/Int\nimport std/Str\nimport std/Io\nimport std/Option\nimport std/Slice\nimport std/collections/Deque\nimport std/collections/Grid\n\nfun main(io: Io) =\n{body}"
|
|
22
22
|
);
|
|
23
23
|
std::fs::write(&src, text).unwrap();
|
|
24
24
|
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).ancestors().nth(2).unwrap();
|
|
@@ -85,3 +85,18 @@ fn in_range_reads_still_work() {
|
|
|
85
85
|
);
|
|
86
86
|
assert!(ok, "stderr: {stderr}");
|
|
87
87
|
}
|
|
88
|
+
|
|
89
|
+
/// `Grid.get`/`set` off the grid crash with the cell and the size, a column past the row
|
|
90
|
+
/// included (its flat index is still inside the array: it would read the next row).
|
|
91
|
+
#[test]
|
|
92
|
+
fn grid_get_and_set_off_the_grid_crash() {
|
|
93
|
+
expectCrash(
|
|
94
|
+
"grid_get_past_row",
|
|
95
|
+
" g := Grid.filled(4, 3, 0)\n io.printLn(\"{g.get(4, 0)}\")\n",
|
|
96
|
+
"Grid.get: cell (4, 0) is off the 4 x 3 grid",
|
|
97
|
+
);
|
|
98
|
+
expectCrash("grid_get_negative", " g := Grid.filled(4, 3, 0)\n io.printLn(\"{g.get(0, -1)}\")\n", "Grid.get: cell (0, -1) is off the 4 x 3 grid");
|
|
99
|
+
expectCrash("grid_set_below", " g := Grid.filled(4, 3, 0)\n g.set(1, 3, 7)\n", "Grid.set: cell (1, 3) is off the 4 x 3 grid");
|
|
100
|
+
let (ok, stderr) = run("grid_fine", " g := Grid.filled(4, 3, 0)\n g.set(3, 2, 7)\n io.printLn(\"{g.get(3, 2)}\")\n");
|
|
101
|
+
assert!(ok, "stderr: {stderr}");
|
|
102
|
+
}
|