PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/specs/core/variant.ds

http://github.com/wilkie/djehuty
Unknown | 65 lines | 55 code | 10 blank | 0 comment | 0 complexity | 004e054306609975b356d2006697acfb MD5 | raw file
 1module specs.core.variant;
 2
 3import testing.support;
 4
 5import core.variant;
 6
 7describe variant() {
 8	describe initial_state() {
 9		it should_be_null() {
10			Variant var;
11			should(var.type == Type.Reference);
12			should(var.to!(Object) is null);
13		}
14	}
15
16	describe assignment() {
17		it should_handle_integer_literals() {
18			Variant var = 2;
19			should(var == 2);
20			should(var.to!(int) == 2);
21		}
22
23		it should_handle_reassignment() {
24			Variant var = 2;
25			var = 3;
26			should(var == 3);
27			var = "foo";
28			should(var == "foo");
29		}
30
31		it should_handle_object_references() {
32			Object foo = new Object();
33			Variant var = foo;
34			should(var == foo);
35		}
36
37		it should_handle_float_literals() {
38			Variant var = 0.5;
39			should(var == 0.5);
40			should(var.to!(float) == 0.5);
41		}
42	}
43
44	describe comparison() {
45		it should_handle_int() {
46			int a = 2;
47			Variant var = a;
48			should(var == a);
49			should(var == 2);
50		}
51
52		it should_handle_float() {
53			float a = 1.23;
54			Variant var = a;
55			should(var == a);
56		}
57
58		it should_handle_string() {
59			string a = "hello";
60			Variant var = a;
61			should(var == a);
62			should(var == "hello");
63		}
64	}
65}