Repository: GraphiteEditor/Graphite
File: editor/src/messages/tool/tool_messages/gradient_tool.rs (Rust)

Code before:
			.collect()
	}

	async fn get_gradient(editor: &mut EditorTestUtils) -> (Gradient, DAffine2) {
		let fills = get_fills(editor).await;
		assert_eq!(fills.len(), 1, "Expected 1 gradient fill, found {}", fills.len());

		let (fill, transform) = fills.first().unwrap();
		let gradient = fill.as_gradient().expect("Expected gradient fill type");

		(gradient.clone(), transform.clone())
	}

	async fn double_click_at(editor: &mut EditorTestUtils, position: DVec2) {
		editor
			.handle_message(InputPreprocessorMessage::DoubleClick {
				editor_mouse_state: EditorMouseState {
					editor_position: position,
					mouse_keys: MouseKeys::LEFT,
					scroll_delta: ScrollDelta::default(),
				},
				modifier_keys: ModifierKeys::empty(),
			})
			.await;
	}

	#[tokio::test]
	async fn ignore_artboard() {
		let mut editor = EditorTestUtils::create();
		editor.new_document().await;
		editor.drag_tool(ToolType::Artboard, 0., 0., 100., 100., ModifierKeys::empty()).await;
		editor.drag_tool(ToolType::Gradient, 2., 2., 4., 4., ModifierKeys::empty()).await;
		assert!(get_fills(&mut editor).await.is_empty());
	}

	#[tokio::test]
	async fn ignore_raster() {
		let mut editor = EditorTestUtils::create();
		editor.new_document().await;
		editor.create_raster_image(Image::new(100, 100, Color::WHITE), Some((0., 0.))).await;
		editor.drag_tool(ToolType::Gradient, 2., 2., 4., 4., ModifierKeys::empty()).await;
		assert!(get_fills(&mut editor).await.is_empty());
	}

	#[tokio::test]
	async fn simple_draw() {
		let mut editor = EditorTestUtils::create();
		editor.new_document().await;
		editor.drag_tool(ToolType::Rectangle, -5., -3., 100., 100., ModifierKeys::empty()).await;
		editor.select_primary_color(Color::GREEN).await;
		editor.select_secondary_color(Color::BLUE).await;

Review comment (suggestion):
This looks good, however why is this not part of the `EditorTestUtils` like all the other testing utilities? It doesn't seem to be specific to the gradient tool.

Code after:
			.collect()
	}

	async fn get_gradient(editor: &mut EditorTestUtils) -> (Gradient, DAffine2) {
		let fills = get_fills(editor).await;
		assert_eq!(fills.len(), 1, "Expected 1 gradient fill, found {}", fills.len());

		let (fill, transform) = fills.first().unwrap();
		let gradient = fill.as_gradient().expect("Expected gradient fill type");

		(gradient.clone(), transform.clone())
	}

	fn assert_stops_at_positions(actual_positions: &[f64], expected_positions: &[f64], tolerance: f64) {
		assert_eq!(
			actual_positions.len(),
			expected_positions.len(),
			"Expected {} stops, found {}",
			expected_positions.len(),
			actual_positions.len()
		);

		for (i, (actual, expected)) in actual_positions.iter().zip(expected_positions.iter()).enumerate() {
			assert!((actual - expected).abs() < tolerance, "Stop {}: Expected position near {}, got {}", i, expected, actual);
		}
	}

	#[tokio::test]
	async fn ignore_artboard() {
		let mut editor = EditorTestUtils::create();
		editor.new_document().await;
		editor.drag_tool(ToolType::Artboard, 0., 0., 100., 100., ModifierKeys::empty()).await;
		editor.drag_tool(ToolType::Gradient, 2., 2., 4., 4., ModifierKeys::empty()).await;
		assert!(get_fills(&mut editor).await.is_empty());
	}

	#[tokio::test]
	async fn ignore_raster() {
		let mut editor = EditorTestUtils::create();
		editor.new_document().await;
		editor.create_raster_image(Image::new(100, 100, Color::WHITE), Some((0., 0.))).await;
		editor.drag_tool(ToolType::Gradient, 2., 2., 4., 4., ModifierKeys::empty()).await;
		assert!(get_fills(&mut editor).await.is_empty());
	}

	#[tokio::test]
	async fn simple_draw() {
		let mut editor = EditorTestUtils::create();
		editor.new_document().await;
		editor.drag_tool(ToolType::Rectangle, -5., -3., 100., 100., ModifierKeys::empty()).await;
		editor.select_primary_color(Color::GREEN).await;