Skip to content

Commit e42e2fd

Browse files
committed
Move tests to and add new tests to run-pass
1 parent 7d10104 commit e42e2fd

23 files changed

+120
-258
lines changed

src/interpreter_test.rs

Lines changed: 0 additions & 258 deletions
Original file line numberDiff line numberDiff line change
@@ -39,58 +39,6 @@ fn run_and_get_last_result(code: &str) -> StmtResult {
3939
}
4040
}
4141

42-
#[test]
43-
fn literal_value_int() {
44-
assert_eq!(run_and_get_last_value("7;"),
45-
Value::Number(Number::Integer(7)));
46-
}
47-
48-
#[test]
49-
fn literal_value_float() {
50-
assert_eq!(run_and_get_last_value("7.0;"),
51-
Value::Number(Number::Float(7.0)));
52-
}
53-
54-
#[test]
55-
fn literal_value_bool_true() {
56-
assert_eq!(run_and_get_last_value("true;"), Value::Bool(true));
57-
}
58-
59-
#[test]
60-
fn literal_value_bool_false() {
61-
assert_eq!(run_and_get_last_value("false;"), Value::Bool(false));
62-
}
63-
64-
#[test]
65-
fn variable_reassignment_with_type_change() {
66-
assert_eq!(run_and_get_last_value("var x = 10; x = false; x;"),
67-
Value::Bool(false));
68-
}
69-
70-
#[test]
71-
fn identifier_name() {
72-
assert_eq!(run_and_get_last_value("var _x_X123_ = false; _x_X123_;"),
73-
Value::Bool(false));
74-
}
75-
76-
#[test]
77-
fn arithmetic_1() {
78-
assert_eq!(run_and_get_last_value("(1 + 3 / (1 + 1)) * 12 - 1;"),
79-
Value::Number(Number::Float(29.0)));
80-
}
81-
82-
#[test]
83-
fn arithmetic_2() {
84-
assert_eq!(run_and_get_last_value("3 - 5 + 12 / 4 - 1;"),
85-
Value::Number(Number::Float(0.0)));
86-
}
87-
88-
#[test]
89-
fn arithmetic_3() {
90-
assert_eq!(run_and_get_last_value("-10 / 4 + -5 - 12;"),
91-
Value::Number(Number::Float(-19.5)));
92-
}
93-
9442
#[test]
9543
fn i64_support() {
9644
assert_eq!(run_and_get_last_value("9223372036854775807;"),
@@ -102,209 +50,3 @@ fn f64_support() {
10250
assert_eq!(run_and_get_last_value("1234567890.012345678;"),
10351
Value::Number(Number::Float(1234567890.012345678)));
10452
}
105-
106-
107-
#[test]
108-
fn logical_and() {
109-
assert_eq!(run_and_get_last_value("true and true;"), Value::Bool(true));
110-
assert_eq!(run_and_get_last_value("false and true;"),
111-
Value::Bool(false));
112-
assert_eq!(run_and_get_last_value("true and false;"),
113-
Value::Bool(false));
114-
assert_eq!(run_and_get_last_value("false and false;"),
115-
Value::Bool(false));
116-
117-
assert_eq!(run_and_get_last_value("2 and 1;"), Value::Bool(true));
118-
assert_eq!(run_and_get_last_value("3.0 and 22.5;"), Value::Bool(true));
119-
assert_eq!(run_and_get_last_value("5 and 0;"), Value::Bool(false));
120-
assert_eq!(run_and_get_last_value("5.6 and 0.0;"), Value::Bool(false));
121-
}
122-
123-
#[test]
124-
fn logical_or() {
125-
assert_eq!(run_and_get_last_value("true or true;"), Value::Bool(true));
126-
assert_eq!(run_and_get_last_value("false or true;"), Value::Bool(true));
127-
assert_eq!(run_and_get_last_value("true or false;"), Value::Bool(true));
128-
assert_eq!(run_and_get_last_value("false or false;"),
129-
Value::Bool(false));
130-
131-
assert_eq!(run_and_get_last_value("2 or 1;"), Value::Bool(true));
132-
assert_eq!(run_and_get_last_value("3.0 or 22.5;"), Value::Bool(true));
133-
assert_eq!(run_and_get_last_value("5 or 0;"), Value::Bool(true));
134-
assert_eq!(run_and_get_last_value("0 or 0.0;"), Value::Bool(false));
135-
}
136-
137-
#[test]
138-
fn logical_not() {
139-
assert_eq!(run_and_get_last_value("not true;"), Value::Bool(false));
140-
assert_eq!(run_and_get_last_value("not false;"), Value::Bool(true));
141-
142-
assert_eq!(run_and_get_last_value("not 5;"), Value::Bool(false));
143-
assert_eq!(run_and_get_last_value("not 0;"), Value::Bool(true));
144-
assert_eq!(run_and_get_last_value("not 0.0;"), Value::Bool(true));
145-
}
146-
147-
#[test]
148-
fn comparisons() {
149-
assert_eq!(run_and_get_last_value("1 < 2;"), Value::Bool(true));
150-
assert_eq!(run_and_get_last_value("1 > 2;"), Value::Bool(false));
151-
assert_eq!(run_and_get_last_value("1.0 < 2.0;"), Value::Bool(true));
152-
assert_eq!(run_and_get_last_value("1.0 > 2.0;"), Value::Bool(false));
153-
assert_eq!(run_and_get_last_value("4 <= 4;"), Value::Bool(true));
154-
assert_eq!(run_and_get_last_value("2 >= 2;"), Value::Bool(true));
155-
assert_eq!(run_and_get_last_value("3 == 3;"), Value::Bool(true));
156-
assert_eq!(run_and_get_last_value("7 == 7.0;"), Value::Bool(true));
157-
assert_eq!(run_and_get_last_value("7 == 7.1;"), Value::Bool(false));
158-
assert_eq!(run_and_get_last_value("true == 1;"), Value::Bool(false));
159-
}
160-
161-
#[test]
162-
fn variable_declaration() {
163-
assert_eq!(run_and_get_last_value("var x = 5; x;"),
164-
Value::Number(Number::Integer(5)));
165-
}
166-
167-
#[test]
168-
fn variable_reassignment() {
169-
assert_eq!(run_and_get_last_value("var x = 10; x = 42; x;"),
170-
Value::Number(Number::Integer(42)));
171-
}
172-
173-
#[test]
174-
fn id_in_expr() {
175-
assert_eq!(run_and_get_last_value("var x = 5; x / 2 + x;"),
176-
Value::Number(Number::Float(7.5)));
177-
}
178-
179-
#[test]
180-
fn create_tuple() {
181-
assert_eq!(run_and_get_last_value("(1, 2, 3);"),
182-
Value::Tuple(vec![
183-
Value::Number(Number::Integer(1)),
184-
Value::Number(Number::Integer(2)),
185-
Value::Number(Number::Integer(3)),
186-
]));
187-
}
188-
189-
#[test]
190-
fn add_tuples() {
191-
assert_eq!(run_and_get_last_value("(\"a\",) + (\"t\",);"),
192-
Value::Tuple(vec![Value::String("a".to_owned()), Value::String("t".to_owned())]));
193-
}
194-
195-
#[test]
196-
fn index_tuple() {
197-
assert_eq!(run_and_get_last_value("(1, 2, 3)[0];"),
198-
Value::Number(Number::Integer(1)));
199-
}
200-
201-
#[test]
202-
fn mix_call_and_index() {
203-
assert_eq!(run_and_get_last_value("((fn() { return false; },), 2, 3)[0][0]();"),
204-
Value::Bool(false));
205-
assert_eq!(run_and_get_last_value("fn() { return fn() { return (1, 2, true); }; }()()[2];"),
206-
Value::Bool(true));
207-
}
208-
209-
#[test]
210-
fn if_expr_true() {
211-
assert_eq!(run_and_get_last_value("var x = 5; if 1 < 2 { x = 6; } else { x = 7; } x;"),
212-
Value::Number(Number::Integer(6)));
213-
}
214-
215-
#[test]
216-
fn if_expr_false() {
217-
assert_eq!(run_and_get_last_value("var x = 5; if 1 > 2 { x = 6; } else { x = 7; } x;"),
218-
Value::Number(Number::Integer(7)));
219-
}
220-
221-
#[test]
222-
fn loop_and_break() {
223-
assert_eq!(run_and_get_last_value("var x = 5; loop { if x > 20 { break; } x = x + 5; } x;"),
224-
Value::Number(Number::Integer(25)));
225-
}
226-
227-
#[test]
228-
fn block_env() {
229-
assert_eq!(run_and_get_last_value("var x = 5; { var x = 10; x = 20; } x;"),
230-
Value::Number(Number::Integer(5)));
231-
assert_eq!(run_and_get_last_value("var x = 5; { var x = 10; x = 20; x; }"),
232-
Value::Number(Number::Integer(20)));
233-
}
234-
235-
#[test]
236-
fn test_println_runs() {
237-
assert_eq!(run_and_get_last_result("println();"), StmtResult::None);
238-
assert_eq!(run_and_get_last_result("println(5, true,);"),
239-
StmtResult::None);
240-
}
241-
242-
#[test]
243-
fn test_factorial() {
244-
assert_eq!(run_and_get_last_value("fn factorial(n) { if n < 2 { return 1; } return n * \
245-
factorial(n - 1); } factorial(5); "),
246-
Value::Number(Number::Integer(120)));
247-
assert_eq!(run_and_get_last_value("fn factorial(n) { if n < 2 { return 1; } return n * \
248-
factorial(n - 1); } factorial(15); "),
249-
Value::Number(Number::Integer(1307674368000)));
250-
}
251-
252-
#[test]
253-
fn test_curried_add() {
254-
let code = "fn addX(x) {
255-
return fn(y) {
256-
return x + y;
257-
};
258-
}
259-
260-
addX(10)(20);
261-
";
262-
assert_eq!(run_and_get_last_value(code),
263-
Value::Number(Number::Integer(30)));
264-
}
265-
266-
#[test]
267-
fn test_y_combinator() {
268-
let code = "fn Y(f) {
269-
var lazywrapper = fn () { return Y (f); };
270-
return f(lazywrapper);
271-
}
272-
273-
fn factorialwrap(lazywrapfact) {
274-
fn factorial(i) {
275-
if (i == 0) {
276-
return 1;
277-
} else {
278-
return i * lazywrapfact()(i - 1);
279-
}
280-
}
281-
return factorial;
282-
}
283-
284-
var fact = Y(factorialwrap);
285-
286-
fact(4);
287-
";
288-
assert_eq!(run_and_get_last_value(code),
289-
Value::Number(Number::Integer(24)));
290-
}
291-
292-
#[test]
293-
fn test_string_concat() {
294-
assert_eq!(run_and_get_last_value("\"abc\" + \"def\";"),
295-
Value::String("abcdef".to_owned()));
296-
assert_eq!(run_and_get_last_value("\"abc\" + 123;"),
297-
Value::String("abc123".to_owned()));
298-
assert_eq!(run_and_get_last_value("\"abc\" + true;"),
299-
Value::String("abctrue".to_owned()));
300-
assert_eq!(run_and_get_last_value("456 + \"abc\";"),
301-
Value::String("456abc".to_owned()));
302-
assert_eq!(run_and_get_last_value("false + \"abc\";"),
303-
Value::String("falseabc".to_owned()));
304-
}
305-
306-
#[test]
307-
fn test_len() {
308-
assert_eq!(run_and_get_last_value("len((1, 2, 3));"),
309-
Value::Number(Number::Integer(3)));
310-
}

