-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval_parity.rs
More file actions
65 lines (57 loc) · 1.41 KB
/
eval_parity.rs
File metadata and controls
65 lines (57 loc) · 1.41 KB
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
mod common;
use common::run_code_capture_output;
use common::run_code_with_vm;
#[test]
fn test_eval_basic() {
let code = r#"<?php
eval("echo 'Hello from eval';");
"#;
let (_, output) = run_code_capture_output(code).unwrap();
assert_eq!(output, "Hello from eval");
}
#[test]
fn test_eval_with_variables() {
let code = r#"<?php
$x = 10;
eval('$y = $x + 5; echo $y;');
"#;
let (_, output) = run_code_capture_output(code).unwrap();
assert_eq!(output, "15");
}
#[test]
fn test_eval_variable_scope() {
let code = r#"<?php
$a = 1;
eval('$b = $a + 1;');
echo $b;
"#;
let (_, output) = run_code_capture_output(code).unwrap();
assert_eq!(output, "2");
}
#[test]
fn test_eval_return_value() {
let code = r#"<?php
$result = eval('return 42;');
echo $result;
"#;
let (_, output) = run_code_capture_output(code).unwrap();
assert_eq!(output, "42");
}
#[test]
fn test_eval_parse_error() {
let code = r#"<?php
eval('this is not valid php');
"#;
let result = run_code_with_vm(code);
// In PHP 7+, parse errors in eval throw ParseError
assert!(result.is_err(), "eval with parse error should fail");
}
#[test]
fn test_eval_vs_include_different_behavior() {
// This test verifies that eval() doesn't try to read from filesystem
let code = r#"<?php
eval('echo "from eval";');
"#;
let (_, output) = run_code_capture_output(code).unwrap();
assert_eq!(output, "from eval");
}