author | Alan Dipert
<alan@dipert.org> 2019-09-06 07:03:23 UTC |
committer | Alan Dipert
<alan@dipert.org> 2019-09-06 07:03:23 UTC |
parent | 0817703b23e4f47f9f9682c846a6517987b165d8 |
jacl-tests.js | +33 | -12 |
jacl.js | +4 | -1 |
diff --git a/jacl-tests.js b/jacl-tests.js index b2f0521..8b274f7 100644 --- a/jacl-tests.js +++ b/jacl-tests.js @@ -41,29 +41,29 @@ QUnit.test('Symbols', async is => { sym = await read1(String.raw`\alan `); is.strictEqual(sym.name, 'aLAN', 'simple symbol with escape'); - const testPkg = Package.makePackage('TEST-PACKAGE'), - plusOne = testPkg.intern("1+"); + const testPkg1 = Package.makePackage('TEST-PACKAGE1'), + plusOne = testPkg1.intern("1+"); - testPkg.exportSymbol("1+"); - sym = await read1('test-package:1+ '); + testPkg1.exportSymbol("1+"); + sym = await read1('test-package1:1+ '); is.strictEqual(sym.name, '1+', 'exported symbol'); - is.strictEqual(sym.packageName, 'TEST-PACKAGE', 'exported symbol'); + is.strictEqual(sym.packageName, 'TEST-PACKAGE1', 'exported symbol'); is.rejects( - read1('test-package:omg ', false), - /Symbol 'OMG' not found in package 'TEST-PACKAGE'/, + read1('test-package1:omg ', false), + /Symbol 'OMG' not found in package 'TEST-PACKAGE1'/, 'non-existent symbol not found' ); [rdr, read1] = freshRdr(is); - testPkg.intern("some symbol") - sym = await read1('|TEST-PACKAGE::some symbol| '); + testPkg1.intern("some symbol") + sym = await read1('|TEST-PACKAGE1::some symbol| '); is.strictEqual(sym.name, 'some symbol', 'pipe/qualified symbol'); - is.strictEqual(sym.packageName, 'TEST-PACKAGE', 'pipe/qualified symbol'); + is.strictEqual(sym.packageName, 'TEST-PACKAGE1', 'pipe/qualified symbol'); is.rejects( - read1('|TEST-PACKAGE:some symbol| ', false), - /Symbol 'some symbol' not external in package 'TEST-PACKAGE'/, + read1('|TEST-PACKAGE1:some symbol| ', false), + /Symbol 'some symbol' not external in package 'TEST-PACKAGE1'/, 'private symbol reference throws' ); [rdr, read1] = freshRdr(is); @@ -71,6 +71,27 @@ QUnit.test('Symbols', async is => { sym = await read1(':some-lil-kw '); is.strictEqual(sym.name, 'SOME-LIL-KW', 'kw name'); is.strictEqual(sym.packageName, 'KEYWORD', 'kw package'); + + const testPkg2 = Package.makePackage('TEST-PACKAGE2'); + + testPkg2.usePackage(testPkg1); + + var symStatus = testPkg2.findSymbol('1+'); + is.strictEqual(symStatus[0].name, '1+', 'inherited kw name'); + is.strictEqual(symStatus[0].packageName, 'TEST-PACKAGE1', 'inherited kw package'); + is.strictEqual(symStatus[1].name, 'INHERITED'); + is.strictEqual(symStatus[1].packageName, 'KEYWORD'); + + testPkg2.intern('INTERNAL-SYM'); + testPkg2.intern('EXTERNAL-SYM'); + + testPkg2.exportSymbol('EXTERNAL-SYM'); + + symStatus = testPkg2.findSymbol('INTERNAL-SYM'); + is.strictEqual(symStatus[1].name, 'INTERNAL'); + + symStatus = testPkg2.findSymbol('EXTERNAL-SYM'); + is.strictEqual(symStatus[1].name, 'EXTERNAL'); }); QUnit.test('Sharpsign', async is => { diff --git a/jacl.js b/jacl.js index aeecad8..b4d38dd 100644 --- a/jacl.js +++ b/jacl.js @@ -165,6 +165,9 @@ class Package { if (this.name === 'KEYWORD') this.exports.add(name); return sym; } + usePackage(otherPackage) { + this.use.push(otherPackage); + } exportSymbol(name) { this.exports.add(name); } @@ -189,7 +192,7 @@ class Package { ); } - for (const usedPkg in this.use) { + for (const usedPkg of this.use) { if (usedPkg.isExported(name)) { return new Values( usedPkg.symbols.get(name),