-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-hello-world-feature.js
159 lines (143 loc) · 10.6 KB
/
2-hello-world-feature.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import { run } from "../../app.js";
import { fakeStdin, fakeStdout } from "../helpers/fake-process.js";
Feature("Hello World", () => {
Scenario("Hello World without loops and without changing the data pointer", () => {
let stdout, stdin;
Given("we have a fake stdout and stdin", () => {
stdout = fakeStdout();
stdin = fakeStdin();
});
When("Running the hello world program without a loop", async () => {
const program = `
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++. set (cell #0) to 72 (H) and print it
+++++++++++++++++++++++++++++. set (cell #0) to 101 (e) and print it
+++++++.. set (cell #0) to 108 (l) and print it twice
+++. set (cell #0) to 111 (o) and print it
-------------------------------------------------------------------------------. set (cell #0) to 32 (space) and print it
+++++++++++++++++++++++++++++++++++++++++++++++++++++++. set (cell #0) to 87 (W) and print it
++++++++++++++++++++++++. set (cell #0) to 111 (o) and print it
+++. set (cell #0) to 114 (r) and print it
------. set (cell #0) to 108 (l) and print it
--------. set (cell #0) to 100 (d) and print it
-------------------------------------------------------------------. set (cell #0) to 33 (!) and print it
-----------------------. set (cell #0) to 10 (newline) and print it
`;
await run(program, stdin, stdout);
});
Then("The output should be 'Hello World!' with a newline", () => {
expect(stdout.getData()).to.eql("Hello World!\n");
});
});
Scenario("Hello World without loops but with a changing data pointer", () => {
let stdout, stdin;
Given("we have a fake stdout and stdin", () => {
stdout = fakeStdout();
stdin = fakeStdin();
});
When("Running the hello world program without a loop but with a changing data pointer", async () => {
const program = `
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ set (cell #0) to 72 (H)
> move to cell #1
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ set (cell #1) to 101 (e)
> move to cell #2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ set (cell #2) to 108 (l)
> move to cell #3
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ set (cell #3) to 111 (o)
> move to cell #4
++++++++++++++++++++++++++++++++ set (cell #4) to 32 (space)
> move to cell #5
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ set (cell #5) to 87 (W)
> move to cell #6
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ set (cell #6) to 111 (o)
> move to cell #7
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ set (cell #7) to 114 (r)
> move to cell #8
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ set (cell #8) to 108 (l)
> move to cell #9
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ set (cell #9) to 100 (d)
> move to cell #10
+++++++++++++++++++++++++++++++++ set (cell #10) to 33 (!)
> move to cell #11
++++++++++ set (cell #11) to 10 (newline)
<<<<<<<<<<< move back to cell #0
. print cell #0
> move to cell #1
. print cell #1
> move to cell #2
.. print cell #2 twice
> move to cell #3
. print cell #3
> move to cell #4
. print cell #4
> move to cell #5
. print cell #5
> move to cell #6
. print cell #6
> move to cell #7
. print cell #7
> move to cell #8
. print cell #8
> move to cell #9
. print cell #9
> move to cell #10
. print cell #10
> move to cell #11
. print cell #11
`;
await run(program, stdin, stdout);
});
Then("The output should be 'Hello World!' with a newline", () => {
expect(stdout.getData()).to.eql("Hello World!\n");
});
});
Scenario("Hello World with a loop", () => {
let stdout, stdin;
Given("we have a fake stdout and stdin", () => {
stdout = fakeStdout();
stdin = fakeStdin();
});
When("Running the hello world program with a loop", async () => {
const program = `
+++++ +++++ initialize counter (cell #0) to 10
[ use loop to set the next four cells to
70/100/30/10
> +++++ ++ add 7 to cell #1
> +++++ +++++ add 10 to cell #2
> +++ add 3 to cell #3
> + add 1 to cell #4
<<<< - decrement counter (cell #0)
]
> ++ . print 'H'
> + . print 'e'
+++++ ++ . print 'l'
. print 'l'
+++ . print 'o'
> ++ . print ' '
<< +++++ +++++ +++++ . print 'W'
> . print 'o'
+++ . print 'r'
----- - . print 'l'
----- --- . print 'd'
> + . print '!'
> . print '\n'`;
await run(program, stdin, stdout);
});
Then("The output should be 'Hello World!' with a newline", () => {
expect(stdout.getData()).to.eql("Hello World!\n");
});
});
Scenario("Hello World with nested loops", () => {
let stdout, stdin;
Given("we have a fake stdout and stdin", () => {
stdout = fakeStdout();
stdin = fakeStdin();
});
When("Running the hello world program with nested loops", async () => {
const program = "++++++++**[**>++++**[**>++>+++>+++>+<<<<-**]**>+>+>->>+**[**<**]**<-**]**>>**.**>---**.**+++++++**..**+++**.**>>**.**<-**.**<**.**+++**.**------**.**--------**.**>>+**.**>++**.**";
await run(program, stdin, stdout);
});
Then("The output should be 'Hello World!' with a newline", () => {
expect(stdout.getData()).to.eql("Hello World!\n");
});
});
});