Skip to content

Commit d31a19f

Browse files
authored
Merge pull request #7356 from RenjiSann/expr-fixes
expr: Add tests
2 parents 15864bc + a9d8eed commit d31a19f

File tree

3 files changed

+889
-11
lines changed

3 files changed

+889
-11
lines changed

src/uu/expr/src/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ pub enum ExprError {
4848
UnmatchedOpeningBrace,
4949
#[error("Unmatched ) or \\}}")]
5050
UnmatchedClosingBrace,
51-
#[error("Invalid content of {0}")]
52-
InvalidContent(String),
51+
#[error("Invalid content of \\{{\\}}")]
52+
InvalidBracketContent,
5353
}
5454

5555
impl UError for ExprError {

src/uu/expr/src/syntax_tree.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ fn check_posix_regex_errors(pattern: &str) -> ExprResult<()> {
264264
(true, true, false) => Ok(()),
265265
(_, false, _) => Err(ExprError::UnmatchedOpeningBrace),
266266
(false, _, _) => Err(ExprError::UnmatchedOpeningParenthesis),
267-
(true, true, true) => Err(ExprError::InvalidContent(r"\{\}".to_string())),
267+
(true, true, true) => Err(ExprError::InvalidBracketContent),
268268
}
269269
}
270270

@@ -601,7 +601,7 @@ pub fn is_truthy(s: &NumOrStr) -> bool {
601601
#[cfg(test)]
602602
mod test {
603603
use crate::ExprError;
604-
use crate::ExprError::InvalidContent;
604+
use crate::ExprError::InvalidBracketContent;
605605

606606
use super::{check_posix_regex_errors, AstNode, BinOp, NumericOp, RelationOp, StringOp};
607607

@@ -795,7 +795,7 @@ mod test {
795795
fn check_regex_empty_repeating_pattern() {
796796
assert_eq!(
797797
check_posix_regex_errors("ab\\{\\}"),
798-
Err(InvalidContent(r"\{\}".to_string()))
798+
Err(InvalidBracketContent)
799799
)
800800
}
801801

@@ -804,27 +804,27 @@ mod test {
804804
assert_eq!(
805805
// out of order
806806
check_posix_regex_errors("ab\\{1,0\\}"),
807-
Err(InvalidContent(r"\{\}".to_string()))
807+
Err(InvalidBracketContent)
808808
);
809809
assert_eq!(
810810
check_posix_regex_errors("ab\\{1,a\\}"),
811-
Err(InvalidContent(r"\{\}".to_string()))
811+
Err(InvalidBracketContent)
812812
);
813813
assert_eq!(
814814
check_posix_regex_errors("ab\\{a,3\\}"),
815-
Err(InvalidContent(r"\{\}".to_string()))
815+
Err(InvalidBracketContent)
816816
);
817817
assert_eq!(
818818
check_posix_regex_errors("ab\\{a,b\\}"),
819-
Err(InvalidContent(r"\{\}".to_string()))
819+
Err(InvalidBracketContent)
820820
);
821821
assert_eq!(
822822
check_posix_regex_errors("ab\\{a,\\}"),
823-
Err(InvalidContent(r"\{\}".to_string()))
823+
Err(InvalidBracketContent)
824824
);
825825
assert_eq!(
826826
check_posix_regex_errors("ab\\{,b\\}"),
827-
Err(InvalidContent(r"\{\}".to_string()))
827+
Err(InvalidBracketContent)
828828
);
829829
}
830830
}

0 commit comments

Comments
 (0)