-
Notifications
You must be signed in to change notification settings - Fork 499
/
logical_operators.rs
83 lines (66 loc) · 1.91 KB
/
logical_operators.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use super::*;
#[track_caller]
fn evaluate(expression: &str, expected: &str) {
Test::new()
.justfile(format!("x := {expression}"))
.env("JUST_UNSTABLE", "1")
.args(["--evaluate", "x"])
.stdout(expected)
.run();
}
#[test]
fn logical_operators_are_unstable() {
Test::new()
.justfile("x := 'foo' && 'bar'")
.args(["--evaluate", "x"])
.stderr_regex(r"error: The logical operators `&&` and `\|\|` are currently unstable. .*")
.status(EXIT_FAILURE)
.run();
Test::new()
.justfile("x := 'foo' || 'bar'")
.args(["--evaluate", "x"])
.stderr_regex(r"error: The logical operators `&&` and `\|\|` are currently unstable. .*")
.status(EXIT_FAILURE)
.run();
}
#[test]
fn and_returns_empty_string_if_lhs_is_empty() {
evaluate("'' && 'hello'", "");
}
#[test]
fn and_returns_rhs_if_lhs_is_non_empty() {
evaluate("'hello' && 'goodbye'", "goodbye");
}
#[test]
fn and_has_lower_precedence_than_plus() {
evaluate("'' && 'goodbye' + 'foo'", "");
evaluate("'foo' + 'hello' && 'goodbye'", "goodbye");
evaluate("'foo' + '' && 'goodbye'", "goodbye");
evaluate("'foo' + 'hello' && 'goodbye' + 'bar'", "goodbyebar");
}
#[test]
fn or_returns_rhs_if_lhs_is_empty() {
evaluate("'' || 'hello'", "hello");
}
#[test]
fn or_returns_lhs_if_lhs_is_non_empty() {
evaluate("'hello' || 'goodbye'", "hello");
}
#[test]
fn or_has_lower_precedence_than_plus() {
evaluate("'' || 'goodbye' + 'foo'", "goodbyefoo");
evaluate("'foo' + 'hello' || 'goodbye'", "foohello");
evaluate("'foo' + '' || 'goodbye'", "foo");
evaluate("'foo' + 'hello' || 'goodbye' + 'bar'", "foohello");
}
#[test]
fn and_has_higher_precedence_than_or() {
evaluate("('' && 'foo') || 'bar'", "bar");
evaluate("'' && 'foo' || 'bar'", "bar");
evaluate("'a' && 'b' || 'c'", "b");
}
#[test]
fn nesting() {
evaluate("'' || '' || '' || '' || 'foo'", "foo");
evaluate("'foo' && 'foo' && 'foo' && 'foo' && 'bar'", "bar");
}