forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass4_test.ml
78 lines (57 loc) · 1.58 KB
/
class4_test.ml
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
66
67
68
69
70
71
72
73
74
75
76
77
78
let suites : Mt.pair_suites ref = ref []
let test_id = ref 0
let eq loc x y =
incr test_id ;
suites :=
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites
class restricted_point x_init =
object (self)
val mutable x = x_init
method get_x = x
method private move d = x <- x + d
method bump = self#move 1
end;;
class type restricted_point_type =
object
method get_x : int
method bump : unit
end;;
class restricted_point' x = (restricted_point x : restricted_point_type);;
class restricted_point2' x = (restricted_point x : restricted_point_type);;
module type POINT = sig
class restricted_point' : int ->
object
method get_x : int
method bump : unit
end
end;;
module Point : POINT = struct
class restricted_point' = restricted_point
end;;
class virtual abstract_point x_init =
object (self)
method virtual get_x : int
method get_offset = self#get_x - x_init
method virtual move : int -> unit
end;;
class point x_init =
object
inherit abstract_point x_init
val mutable x = x_init
method get_x = x
method move d = x <- x + d
end;;
class colored_point x (c : string) =
object
inherit point x
val c = c
method color = c
end;;
let p' = new colored_point 5 "red";;
let () =
eq __LOC__ (5, "red") (p'#get_x, p'#color);;
let get_succ_x p = p#get_x + 1;;
let () = eq __LOC__ 6 (get_succ_x p');;
let set_x p = p#set_x;;
let incr p = set_x p (get_succ_x p)
let () = Mt.from_pair_suites __FILE__ !suites