From ddf33de79dc938e60d22e13b0c5a87f0545b73d9 Mon Sep 17 00:00:00 2001 From: damc Date: Tue, 26 Jul 2022 16:46:13 +0200 Subject: [PATCH] ppTests Explain and rename include_basic,include_origin -> include_withindent,include_noindent --- sv-parser-pp/src/preprocess.rs | 116 +++++++++++------- ...{include_origin.sv => include_noindent.sv} | 0 ...include_basic.sv => include_withindent.sv} | 0 ...{include_origin.sv => include_noindent.sv} | 0 ...include_basic.sv => include_withindent.sv} | 0 5 files changed, 72 insertions(+), 44 deletions(-) rename sv-parser-pp/testcases/expected/{include_origin.sv => include_noindent.sv} (100%) rename sv-parser-pp/testcases/expected/{include_basic.sv => include_withindent.sv} (100%) rename sv-parser-pp/testcases/{include_origin.sv => include_noindent.sv} (100%) rename sv-parser-pp/testcases/{include_basic.sv => include_withindent.sv} (100%) diff --git a/sv-parser-pp/src/preprocess.rs b/sv-parser-pp/src/preprocess.rs index adc4303..c8d3626 100644 --- a/sv-parser-pp/src/preprocess.rs +++ b/sv-parser-pp/src/preprocess.rs @@ -1234,38 +1234,6 @@ mod tests { ); } // }}} - #[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("included.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, 63); - } // }}} - #[test] fn include_ignore() { // {{{ let include_paths = [testfile_path("")]; @@ -1284,35 +1252,49 @@ mod tests { } // }}} #[test] - fn include_origin() { // {{{ + fn include_noindent() { // {{{ let include_paths = [testfile_path("")]; let (ret, _) = preprocess( - testfile_path("include_origin.sv"), + testfile_path("include_noindent.sv"), &HashMap::new(), &include_paths, false, false, ) .unwrap(); + assert_eq!( ret.text(), - testfile_contents("expected/include_origin.sv") + testfile_contents("expected/include_noindent.sv") ); + + // 11th char of returned text is '_' in the module identifier + // "and_op", and originates from the parent file. + // Characters are zero-indexed. + let n = 10; assert_eq!( - ret.origin(10).unwrap().0, - &PathBuf::from(testfile_path("include_origin.sv")) + ret.origin(n).unwrap(), + (&PathBuf::from(testfile_path("include_noindent.sv")), n) ); - assert_eq!(ret.origin(10).unwrap().1, 10); + assert_eq!(ret.text().chars().nth(n).unwrap(), '_'); + + // 51st char of returned text is 'd' in the primitive identifier + // "and", and originates from the child file at character index 72. + let n = 50; assert_eq!( - ret.origin(50).unwrap().0, - &PathBuf::from(testfile_path("included.svh")) + ret.origin(n).unwrap(), + (&PathBuf::from(testfile_path("included.svh")), 73) ); - assert_eq!(ret.origin(50).unwrap().1, 73); + assert_eq!(ret.text().chars().nth(n).unwrap(), 'd'); + + // 71st char of returned text is 'o' in the keword "endmodule", and + // originates from the parent file. + let n = 70; assert_eq!( - ret.origin(70).unwrap().0, - &PathBuf::from(testfile_path("include_origin.sv")) + ret.origin(n).unwrap(), + (&PathBuf::from(testfile_path("include_noindent.sv")), 53) ); - assert_eq!(ret.origin(70).unwrap().1, 53); + assert_eq!(ret.text().chars().nth(n).unwrap(), 'o'); } // }}} #[test] @@ -1373,6 +1355,52 @@ mod tests { assert_eq!(format!("{:?}", ret), "Err(IncludeLine)"); } // }}} + #[test] + fn include_withindent() { // {{{ + let include_paths = [testfile_path("")]; + let (ret, _) = preprocess( + testfile_path("include_withindent.sv"), + &HashMap::new(), + &include_paths, + false, + false, + ) + .unwrap(); + + assert_eq!( + ret.text(), + testfile_contents("expected/include_withindent.sv") + ); + + // 11th char of returned text is '_' in the module identifier + // "and_op", and originates from the parent file. + // Characters are zero-indexed. + let n = 10; + assert_eq!( + ret.origin(n).unwrap(), + (&PathBuf::from(testfile_path("include_withindent.sv")), n) + ); + assert_eq!(ret.text().chars().nth(n).unwrap(), '_'); + + // 59th char of returned text is 'n' in the primitive identifier + // "and", and originates from the child file at character index 72. + let n = 58; + assert_eq!( + ret.origin(n).unwrap(), + (&PathBuf::from(testfile_path("included.svh")), 72) + ); + assert_eq!(ret.text().chars().nth(n).unwrap(), 'n'); + + // 80th char of returned text is 'o' in the keyword "endmodule", and + // originates from the parent file. + let n = 79; + assert_eq!( + ret.origin(n).unwrap(), + (&PathBuf::from(testfile_path("include_withindent.sv")), 62) + ); + assert_eq!(ret.text().chars().nth(n).unwrap(), 'o'); + } // }}} + #[test] fn keywords() { // {{{ let include_paths = [testfile_path("")]; diff --git a/sv-parser-pp/testcases/expected/include_origin.sv b/sv-parser-pp/testcases/expected/include_noindent.sv similarity index 100% rename from sv-parser-pp/testcases/expected/include_origin.sv rename to sv-parser-pp/testcases/expected/include_noindent.sv diff --git a/sv-parser-pp/testcases/expected/include_basic.sv b/sv-parser-pp/testcases/expected/include_withindent.sv similarity index 100% rename from sv-parser-pp/testcases/expected/include_basic.sv rename to sv-parser-pp/testcases/expected/include_withindent.sv diff --git a/sv-parser-pp/testcases/include_origin.sv b/sv-parser-pp/testcases/include_noindent.sv similarity index 100% rename from sv-parser-pp/testcases/include_origin.sv rename to sv-parser-pp/testcases/include_noindent.sv diff --git a/sv-parser-pp/testcases/include_basic.sv b/sv-parser-pp/testcases/include_withindent.sv similarity index 100% rename from sv-parser-pp/testcases/include_basic.sv rename to sv-parser-pp/testcases/include_withindent.sv