@@ -632,8 +632,6 @@ fn parse_file_inner(loc: Location) -> Result<Vec<Record>, ParseError> {
632
632
mod tests {
633
633
use std:: io:: Write ;
634
634
635
- use difference:: { Changeset , Difference } ;
636
-
637
635
use super :: * ;
638
636
639
637
#[ test]
@@ -647,54 +645,44 @@ mod tests {
647
645
parse_roundtrip ( "../examples/basic/basic.slt" )
648
646
}
649
647
650
- /// Parses the specified file into Records, and ensures the
651
- /// results of unparsing them are the same
652
- ///
653
- /// Prints a hopefully useful message on failure
648
+ #[ test]
649
+ fn test_condition ( ) {
650
+ parse_roundtrip ( "../examples/condition/condition.slt" )
651
+ }
652
+
653
+ #[ test]
654
+ fn test_file_level_sort_mode ( ) {
655
+ parse_roundtrip ( "../examples/file_level_sort_mode/file_level_sort_mode.slt" )
656
+ }
657
+
658
+ #[ test]
659
+ fn test_rowsort ( ) {
660
+ parse_roundtrip ( "../examples/rowsort/rowsort.slt" )
661
+ }
662
+
663
+ #[ test]
664
+ fn test_test_dir_escape ( ) {
665
+ parse_roundtrip ( "../examples/test_dir_escape/test_dir_escape.slt" )
666
+ }
667
+
668
+ #[ test]
669
+ fn test_validator ( ) {
670
+ parse_roundtrip ( "../examples/validator/validator.slt" )
671
+ }
672
+
673
+ /// Verifies Display impl is consistent with parsing by ensuring
674
+ /// roundtrip parse(unparse(parse())) is consistent
654
675
fn parse_roundtrip ( filename : impl AsRef < Path > ) {
655
676
let filename = filename. as_ref ( ) ;
656
- let input_contents = std:: fs:: read_to_string ( filename) . expect ( "reading file" ) ;
657
-
658
677
let records = parse_file ( filename) . expect ( "parsing to complete" ) ;
659
678
660
679
let unparsed = records
661
680
. iter ( )
662
681
. map ( |record| record. to_string ( ) )
663
682
. collect :: < Vec < _ > > ( ) ;
664
683
665
- // Technically this will not always be the same due to some whitespace normalization
666
- //
667
- // query III
668
- // select * from foo;
669
- // ----
670
- // 1 2
671
- //
672
- // Will print out collaposting the spaces between `query`
673
- //
674
- // query III
675
- // select * from foo;
676
- // ----
677
- // 1 2
678
684
let output_contents = unparsed. join ( "\n " ) ;
679
685
680
- let changeset = Changeset :: new ( & input_contents, & output_contents, "\n " ) ;
681
-
682
- assert ! (
683
- no_diffs( & changeset) ,
684
- "Mismatch for {:?}\n \
685
- *********\n \
686
- diff:\n \
687
- *********\n \
688
- {}\n \n \
689
- *********\n \
690
- output:\n \
691
- *********\n \
692
- {}\n \n ",
693
- filename,
694
- UsefulDiffDisplay ( & changeset) ,
695
- output_contents,
696
- ) ;
697
-
698
686
// The orignal and parsed records should be logically requivalent
699
687
let mut output_file = tempfile:: NamedTempFile :: new ( ) . expect ( "Error creating tempfile" ) ;
700
688
output_file
@@ -724,26 +712,6 @@ mod tests {
724
712
) ;
725
713
}
726
714
727
- /// returns true if there are no differences in the changeset
728
- fn no_diffs ( changeset : & Changeset ) -> bool {
729
- changeset
730
- . diffs
731
- . iter ( )
732
- . all ( |diff| matches ! ( diff, Difference :: Same ( _) ) )
733
- }
734
-
735
- struct UsefulDiffDisplay < ' a > ( & ' a Changeset ) ;
736
-
737
- impl < ' a > std:: fmt:: Display for UsefulDiffDisplay < ' a > {
738
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
739
- self . 0 . diffs . iter ( ) . try_for_each ( |diff| match diff {
740
- Difference :: Same ( x) => writeln ! ( f, "{x}" ) ,
741
- Difference :: Add ( x) => writeln ! ( f, "+ {x}" ) ,
742
- Difference :: Rem ( x) => writeln ! ( f, "- {x}" ) ,
743
- } )
744
- }
745
- }
746
-
747
715
/// Replaces the actual filename in all Records with
748
716
/// "__FILENAME__" so different files with the same contents can
749
717
/// compare equal
0 commit comments