| 1 | use insta::assert_snapshot; |
| 2 | use std::{error::Error, path::PathBuf}; |
| 3 | |
| 4 | #[rstest::rstest] |
| 5 | #[case("simple")] |
| 6 | #[case("no_error_lut")] |
| 7 | #[case("skip_callback")] |
| 8 | #[case("skip_callback_failure")] |
| 9 | #[case("error_callback0")] |
| 10 | #[case("error_callback1")] |
| 11 | #[case("error_callback_failure")] |
| 12 | pub fn test_codegen(#[case] fixture: &str) -> Result<(), Box<dyn Error>> { |
| 13 | let mut fixture_dir = PathBuf::new(); |
| 14 | fixture_dir.push(env!("CARGO_MANIFEST_DIR")); |
| 15 | fixture_dir.push("tests"); |
| 16 | fixture_dir.push("data"); |
| 17 | fixture_dir.push("codegen"); |
| 18 | fixture_dir.push(fixture); |
| 19 | |
| 20 | let input = fixture_dir.join("input.rs"); |
| 21 | let input = std::fs::read_to_string(input)?; |
| 22 | |
| 23 | let generated = logos_codegen::generate(input.parse()?).to_string(); |
| 24 | |
| 25 | if cfg!(rust_1_82) { |
| 26 | assert_snapshot!(format!("{fixture}-1_82"), generated); |
| 27 | } else { |
| 28 | assert_snapshot!(format!("{fixture}-pre_1_82"), generated); |
| 29 | } |
| 30 | |
| 31 | Ok(()) |
| 32 | } |