feat: add getVariableName and getProcedureName to CodeGenerator (#7445)

* feat: add getVariableName and getProcedureName to CodeGenerator

* feat: make nameDB_ public

* feat: update block code generators to use new APIs

* chore: fix build

* chore: remove unused imports
This commit is contained in:
Maribeth Bottorff
2023-08-31 10:49:17 -07:00
committed by GitHub
parent b0a7c004a9
commit 68261e5dd9
28 changed files with 122 additions and 109 deletions

View File

@@ -190,5 +190,36 @@ suite('Generator', function () {
});
});
});
suite('Names', function () {
setup(function () {
class TestGenerator extends Blockly.CodeGenerator {
init() {
super.init();
this.nameDB_ = sinon.createStubInstance(Blockly.Names, {
getName: 'foo',
});
}
}
this.generator = new TestGenerator();
});
test('No nameDB_ initialized', function () {
chai.assert.throws(() => {
this.generator.getVariableName('foo');
});
});
test('Get variable name', function () {
this.generator.init();
chai.assert.equal(this.generator.getVariableName('foo'), 'foo');
});
test('Get procedure name', function () {
this.generator.init();
chai.assert.equal(this.generator.getProcedureName('foo'), 'foo');
});
});
});
});