GraphiteEditor / GraphiteEditor/Graphite
Add tests for polygon shape, star shape, and grid snapping tools
- 主要语言
- Rust
- 星标
- 27.2k
- 派生
- 1.3k
- 平均合并
- 20 小时 5 分钟
- 30 天内合并 PR
- 57
描述
## Summary
This issue tracks adding `#[cfg(test)]` test coverage to three currently untested files in the tool and snapping systems. These are good starting points for GSoC test coverage work, as they follow the same pattern already established in `ellipse_shape.rs` and `line_shape.rs`.
---
## Files to Test
### 1. `editor/src/messages/tool/common_functionality/shapes/polygon_shape.rs` (~193 LOC)
**What to test:**
- `draw_polygon_simple` — drag with `ToolType::Shape` (polygon mode), assert vertex count and radius
- `draw_polygon_square_ratio` — drag with `ModifierKeys::SHIFT` (lock ratio), assert equal dimensions
- `draw_polygon_from_center` — drag with `ModifierKeys::ALT`, assert center origin
- `draw_polygon_cancel_rmb` — use `drag_tool_cancel_rmb`, assert no layer created
- `polygon_decrease_sides` — assert `decrease_or_increase_sides(true, ...)` clamps to minimum 3
- `polygon_increase_sides` — assert side count increments correctly
**Reference pattern:** `ellipse_shape.rs` (same file, same module structure)
---
### 2. `editor/src/messages/tool/common_functionality/shapes/star_shape.rs` (~172 LOC)
**What to test:**
- `draw_star_simple` — drag to create star, assert outer/inner radius values
- `draw_star_square_ratio` — with `ModifierKeys::SHIFT`
- `draw_star_from_center` — with `ModifierKeys::ALT`
- `draw_star_cancel_rmb` — assert no layer created on RMB cancel
- Verify inner radius is set to `outer_radius / 2.0` by default (`Star::update_shape` line 161)
**Reference pattern:** Same as `ellipse_shape.rs`; use `NodeGraphLayer::upstream_node_id_from_protonode` with `star::IDENTIFIER`
---
### 3. `editor/src/messages/tool/common_functionality/snapping/grid_snapper.rs` (~181 LOC)
**What to test:**
- `rectangular_grid_snap_on_line` — point exactly on a grid line snaps with distance ≈ 0
- `rectangular_grid_snap_within_tolerance` — point within tolerance snaps to nearest line
- `rectangular_grid_no_snap_outside_tolerance` — point beyond tolerance produces no snap result
- `isometric_grid_snap_vertical` — snap to vertical lines in isometric grid
- `isometric_grid_angle_lines` — snap to angled lines (angle_a / angle_b)
- `constrained_snap_to_grid_intersection` — constrained snap hits grid line correctly
## Test Infrastructure
All tests should use the existing `EditorTestUtils` helper:
```rust
#[cfg(test)]
mod test_polygon {
use crate::test_utils::test_prelude::*;
// ...
#[tokio::test]
async fn draw_polygon_simple() {
let mut editor = EditorTestUtils::create();
editor.new_document().await;
editor.drag_tool(ToolType::Shape, 10., 10., 50., 50., ModifierKeys::empty()).await;
// assert layer count, vertex count, radius etc.
}
}
贡献指南
这个仓库没有索引到贡献指南
调研方向
先从 ellipse_shape.rs 和 line_shape.rs 中现有的测试开始,然后检查 polygon_shape.rs、star_shape.rs 和 grid_snapper.rs。使用文档中说明的 EditorTestUtils 模式并运行相关的 Rust 测试;完成的标准是,所列出的形状、取消、半径、边数和网格捕捉用例中的断言都通过。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- rust
- 领域
- testing
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 72/100