This repository was archived by the owner on May 18, 2026. It is now read-only.
forked from scratchfoundation/scratch-gui
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathlooks.test.js
More file actions
127 lines (115 loc) · 4.71 KB
/
Copy pathlooks.test.js
File metadata and controls
127 lines (115 loc) · 4.71 KB
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
import RubyGenerator from '../../../../src/lib/ruby-generator';
import LooksBlocks from '../../../../src/lib/ruby-generator/looks';
describe('RubyGenerator/Looks', () => {
beforeEach(() => {
RubyGenerator.cache_ = {
comments: {},
targetCommentTexts: []
};
RubyGenerator.definitions_ = {};
RubyGenerator.functionNames_ = {};
RubyGenerator.currentTarget = null;
LooksBlocks(RubyGenerator);
});
describe('looks_say', () => {
test('normal say', () => {
const block = {
id: 'block-id',
opcode: 'looks_say',
inputs: {
MESSAGE: {}
}
};
RubyGenerator.valueToCode = jest.fn().mockReturnValue('"Hello!"');
const expected = 'say("Hello!")\n';
expect(RubyGenerator.looks_say(block)).toEqual(expected);
});
test('with @ruby:method:print', () => {
const block = {
id: 'block-id',
opcode: 'looks_say',
inputs: {
MESSAGE: {}
}
};
RubyGenerator.cache_.comments['block-id'] = { text: '@ruby:method:print' };
RubyGenerator.valueToCode = jest.fn().mockReturnValue('"Hello!"');
const expected = 'print("Hello!")\n';
expect(RubyGenerator.looks_say(block)).toEqual(expected);
});
test('with @ruby:method:puts', () => {
const block = {
id: 'block-id',
opcode: 'looks_say',
inputs: {
MESSAGE: {}
}
};
RubyGenerator.cache_.comments['block-id'] = { text: '@ruby:method:puts' };
RubyGenerator.valueToCode = jest.fn().mockReturnValue('"Hello!"');
const expected = 'puts("Hello!")\n';
expect(RubyGenerator.looks_say(block)).toEqual(expected);
});
test('with @ruby:method:p', () => {
const block = {
id: 'block-id',
opcode: 'looks_say',
inputs: {
MESSAGE: {}
}
};
RubyGenerator.cache_.comments['block-id'] = { text: '@ruby:method:p' };
RubyGenerator.valueToCode = jest.fn().mockReturnValue('"Hello!"');
const expected = 'p("Hello!")\n';
expect(RubyGenerator.looks_say(block)).toEqual(expected);
});
test('with unknown @ruby: tag defaults to say', () => {
const block = {
id: 'block-id',
opcode: 'looks_say',
inputs: {
MESSAGE: {}
}
};
RubyGenerator.cache_.comments['block-id'] = { text: '@ruby:unknown' };
RubyGenerator.valueToCode = jest.fn().mockReturnValue('"Hello!"');
const expected = 'say("Hello!")\n';
expect(RubyGenerator.looks_say(block)).toEqual(expected);
});
});
describe('scrub_ (meta-comment filtering)', () => {
test('should filter out @ruby: comments', () => {
const block = {
id: 'block-id',
opcode: 'looks_say',
inputs: {},
next: null
};
RubyGenerator.cache_.comments['block-id'] = { text: '@ruby:method:print' };
RubyGenerator.getInputs = jest.fn().mockReturnValue({});
RubyGenerator.isConnectedValue = jest.fn().mockReturnValue(false);
RubyGenerator.getBlock = jest.fn().mockReturnValue(null);
RubyGenerator.blockToCode = jest.fn().mockReturnValue('');
const code = 'print("Hello!")\n';
const result = RubyGenerator.scrub_(block, code);
// Should NOT contain the comment since it starts with @ruby:
expect(result).toEqual('print("Hello!")\n');
});
test('should keep normal comments', () => {
const block = {
id: 'block-id',
opcode: 'looks_say',
inputs: {},
next: null
};
RubyGenerator.cache_.comments['block-id'] = { text: 'normal comment' };
RubyGenerator.getInputs = jest.fn().mockReturnValue({});
RubyGenerator.isConnectedValue = jest.fn().mockReturnValue(false);
RubyGenerator.getBlock = jest.fn().mockReturnValue(null);
RubyGenerator.blockToCode = jest.fn().mockReturnValue('');
const code = 'say("Hello!")\n';
const result = RubyGenerator.scrub_(block, code);
expect(result).toEqual('# normal comment\nsay("Hello!")\n');
});
});
});