Skip to content

Commit 5b7b47e

Browse files
committed
Add tests for ReconstructionSettings constructor
1 parent 79caaea commit 5b7b47e

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

core/src/lang.rs

+82-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ impl<'a> From<LogicalLines<'a>> for (&'a [Token<'a>], Vec<LogicalLine>) {
489489
}
490490
}
491491

492-
#[derive(Debug)]
492+
#[derive(Debug, PartialEq, Eq)]
493493
pub struct InvalidReconstructionSettingsError {
494494
msg: String,
495495
}
@@ -669,3 +669,84 @@ impl LogicalLineFileFormatter for FormatterKind {
669669
}
670670
}
671671
}
672+
673+
#[cfg(test)]
674+
mod tests {
675+
use super::*;
676+
677+
mod reconstruction_validation {
678+
use super::*;
679+
680+
#[test]
681+
fn normal_whitespace() {
682+
assert!(ReconstructionSettings::new("\n", "\t", " ",).is_ok());
683+
}
684+
685+
#[test]
686+
fn weird_whitespace() {
687+
assert!(ReconstructionSettings::new("\0", "\x1F", "\u{3000}",).is_ok());
688+
}
689+
690+
#[test]
691+
fn borrowed_or_owned() {
692+
assert!(ReconstructionSettings::new("\n", " ", " ").is_ok());
693+
assert!(
694+
ReconstructionSettings::new("\n".to_owned(), " ".to_owned(), " ".to_owned())
695+
.is_ok()
696+
);
697+
}
698+
699+
#[test]
700+
fn invalid_empty() {
701+
use super::InvalidReconstructionSettingsError as E;
702+
703+
assert_eq!(
704+
ReconstructionSettings::new("", "", "").err(),
705+
Some(E::new("newline sequence cannot be blank"))
706+
);
707+
assert_eq!(
708+
ReconstructionSettings::new("\n", "", "").err(),
709+
Some(E::new("indentation sequence cannot be blank"))
710+
);
711+
assert_eq!(
712+
ReconstructionSettings::new("\n", " ", "").err(),
713+
Some(E::new("continuation sequence cannot be blank"))
714+
);
715+
}
716+
717+
#[test]
718+
fn invalid_non_whitespace() {
719+
use super::InvalidReconstructionSettingsError as E;
720+
721+
assert_eq!(
722+
ReconstructionSettings::new("a", " ", " ").err(),
723+
Some(E::new(
724+
"newline sequence must be all whitespace (was \"a\")"
725+
))
726+
);
727+
assert_eq!(
728+
ReconstructionSettings::new("\n", "a", " ").err(),
729+
Some(E::new(
730+
"indentation sequence must be all whitespace (was \"a\")"
731+
))
732+
);
733+
assert_eq!(
734+
ReconstructionSettings::new("\n", " ", "a").err(),
735+
Some(E::new(
736+
"continuation sequence must be all whitespace (was \"a\")"
737+
))
738+
);
739+
}
740+
741+
#[test]
742+
fn display() {
743+
assert_eq!(
744+
ReconstructionSettings::new("", " ", " ")
745+
.err()
746+
.unwrap()
747+
.to_string(),
748+
"Invalid reconstruction settings: newline sequence cannot be blank"
749+
);
750+
}
751+
}
752+
}

0 commit comments

Comments
 (0)