-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliterals.rs
54 lines (49 loc) · 1.34 KB
/
literals.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
use evilang_lib::ast::expression::Expression;
use evilang_lib::interpreter::runtime_values::PrimitiveValue;
use crate::common::{ensure_program_statement_results, TestRes};
mod common;
#[test]
fn integer_literal() -> TestRes {
return ensure_program_statement_results(
"42;",
vec![Expression::integer_literal(42).consume_as_statement()],
vec![PrimitiveValue::integer(42)],
);
}
#[test]
fn string_literal() -> TestRes {
return ensure_program_statement_results(
r#""This is a string and this is a double quote: \"";"#,
vec![Expression::StringLiteral("This is a string and this is a double quote: \"".parse().unwrap()).consume_as_statement()],
vec![PrimitiveValue::String("This is a string and this is a double quote: \"".parse().unwrap())],
);
}
#[test]
fn comments_and_white_space() -> TestRes {
ensure_program_statement_results(
r#"
// This is a comment
//*
"someCode();"
/*/
"someOtherCode();"
//*/
;
"#,
vec![Expression::StringLiteral("someCode();".parse().unwrap()).consume_as_statement()],
vec![PrimitiveValue::String("someCode();".parse().unwrap())],
);
ensure_program_statement_results(
r#"
// This is a comment
/*
"someCode();"
/*/
"someOtherCode();"
//*/
;
"#,
vec![Expression::StringLiteral("someOtherCode();".parse().unwrap()).consume_as_statement()],
vec![PrimitiveValue::String("someOtherCode();".parse().unwrap())],
);
}