Skip to content

Commit 968de75

Browse files
committed
Remove contents check, add rest of example files
Signed-off-by: Andrew Lamb <[email protected]>
1 parent 225662b commit 968de75

File tree

1 file changed

+27
-59
lines changed

1 file changed

+27
-59
lines changed

sqllogictest/src/parser.rs

+27-59
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,6 @@ fn parse_file_inner(loc: Location) -> Result<Vec<Record>, ParseError> {
632632
mod tests {
633633
use std::io::Write;
634634

635-
use difference::{Changeset, Difference};
636-
637635
use super::*;
638636

639637
#[test]
@@ -647,54 +645,44 @@ mod tests {
647645
parse_roundtrip("../examples/basic/basic.slt")
648646
}
649647

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
654675
fn parse_roundtrip(filename: impl AsRef<Path>) {
655676
let filename = filename.as_ref();
656-
let input_contents = std::fs::read_to_string(filename).expect("reading file");
657-
658677
let records = parse_file(filename).expect("parsing to complete");
659678

660679
let unparsed = records
661680
.iter()
662681
.map(|record| record.to_string())
663682
.collect::<Vec<_>>();
664683

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
678684
let output_contents = unparsed.join("\n");
679685

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-
698686
// The orignal and parsed records should be logically requivalent
699687
let mut output_file = tempfile::NamedTempFile::new().expect("Error creating tempfile");
700688
output_file
@@ -724,26 +712,6 @@ mod tests {
724712
);
725713
}
726714

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-
747715
/// Replaces the actual filename in all Records with
748716
/// "__FILENAME__" so different files with the same contents can
749717
/// compare equal

0 commit comments

Comments
 (0)