tests/run-pass/arithmetic.bl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
assert_eq((1 + 3 / (1 + 1)) * 12 - 1, 29.0);
2+
assert_eq(3 - 5 + 12 / 4 - 1, 0.0);
3+
assert_eq(-10 / 4 + -5 - 12, -19.5);

tests/run-pass/block-env.bl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var x = 3;
2+
var y = 10;
3+
{
4+
var x = 6;
5+
assert_eq(x, 6);
6+
y = 20;
7+
}
8+
assert_eq(x, 3);
9+
assert_eq(y, 20);

tests/run-pass/bool-cast.bl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
assert(1);
2+
assert(not 0);
3+
assert(1.1);
4+
assert(not 0.0);
5+
assert("Hello!");
6+
assert(not "");
7+
assert((1, 2));
8+
assert(not (,));

tests/run-pass/comparisons.bl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
assert(1 < 2);
2+
assert(not 2 < 1);
3+
assert(1.0 < 2.0);
4+
assert(not 2.0 < 1.0);
5+
assert(4 <= 4);
6+
assert(4 >= 4);
7+
assert(5.0 <= 5.0);
8+
assert(5.0 >= 5.0);
9+
assert(7 == 7.0);
10+
assert(not 7 == 7.1);
11+
assert(not 1 == true);

tests/run-pass/curried-add.bl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn add_x(x) {
2+
return fn(y) {
3+
return x + y;
4+
};
5+
}
6+
7+
assert_eq(add_x("Hello,")(" world!"), "Hello, world!");

tests/run-pass/empty.bl

Whitespace-only changes.

tests/run-pass/fn.bl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn foo(x) {
2+
return x + 1;
3+
}
4+
5+
assert_eq(foo(10), 11);

tests/run-pass/id-in-expr.bl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var x = 5;
2+
assert_eq(x / 2 + x, 7.5);

tests/run-pass/identifier-name.bl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var _x_X123_ = false;
2+
assert_eq(_x_X123_, false);

0 commit comments

Comments
 (0)