2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-12-22 13:10:43 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_simple_arithmetic() {
|
2021-05-29 21:25:23 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["1", "+", "1"])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("2\n");
|
2015-12-22 13:10:43 +00:00
|
|
|
|
2021-05-29 21:25:23 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["1", "-", "1"])
|
|
|
|
.fails()
|
|
|
|
.status_code(1)
|
|
|
|
.stdout_only("0\n");
|
2015-12-22 13:10:43 +00:00
|
|
|
|
2021-05-29 21:25:23 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["3", "*", "2"])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("6\n");
|
2015-12-22 13:10:43 +00:00
|
|
|
|
2021-05-29 21:25:23 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["4", "/", "2"])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("2\n");
|
2015-12-22 13:10:43 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 22:30:07 +00:00
|
|
|
#[test]
|
|
|
|
fn test_complex_arithmetic() {
|
2021-05-29 21:25:23 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["9223372036854775807", "+", "9223372036854775807"])
|
2021-05-29 21:25:23 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("18446744073709551614\n");
|
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&[
|
|
|
|
"92233720368547758076549841651981984981498415651",
|
|
|
|
"%",
|
|
|
|
"922337203685",
|
|
|
|
])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("533691697086\n");
|
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&[
|
|
|
|
"92233720368547758076549841651981984981498415651",
|
|
|
|
"*",
|
|
|
|
"922337203685",
|
|
|
|
])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("85070591730190566808700855121818604965830915152801178873935\n");
|
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&[
|
|
|
|
"92233720368547758076549841651981984981498415651",
|
|
|
|
"-",
|
|
|
|
"922337203685",
|
|
|
|
])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("92233720368547758076549841651981984059161211966\n");
|
2018-06-26 22:30:07 +00:00
|
|
|
|
2021-05-29 21:25:23 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["9", "/", "0"])
|
|
|
|
.fails()
|
|
|
|
.stderr_only("expr: division by zero\n");
|
2018-06-26 22:30:07 +00:00
|
|
|
}
|
|
|
|
|
2015-12-22 13:10:43 +00:00
|
|
|
#[test]
|
|
|
|
fn test_parenthesis() {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["(", "1", "+", "1", ")", "*", "2"])
|
2021-05-29 21:25:23 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("4\n");
|
2015-12-22 13:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_or() {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["0", "|", "foo"])
|
2021-05-29 21:25:23 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("foo\n");
|
2020-04-13 18:36:03 +00:00
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["foo", "|", "bar"])
|
2021-05-29 21:25:23 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("foo\n");
|
2015-12-22 13:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_and() {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["foo", "&", "1"])
|
2021-05-29 21:25:23 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("foo\n");
|
2015-12-22 13:10:43 +00:00
|
|
|
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["", "&", "1"]).run().stdout_is("0\n");
|
2015-12-22 13:10:43 +00:00
|
|
|
}
|
2021-05-23 19:58:18 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_substr() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["substr", "abc", "1", "1"])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("a\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_invalid_substr() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["substr", "abc", "0", "1"])
|
|
|
|
.fails()
|
|
|
|
.status_code(1)
|
|
|
|
.stdout_only("\n");
|
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["substr", "abc", &(std::usize::MAX.to_string() + "0"), "1"])
|
|
|
|
.fails()
|
|
|
|
.status_code(1)
|
|
|
|
.stdout_only("\n");
|
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["substr", "abc", "0", &(std::usize::MAX.to_string() + "0")])
|
|
|
|
.fails()
|
|
|
|
.status_code(1)
|
|
|
|
.stdout_only("\n");
|
|
|
|
}
|