From 3e417fa4c42dbaf39ca90cadbdcb43c2beecbbd7 Mon Sep 17 00:00:00 2001 From: jahorton Date: Fri, 1 May 2020 12:32:43 +0700 Subject: [PATCH] feat(web/engine): basic store explosion test relocated --- .../src/text/kbdInterface.ts | 2 +- common/core/web/keyboard-processor/test.sh | 2 +- .../tests/cases/engine/stores.js | 49 +++++++++++++++++++ web/unit_tests/cases/engine.js | 24 --------- 4 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 common/core/web/keyboard-processor/tests/cases/engine/stores.js diff --git a/common/core/web/keyboard-processor/src/text/kbdInterface.ts b/common/core/web/keyboard-processor/src/text/kbdInterface.ts index aee5ef26c3..b7b5695a0f 100644 --- a/common/core/web/keyboard-processor/src/text/kbdInterface.ts +++ b/common/core/web/keyboard-processor/src/text/kbdInterface.ts @@ -184,7 +184,7 @@ namespace com.keyman.text { _AnyIndices: number[] = []; // AnyIndex - array of any/index match indices // Must be accessible to some of the keyboard API methods. - activeKeyboard: any; + activeKeyboard: keyboards.Keyboard; activeDevice: EngineDeviceSpec; variableStoreSerializer?: VariableStoreSerializer; diff --git a/common/core/web/keyboard-processor/test.sh b/common/core/web/keyboard-processor/test.sh index 71cbeb047a..13b651fd03 100755 --- a/common/core/web/keyboard-processor/test.sh +++ b/common/core/web/keyboard-processor/test.sh @@ -54,7 +54,7 @@ test-headless ( ) { FLAGS="$FLAGS --reporter mocha-teamcity-reporter" fi - npm run mocha -- --recursive $FLAGS ./tests/cases/*.js + npm run mocha -- --recursive $FLAGS ./tests/cases/ } # Build test dependency diff --git a/common/core/web/keyboard-processor/tests/cases/engine/stores.js b/common/core/web/keyboard-processor/tests/cases/engine/stores.js new file mode 100644 index 0000000000..66f0a57b20 --- /dev/null +++ b/common/core/web/keyboard-processor/tests/cases/engine/stores.js @@ -0,0 +1,49 @@ +var assert = require('chai').assert; +let fs = require('fs'); +let vm = require('vm'); + +let KeyboardProcessor = require('../../../dist'); +let KMWRecorder = require('../../../../tools/recorder/dist/nodeProctor'); + +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. + +describe('Engine - Stores', function() { + var toSupplementaryPairString = function(code){ + var H = Math.floor((code - 0x10000) / 0x400) + 0xD800; + var L = (code - 0x10000) % 0x400 + 0xDC00; + + return String.fromCharCode(H, L); + } + + it('Store \'Explosion\'', function() { + let processor = new KeyboardProcessor(); + // A 'hollow' Keyboard that only follows default rules. That said, we need a Keyboard + // instance to host cache data for our exploded store tests. + processor.activeKeyboard = new com.keyman.keyboards.Keyboard(); + + // Function defined at top of file; creates supplementary pairs for extended Unicode codepoints. + var u = toSupplementaryPairString; + + var STORES = [ + {smp: false, in: "apple", out: ['a','p','p','l','e']}, + //In JS-escaped form: "\\ud804\\udd12\\ud804\\udd0d\\ud804\\udd0f\\ud804\\udd10\\ud804\\udd0a\\ud804\\udd05" + //(Supplementary pairs, copied from the easy_chakma keyboard.) + {smp: true, in: "𑄒𑄍𑄏𑄐𑄊𑄅", out: ["𑄒","𑄍","𑄏","𑄐","𑄊","𑄅"]}, + // Built in-line via function. Looks functionally equivalent to "apple", but with SMP characters. + {smp: true, in: (u(0x1d5ba)+u(0x1d5c9)+u(0x1d5c9)+u(0x1d5c5)+u(0x1d5be)), + out: [u(0x1d5ba), u(0x1d5c9), u(0x1d5c9), u(0x1d5c5), u(0x1d5be)]} + ]; + + for(var i=0; i < STORES.length; i++) { + var s = STORES[i]; + + String.kmwEnableSupplementaryPlane(s.smp); + var result = processor.keyboardInterface._ExplodeStore(s.in); + assert.sameOrderedMembers(result, s.out, "Failure exploding " + (s.smp ? "SMP" : "non-SMP") + " string value \"" + s.in + "\""); + } + String.kmwEnableSupplementaryPlane(false); + }); + + // TODO: Migrate a Node-based copy of the variable store tests here as well. +}); \ No newline at end of file diff --git a/web/unit_tests/cases/engine.js b/web/unit_tests/cases/engine.js index b4cfb23149..acca58376a 100644 --- a/web/unit_tests/cases/engine.js +++ b/web/unit_tests/cases/engine.js @@ -789,30 +789,6 @@ describe('Engine', function() { fixture.cleanup(); }); - it('Store \'Explosion\'', function() { - // Function defined at top of file; creates supplementary pairs for extended Unicode codepoints. - var u = toSupplementaryPairString; - - var STORES = [ - {smp: false, in: "apple", out: ['a','p','p','l','e']}, - //In JS-escaped form: "\\ud804\\udd12\\ud804\\udd0d\\ud804\\udd0f\\ud804\\udd10\\ud804\\udd0a\\ud804\\udd05" - //(Supplementary pairs, copied from the easy_chakma keyboard.) - {smp: true, in: "𑄒𑄍𑄏𑄐𑄊𑄅", out: ["𑄒","𑄍","𑄏","𑄐","𑄊","𑄅"]}, - // Built in-line via function. Looks functionally equivalent to "apple", but with SMP characters. - {smp: true, in: (u(0x1d5ba)+u(0x1d5c9)+u(0x1d5c9)+u(0x1d5c5)+u(0x1d5be)), - out: [u(0x1d5ba), u(0x1d5c9), u(0x1d5c9), u(0x1d5c5), u(0x1d5be)]} - ]; - - for(var i=0; i < STORES.length; i++) { - var s = STORES[i]; - - String.kmwEnableSupplementaryPlane(s.smp); - var result = keyman.core.keyboardInterface._ExplodeStore(s.in); - assert.sameOrderedMembers(result, s.out, "Failure exploding " + (s.smp ? "SMP" : "non-SMP") + " string value \"" + s.in + "\""); - } - String.kmwEnableSupplementaryPlane(false); - }); - // Tests "stage 1" of fullContextMatch - ensuring that a proper context index map is built. it('Extended Context Mapping', function() { var inputElem = document.getElementById('singleton');