1
2
3
4
5
6
7
8
9
10 :(scenario deep_copy_number)
11 def main [
12 local-scope
13 x:num <- copy 34
14 y:num <- deep-copy x
15 10:bool/raw <- equal x, y
16 ]
17
18 +mem: storing 1 in location 10
19
20 :(scenario deep_copy_null_pointer)
21 def main [
22 local-scope
23 x:&:num <- copy 0
24 y:&:num <- deep-copy x
25 10:bool/raw <- equal x, y
26 ]
27
28 +mem: storing 1 in location 10
29
30 :(scenario deep_copy_container_without_address)
31 container foo [
32 x:num
33 y:num
34 ]
35 def main [
36 local-scope
37 a:foo <- merge 34, 35
38 b:foo <- deep-copy a
39 10:bool/raw <- equal a, b
40 ]
41
42 +mem: storing 1 in location 10
43
44 :(scenario deep_copy_address)
45 % Memory_allocated_until = 200;
46 def main [
47
48
49 1:&:num <- copy 100/unsafe
50 *1:&:num <- copy 34
51 2:&:num <- deep-copy 1:&:num
52 10:bool <- equal 1:&:num, 2:&:num
53 11:bool <- equal *1:&:num, *2:&:num
54 2:&:num <- copy 0
55 ]
56
57 +mem: storing 0 in location 10
58
59 +mem: storing 1 in location 11
60
61 :(scenario deep_copy_address_to_container)
62 % Memory_allocated_until = 200;
63 def main [
64
65
66 1:&:point <- copy 100/unsafe
67 *1:&:point <- merge 34, 35
68 2:&:point <- deep-copy 1:&:point
69 10:bool <- equal 1:&:point, 2:&:point
70 11:bool <- equal *1:&:point, *2:&:point
71 ]
72
73 +mem: storing 0 in location 10
74
75 +mem: storing 1 in location 11
76
77 :(scenario deep_copy_address_to_address)
78 % Memory_allocated_until = 200;
79 def main [
80
81
82 1:&:&:num <- copy 100/unsafe
83 *1:&:&:num <- copy 150/unsafe
84 **1:&:&:num <- copy 34
85 2:&:&:num <- deep-copy 1:&:&:num
86 10:bool <- equal 1:&:&:num, 2:&:&:num
87 11:bool <- equal *1:&:&:num, *2:&:&:num
88 12:bool <- equal **1:&:&:num, **2:&:&:num
89 ]
90
91 +mem: storing 0 in location 10
92
93 +mem: storing 0 in location 11
94
95 +mem: storing 1 in location 12
96
97 :(scenario deep_copy_array)
98 % Memory_allocated_until = 200;
99 def main [
100
101
102 100:num <- copy 3
103 1:&:@:num <- copy 100/unsafe
104 put-index *1:&:@:num, 0, 34
105 put-index *1:&:@:num, 1, 35
106 put-index *1:&:@:num, 2, 36
107 stash [old:], *1:&:@:num
108 2:&:@:num <- deep-copy 1:&:@:num
109 stash 2:&:@:num
110 stash [new:], *2:&:@:num
111 10:bool# To check our support for screens in scenarios, rewrite tests from print.mu
scenario print-character-at-top-left-2 [
local-scope
assume-screen 3/width, 2/height
run [
a:char <- copy 97/a
screen <- print screen, a
]
screen-should-contain [
.a .
. .
]
]
scenario clear-line-erases-printed-characters-2 [
local-scope
assume-screen 5/width, 3/height
# print a character
a:char <- copy 97/a
screen <- print screen, a
# move cursor to start of line
screen <- move-cursor screen, 0/row, 0/column
run [
screen <- clear-line screen
]
screen-should-contain [
. .
. .
. .
]
]
scenario scroll-screen [
local-scope
assume-screen 3/width, 2/height
run [
a:char <- copy 97/a
move-cursor screen, 1/row, 2/column
screen <- print screen, a
screen <- print screen, a
]
screen-should-contain [
. a.
.a .
]
]