author | Alan Dipert
<alan@dipert.org> 2020-08-14 14:47:26 UTC |
committer | Alan Dipert
<alan@dipert.org> 2020-08-14 14:47:26 UTC |
parent | 7f664f8f7138f7cb53a6bfdd96b5135237639c81 |
jacl-tests.js | +0 | -152 |
diff --git a/jacl-tests.js b/jacl-tests.js deleted file mode 100644 index 7e15431..0000000 --- a/jacl-tests.js +++ /dev/null @@ -1,152 +0,0 @@ -QUnit.config.testTimeout = 100; // milliseconds -QUnit.config.autostart = false; - -QUnit.module('Reader'); - -const read1 = async s => { - return (new Reader(new StringStream(s))).read(); -} - -QUnit.test('Integers', async is => { - is.strictEqual(await read1('123 '), 123, 'single integer'); - is.strictEqual(await read1('+9912 '), 9912, 'integer with leading +'); - is.strictEqual(await read1('0 '), 0, 'zero'); - is.strictEqual(await read1('-32 '), -32, 'negative number'); - is.strictEqual(await read1('1. '), 1, 'number with trailing dot'); -}); - -QUnit.test('Symbols', async is => { - var sym; - - sym = await read1('somesym '); - is.strictEqual(sym.name, 'SOMESYM', 'simple symbol name'); - is.strictEqual(sym.packageName, 'COMMON-LISP-USER', 'simple symbol package'); - - sym = await read1('|Alan| '); - is.strictEqual(sym.name, 'Alan', 'simple symbol name'); - - sym = await read1(String.raw`\alan `); - is.strictEqual(sym.name, 'aLAN', 'simple symbol with escape'); - - const testPkg1 = Package.makePackage('TEST-PACKAGE1'), - plusOne = testPkg1.intern("1+"); - - testPkg1.exportSymbol("1+"); - sym = await read1('test-package1:1+ '); - is.strictEqual(sym.name, '1+', 'exported symbol'); - is.strictEqual(sym.packageName, 'TEST-PACKAGE1', 'exported symbol'); - - is.rejects( - read1('test-package1:omg ', false), - /Symbol 'OMG' not found in package 'TEST-PACKAGE1'/, - 'non-existent symbol not found' - ); - - testPkg1.intern("some symbol") - sym = await read1('|TEST-PACKAGE1::some symbol| '); - is.strictEqual(sym.name, 'TEST-PACKAGE1::some symbol', 'pipe/qualified symbol'); - is.strictEqual(sym.packageName, 'COMMON-LISP-USER', 'pipe/qualified symbol'); - - sym = await read1('test-package1::|some symbol| '); - is.strictEqual(sym.name, 'some symbol', 'pipe/qualified symbol'); - is.strictEqual(sym.packageName, 'TEST-PACKAGE1', 'pipe/qualified symbol'); - - sym = await read1('test-package1::another-symbol '); - is.strictEqual(sym.name, 'ANOTHER-SYMBOL', 'symbol created externally'); - is.strictEqual(sym.packageName, 'TEST-PACKAGE1', 'symbol created externally'); - - sym = await read1("test-package1|::lol| "); - is.strictEqual(sym.name, 'TEST-PACKAGE1::lol', 'pipe without package'); - is.strictEqual(sym.packageName, 'COMMON-LISP-USER', 'pipe without package has default package'); - - is.rejects( - read1('test-package1:|some symbol| ', false), - /Symbol 'some symbol' not external in package 'TEST-PACKAGE1'/, - 'private symbol reference throws' - ); - - is.rejects( - read1('test-package1:sym123 ', false), - /Symbol 'SYM123' not found in package 'TEST-PACKAGE1'/, - 'non-existent qualified symbol throws' - ); - - 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 => { - var sym; - - sym = await read1('#:foop '); - is.strictEqual(sym.name, 'FOOP', 'uninterned sym has a name'); - is.strictEqual(sym.packageName, null, 'uninterned packageName is null'); - - sym = await read1("#'foop "); - is.ok(sym instanceof Cons, "#' makes a cons"); -}); - -QUnit.test('Conses', async is => { - var cons; - - cons = await read1('()'); - is.strictEqual(cons, null, 'nil'); - - cons = await read1('(1)'); - is.strictEqual(cons.car, 1, 'car of cons'); - is.strictEqual(cons.cdr, null, 'cdr of cons'); - - cons = await read1('(1 . 2)'); - is.strictEqual(cons.car, 1, 'car of dot cons'); - is.strictEqual(cons.cdr, 2, 'cdr of dot cons'); - - is.rejects( - read1('(1 . )', false), - /Nothing after . in list/, - 'nothing after dot' - ); - - is.rejects( - read1('( . t)', false), - /Nothing before . in list/, - 'nothing before dot' - ); - - is.rejects( - read1('(1 . 2 3)', false), - /More than one object after . in list/, - 'more than one object after dot' - ); - - cons = await read1('(1 2 3 4)'); - is.deepEqual(Array.from(cons), [1,2,3,4], 'convert to array'); - - cons = await read1('(1 . 2)'); - is.deepEqual(Array.from(cons), [1,2], 'convert to pair'); - - cons = await read1('((((x . y))))'); - is.strictEqual(cons.car.car.car.car.name, 'X', 'very deep pair'); - is.strictEqual(cons.car.car.car.cdr.name, 'Y', 'very deep pair'); -});