From daa55135bc24e2fa1ff06fb4695c26586371ecdc Mon Sep 17 00:00:00 2001 From: damc Date: Thu, 21 Jul 2022 13:34:23 +0200 Subject: [PATCH] ppTests MESSY Rearrange tests alphabetically. - This should be the last messy commit. - Renamed and re-arranged tests are now easier to navigate. - Six test failing for different reasons. --- sv-parser-pp/src/preprocess.rs | 526 ++++++++++++++++----------------- 1 file changed, 263 insertions(+), 263 deletions(-) diff --git a/sv-parser-pp/src/preprocess.rs b/sv-parser-pp/src/preprocess.rs index 0a34220..5afd447 100644 --- a/sv-parser-pp/src/preprocess.rs +++ b/sv-parser-pp/src/preprocess.rs @@ -882,6 +882,90 @@ mod tests { contents } + #[test] + fn escaped_identifier() { + let (ret, _) = preprocess( + testfile_path("escaped_identifier.sv"), + &HashMap::new(), + &[] as &[String], + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/escaped_identifier.sv") + ); + } + + #[test] + #[allow(non_snake_case)] + fn IEEE18002017_macro_mix_quotes() { + let (ret, _) = preprocess( + testfile_path("IEEE18002017_macro_mix_quotes.sv"), + &HashMap::new(), + &[] as &[String], + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/IEEE18002017_macro_mix_quotes.sv") + ); + } + + #[test] + #[allow(non_snake_case)] + fn IEEE18002017_macro_noexpand_string() { + let (ret, _) = preprocess( + testfile_path("IEEE18002017_macro_noexpand_string.sv"), + &HashMap::new(), + &[] as &[String], + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/IEEE18002017_macro_noexpand_string.sv") + ); + } + + #[test] + fn ifdef_nested() { + let (ret, _) = preprocess( + testfile_path("ifdef_nested.sv"), + &HashMap::new(), + &[] as &[String], + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/ifdef_nested.sv") + ); + } + + #[test] + fn ifdef_predefined() { + let mut defines = HashMap::new(); + defines.insert(String::from("behavioral"), None); + let (ret, _) = preprocess( + testfile_path("ifdef_predefined.sv"), + &defines, + &[] as &[String], + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/ifdef_predefined.sv") + ) + } + #[test] fn ifdef_undefined() { let (ret, _) = preprocess( @@ -906,12 +990,10 @@ mod tests { } #[test] - fn ifdef_predefined() { - let mut defines = HashMap::new(); - defines.insert(String::from("behavioral"), None); + fn ifndef_undefined() { let (ret, _) = preprocess( - testfile_path("ifdef_predefined.sv"), - &defines, + testfile_path("ifndef_undefined.sv"), + &HashMap::new(), &[] as &[String], false, false, @@ -919,8 +1001,57 @@ mod tests { .unwrap(); assert_eq!( ret.text(), - testfile_contents("expected/ifdef_predefined.sv") + testfile_contents("expected/ifndef_undefined.sv") + ); + } + + #[test] + fn include_basic() { + let include_paths = [testfile_path("")]; + let (ret, _) = preprocess( + testfile_path("include_basic.sv"), + &HashMap::new(), + &include_paths, + false, + false, ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/include_basic.sv") + ); + assert_eq!( + ret.origin(10).unwrap().0, + &PathBuf::from(testfile_path("include_basic.sv")) + ); + assert_eq!(ret.origin(10).unwrap().1, 10); + assert_eq!( + ret.origin(60).unwrap().0, + &PathBuf::from(testfile_path("test2.svh")) + ); + assert_eq!(ret.origin(60).unwrap().1, 74); + assert_eq!( + ret.origin(80).unwrap().0, + &PathBuf::from(testfile_path("include_basic.sv")) + ); + assert_eq!(ret.origin(80).unwrap().1, 60); + } + + #[test] + fn include_ignore() { + let include_paths = [testfile_path("")]; + let (ret, _) = preprocess( + testfile_path("include_ignore.sv"), + &HashMap::new(), + &include_paths, + false, + true, + ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/include_ignore.sv") + ); } #[test] @@ -956,19 +1087,141 @@ mod tests { } #[test] - fn include_ignore() { + fn include_sameline_comment() { let include_paths = [testfile_path("")]; let (ret, _) = preprocess( - testfile_path("include_ignore.sv"), + testfile_path("include_sameline_comment.sv"), &HashMap::new(), &include_paths, false, - true, + false, ) .unwrap(); assert_eq!( ret.text(), - testfile_contents("expected/include_ignore.sv") + testfile_contents("expected/include_sameline_comment.sv") + ); + assert_eq!( + ret.origin(10).unwrap().0, + &PathBuf::from(testfile_path("include_sameline_comment.sv")) + ); + assert_eq!(ret.origin(10).unwrap().1, 10); + assert_eq!( + ret.origin(50).unwrap().0, + &PathBuf::from(testfile_path("test2.svh")) + ); + assert_eq!(ret.origin(50).unwrap().1, 73); + assert_eq!( + ret.origin(70).unwrap().0, + &PathBuf::from(testfile_path("include_sameline_comment.sv")) + ); + assert_eq!(ret.origin(70).unwrap().1, 50); + } + + #[test] + fn include_sameline_include() { + let include_paths = [testfile_path("")]; + let ret = preprocess( + testfile_path("include_sameline_include.sv"), + &HashMap::new(), + &include_paths, + false, + false, + ); + assert_eq!(format!("{:?}", ret), "Err(IncludeLine)"); + } + + #[test] + fn include_sameline_keyword() { + let include_paths = [testfile_path("")]; + let ret = preprocess( + testfile_path("include_sameline_keyword.sv"), + &HashMap::new(), + &include_paths, + false, + false, + ); + assert_eq!(format!("{:?}", ret), "Err(IncludeLine)"); + } + + #[test] + fn macro_basic() { + let (ret, _) = preprocess( + testfile_path("macro_basic.sv"), + &HashMap::new(), + &[] as &[String], + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/macro_basic.sv") + ); + } + + #[test] + fn macro_comment() { + let (ret, _) = preprocess( + testfile_path("macro_comment.sv"), + &HashMap::new(), + &[] as &[String], + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/macro_comment.sv") + ); + } + + #[test] + fn macro_identifier() { + let (ret, _) = preprocess( + testfile_path("macro_identifier.sv"), + &HashMap::new(), + &[] as &[String], + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/macro_identifier.sv") + ); + } + + #[test] + #[allow(non_snake_case)] + fn macro_LINE() { + let (ret, _) = preprocess( + testfile_path("macro_LINE.sv"), + &HashMap::new(), + &[] as &[String], + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/macro_LINE.sv") + ); + } + + #[test] + fn macro_multiline_comment() { + let (ret, _) = preprocess( + testfile_path("macro_multiline_comment.sv"), + &HashMap::new(), + &[] as &[String], + false, + false, + ) + .unwrap(); + assert_eq!( + ret.text(), + testfile_contents("expected/macro_multiline_comment.sv") ); } @@ -1004,40 +1257,6 @@ mod tests { ); } - #[test] - #[allow(non_snake_case)] - fn IEEE18002017_macro_noexpand_string() { - let (ret, _) = preprocess( - testfile_path("IEEE18002017_macro_noexpand_string.sv"), - &HashMap::new(), - &[] as &[String], - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/IEEE18002017_macro_noexpand_string.sv") - ); - } - - #[test] - #[allow(non_snake_case)] - fn IEEE18002017_macro_mix_quotes() { - let (ret, _) = preprocess( - testfile_path("IEEE18002017_macro_mix_quotes.sv"), - &HashMap::new(), - &[] as &[String], - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/IEEE18002017_macro_mix_quotes.sv") - ); - } - #[test] fn macro_recursion_direct() { let ret = preprocess( @@ -1062,225 +1281,6 @@ mod tests { assert_eq!(format!("{:?}", ret), "Err(ExceedRecursiveLimit)"); } - #[test] - fn include_sameline_include() { - let include_paths = [testfile_path("")]; - let ret = preprocess( - testfile_path("include_sameline_include.sv"), - &HashMap::new(), - &include_paths, - false, - false, - ); - assert_eq!(format!("{:?}", ret), "Err(IncludeLine)"); - } - - #[test] - fn include_sameline_keyword() { - let include_paths = [testfile_path("")]; - let ret = preprocess( - testfile_path("include_sameline_keyword.sv"), - &HashMap::new(), - &include_paths, - false, - false, - ); - assert_eq!(format!("{:?}", ret), "Err(IncludeLine)"); - } - - #[test] - #[allow(non_snake_case)] - fn macro_LINE() { - let (ret, _) = preprocess( - testfile_path("macro_LINE.sv"), - &HashMap::new(), - &[] as &[String], - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/macro_LINE.sv") - ); - } - - #[test] - fn escaped_identifier() { - let (ret, _) = preprocess( - testfile_path("escaped_identifier.sv"), - &HashMap::new(), - &[] as &[String], - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/escaped_identifier.sv") - ); - } - - #[test] - fn macro_comment() { - let (ret, _) = preprocess( - testfile_path("macro_comment.sv"), - &HashMap::new(), - &[] as &[String], - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/macro_comment.sv") - ); - } - - #[test] - fn ifdef_nested() { - let (ret, _) = preprocess( - testfile_path("ifdef_nested.sv"), - &HashMap::new(), - &[] as &[String], - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/ifdef_nested.sv") - ); - } - - #[test] - fn macro_basic() { - let (ret, _) = preprocess( - testfile_path("macro_basic.sv"), - &HashMap::new(), - &[] as &[String], - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/macro_basic.sv") - ); - } - - #[test] - fn macro_identifier() { - let (ret, _) = preprocess( - testfile_path("macro_identifier.sv"), - &HashMap::new(), - &[] as &[String], - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/macro_identifier.sv") - ); - } - - #[test] - fn macro_multiline_comment() { - let (ret, _) = preprocess( - testfile_path("macro_multiline_comment.sv"), - &HashMap::new(), - &[] as &[String], - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/macro_multiline_comment.sv") - ); - } - - #[test] - fn ifndef_undefined() { - let (ret, _) = preprocess( - testfile_path("ifndef_undefined.sv"), - &HashMap::new(), - &[] as &[String], - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/ifndef_undefined.sv") - ); - } - - #[test] - fn include_sameline_comment() { - let include_paths = [testfile_path("")]; - let (ret, _) = preprocess( - testfile_path("include_sameline_comment.sv"), - &HashMap::new(), - &include_paths, - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/include_sameline_comment.sv") - ); - assert_eq!( - ret.origin(10).unwrap().0, - &PathBuf::from(testfile_path("include_sameline_comment.sv")) - ); - assert_eq!(ret.origin(10).unwrap().1, 10); - assert_eq!( - ret.origin(50).unwrap().0, - &PathBuf::from(testfile_path("test2.svh")) - ); - assert_eq!(ret.origin(50).unwrap().1, 73); - assert_eq!( - ret.origin(70).unwrap().0, - &PathBuf::from(testfile_path("include_sameline_comment.sv")) - ); - assert_eq!(ret.origin(70).unwrap().1, 50); - } - - #[test] - fn include_basic() { - let include_paths = [testfile_path("")]; - let (ret, _) = preprocess( - testfile_path("include_basic.sv"), - &HashMap::new(), - &include_paths, - false, - false, - ) - .unwrap(); - assert_eq!( - ret.text(), - testfile_contents("expected/include_basic.sv") - ); - assert_eq!( - ret.origin(10).unwrap().0, - &PathBuf::from(testfile_path("include_basic.sv")) - ); - assert_eq!(ret.origin(10).unwrap().1, 10); - assert_eq!( - ret.origin(60).unwrap().0, - &PathBuf::from(testfile_path("test2.svh")) - ); - assert_eq!(ret.origin(60).unwrap().1, 74); - assert_eq!( - ret.origin(80).unwrap().0, - &PathBuf::from(testfile_path("include_basic.sv")) - ); - assert_eq!(ret.origin(80).unwrap().1, 60); - } - // Check that preprocess() doesn't introduce extra whitespace within and // around compiler directives. #[test]