| 1 | extern crate transformation_pipeline; |
| 2 | |
| 3 | use transformation_pipeline::{TransformationStage, StageActions, StageResult, TransformationPipeline}; |
| 4 | |
| 5 | struct FirstTransformation {} |
| 6 | |
| 7 | impl TransformationStage<String> for FirstTransformation { |
| 8 | |
| 9 | fn run(&self, _previous: String) -> StageResult<String> { |
| 10 | Ok(StageActions::Next("a".to_owned())) |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | struct SecondTransformation {} |
| 15 | |
| 16 | impl TransformationStage<String> for SecondTransformation { |
| 17 | |
| 18 | fn run(&self, _previous: String) -> StageResult<String> { |
| 19 | Ok(StageActions::Skip) |
| 20 | } |
| 21 | |
| 22 | } |
| 23 | |
| 24 | struct ThirdTransformation {} |
| 25 | |
| 26 | impl TransformationStage<String> for ThirdTransformation { |
| 27 | |
| 28 | fn run(&self, previous: String) -> StageResult<String> { |
| 29 | assert_eq!(previous, "a".to_owned()); |
| 30 | Ok(StageActions::Next("b".to_owned())) |
| 31 | } |
| 32 | |
| 33 | } |
| 34 | |
| 35 | #[test] |
| 36 | fn run_pipeline() { |
| 37 | let pipeline: TransformationPipeline<String> = TransformationPipeline::new(vec![ |
| 38 | Box::new(FirstTransformation {}), |
| 39 | Box::new(SecondTransformation {}), |
| 40 | Box::new(ThirdTransformation {}), |
| 41 | ]); |
| 42 | |
| 43 | assert_eq!(pipeline.run("z".to_owned()).unwrap(), "b".to_owned()); |
| 44 | } |