-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_class.p8
53 lines (45 loc) · 1.49 KB
/
test_class.p8
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
pico-8 cartridge // http://www.pico-8.com
version 18
__lua__
-- Unit tests for the class module
-- by sparr
-- to run the tests use `pico8 -x tests/test_class.p8`
#include ../pico8lib/class.lua
#include ../pico8lib/functions.lua
#include ../pico8lib/strings.lua
#include ../pico8lib/log.lua
#include ../pico8lib/tables.lua
#include ../pico8lib/test.lua
local suite = TestSuite("class.p8")
local Inheritance = TestCase("inheritance")
function Inheritance:test_assert_inheritance_values ()
local class_parent = class( nil, { a = 1 } )
local class_child = class(class_parent, { b = 2 } )
local instance_parent = class_parent()
local instance_child = class_child()
self:assert_equal(class_parent.a, 1)
self:assert_nil(class_parent.b)
self:assert_equal(instance_parent.a, 1)
self:assert_nil(instance_parent.b)
self:assert_equal(class_child.a, 1)
self:assert_equal(class_child.b, 2)
self:assert_equal(instance_child.a, 1)
self:assert_equal(instance_child.b, 2)
class_parent.a = 3
self:assert_equal(class_child.a, 3)
self:assert_equal(instance_child.a, 3)
self:assert_equal(instance_parent.a, 3)
class_child.a = 4
self:assert_equal(instance_parent.a, 3)
self:assert_equal(instance_child.a, 4)
instance_parent.a = 5
self:assert_equal(class_parent.a, 3)
self:assert_equal(instance_child.a, 4)
instance_child.a = 6
self:assert_equal(class_parent.a, 3)
self:assert_equal(class_child.a, 4)
class_child.b = 7
self:assert_equal(instance_child.b, 7)
end
suite:add_test_case(Inheritance)
run_suites{suite}