From 1d7849bba7b3b55be37aef712e3baa1dc8852a5e Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 22 Apr 2024 11:44:32 +0100 Subject: [PATCH 1/6] chore(developer): correct two test descriptions --- developer/src/kmc-kmn/test/test-messages.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/developer/src/kmc-kmn/test/test-messages.ts b/developer/src/kmc-kmn/test/test-messages.ts index e338cbe521f..d1792ffcd55 100644 --- a/developer/src/kmc-kmn/test/test-messages.ts +++ b/developer/src/kmc-kmn/test/test-messages.ts @@ -53,14 +53,14 @@ describe('KmnCompilerMessages', function () { // ERROR_DuplicateGroup - it('should generate CERR_DuplicateGroup if the kmn contains two groups with the same name', async function() { + it('should generate ERROR_DuplicateGroup if the kmn contains two groups with the same name', async function() { await testForMessage(this, ['invalid-keyboards', 'error_duplicate_group.kmn'], KmnCompilerMessages.ERROR_DuplicateGroup); assert.equal(callbacks.messages[0].message, "A group with this name has already been defined. Group 'ខ្មែរ' declared on line 9"); }); // ERROR_DuplicateStore - it('should generate CERR_DuplicateStore if the kmn contains two stores with the same name', async function() { + it('should generate ERROR_DuplicateStore if the kmn contains two stores with the same name', async function() { await testForMessage(this, ['invalid-keyboards', 'error_duplicate_store.kmn'], KmnCompilerMessages.ERROR_DuplicateStore); assert.equal(callbacks.messages[0].message, "A store with this name has already been defined. Store 'ខ្មែរ' declared on line 11"); }); From 5ec3589e07b748e5654e9ba2d067c743b156d962 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 22 Apr 2024 15:44:34 +0100 Subject: [PATCH 2/6] chore(developer): correct ERROR_OutsTooLong test following fix #11137 --- .../fixtures/invalid-keyboards/error_outs_too_long.kmn | 7 +++---- developer/src/kmc-kmn/test/test-messages.ts | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_outs_too_long.kmn b/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_outs_too_long.kmn index 750e45d3bad..76d68b97e85 100644 --- a/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_outs_too_long.kmn +++ b/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_outs_too_long.kmn @@ -7,12 +7,11 @@ group(main) using keys c maximum store length is 4096 UTF-16 code units, including U+0000 terminator c #define GLOBAL_BUFSIZE 4096 // compfile.h -c so we need 0x101C - 0x0020 + 1 = 0x0FFD --> 4093 words -c + 1, for 'a' in the rule below = 4094, which triggers the buffer boundary check. +c so we need 0x101D - 0x0020 + 1 = 0x0FFE --> 4094 words +c + 1, for 'a' in the rule below = 4095, which triggers the buffer boundary check. c Noting that this is conservative and losing 2 possible chars, but not fixing c in compiler.cpp at this time. -c See #11136 for calculation adjustment TODO -store(x) U+0020 .. U+101C +store(x) U+0020 .. U+101D 'a' outs(x) + 'x' > 'x' context diff --git a/developer/src/kmc-kmn/test/test-messages.ts b/developer/src/kmc-kmn/test/test-messages.ts index d1792ffcd55..9ffe617e70d 100644 --- a/developer/src/kmc-kmn/test/test-messages.ts +++ b/developer/src/kmc-kmn/test/test-messages.ts @@ -96,9 +96,9 @@ describe('KmnCompilerMessages', function () { // ERROR_OutsTooLong - it('should generate ERROR_OutsTooLong if a store referenced in outs() is too long (more than GLOBAL_BUFSIZE elements)', async function() { + it('should generate ERROR_OutsTooLong if a store referenced in outs() is too long and would overflow the buffer', async function() { await testForMessage(this, ['invalid-keyboards', 'error_outs_too_long.kmn'], KmnCompilerMessages.ERROR_OutsTooLong); - // callbacks.printMessages(); + assert.equal(callbacks.messages[0].message, "Store cannot be inserted with outs() as it makes the extended string too long character offset: 5"); }); // ERROR_ExtendedStringTooLong From 92fb9cded0ef7aa5a94c2e13f13ec215c4996b4f Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 22 Apr 2024 16:28:11 +0100 Subject: [PATCH 3/6] chore(developer): correct ERROR_ExtendedStringTooLong test following fix #11137 --- .../invalid-keyboards/error_extended_string_too_long.kmn | 3 +-- .../test/fixtures/invalid-keyboards/error_outs_too_long.kmn | 2 +- developer/src/kmc-kmn/test/test-messages.ts | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_extended_string_too_long.kmn b/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_extended_string_too_long.kmn index fcae6a5d758..18974124aa2 100644 --- a/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_extended_string_too_long.kmn +++ b/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_extended_string_too_long.kmn @@ -8,8 +8,7 @@ group(main) using keys c c maximum store length is 4096 UTF-16 code units, including U+0000 terminator c #define GLOBAL_BUFSIZE 4096 // compfile.h -c so we need 0x101B - 0x0020 + 1 = 0x0FFD --> 4092 words, + 4 = 4096 = too long -c See #11136 for calculation adjustment TODO +c so we need 0x101B - 0x0020 + 1 = 0x0FFC --> 4092 words, + 4 = 4096 = too long store(x) U+0020 .. U+101B diff --git a/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_outs_too_long.kmn b/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_outs_too_long.kmn index 76d68b97e85..cbd22204152 100644 --- a/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_outs_too_long.kmn +++ b/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_outs_too_long.kmn @@ -9,7 +9,7 @@ c maximum store length is 4096 UTF-16 code units, including U+0000 terminator c #define GLOBAL_BUFSIZE 4096 // compfile.h c so we need 0x101D - 0x0020 + 1 = 0x0FFE --> 4094 words c + 1, for 'a' in the rule below = 4095, which triggers the buffer boundary check. -c Noting that this is conservative and losing 2 possible chars, but not fixing +c Noting that this is conservative and losing 1 possible char, but not fixing c in compiler.cpp at this time. store(x) U+0020 .. U+101D diff --git a/developer/src/kmc-kmn/test/test-messages.ts b/developer/src/kmc-kmn/test/test-messages.ts index 9ffe617e70d..29e9222989e 100644 --- a/developer/src/kmc-kmn/test/test-messages.ts +++ b/developer/src/kmc-kmn/test/test-messages.ts @@ -103,9 +103,9 @@ describe('KmnCompilerMessages', function () { // ERROR_ExtendedStringTooLong - it('should generate ERROR_ExtendedStringTooLong if an extended string is too long (more than GLOBAL_BUFSIZE elements)', async function() { + it('should generate ERROR_ExtendedStringTooLong if an extended string is too long and would overflow the buffer', async function() { await testForMessage(this, ['invalid-keyboards', 'error_extended_string_too_long.kmn'], KmnCompilerMessages.ERROR_ExtendedStringTooLong); - // callbacks.printMessages(); + assert.equal(callbacks.messages[0].message, "Extended string is too long character offset: 9"); }); // ERROR_VirtualKeyExpansionTooLong From 5fcf92df32dea6871c36c01eb83e2021eafdcf42 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 22 Apr 2024 16:49:54 +0100 Subject: [PATCH 4/6] chore(developer): correct ERROR_VirtualKeyExpansionTooLong test following fix #11137 --- .../error_virtual_key_expansion_too_long.kmn | 9 ++++----- developer/src/kmc-kmn/test/test-messages.ts | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_virtual_key_expansion_too_long.kmn b/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_virtual_key_expansion_too_long.kmn index a617f294349..8646f65019a 100644 --- a/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_virtual_key_expansion_too_long.kmn +++ b/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_virtual_key_expansion_too_long.kmn @@ -7,11 +7,10 @@ group(main) using keys c maximum store length is 4096 UTF-16 code units, including U+0000 terminator c #define GLOBAL_BUFSIZE 4096 // compfile.h -c so we need 0x101E - 0x0020 + 1 = 0x0FFF --> 4095 words -c each vk is 5 words long UC_SENTINEL CODE_EXTENDED shift key CODE_EXTENDEDEND (some long history here!) -c we start filling the buffer with 4066 words and then the remaining 30 bytes = 6 VKs A-F -c See #11136 for calculation adjustment TODO +c so we need 0x101D - 0x0020 + 1 = 0x0FFE --> 4094 words +c each VK is 5 words long UC_SENTINEL CODE_EXTENDED shift key CODE_EXTENDEDEND (some long history here!) +c we start filling the buffer with 4064 words (0x0FFF - 0x0020 + 1) and then the remaining 30 bytes = 6 VKs A-F -store(x) U+0020 .. U+1000 [K_A] .. [K_F] +store(x) U+0020 .. U+0FFF [K_A] .. [K_F] any(x) + 'x' > 'x' context diff --git a/developer/src/kmc-kmn/test/test-messages.ts b/developer/src/kmc-kmn/test/test-messages.ts index 29e9222989e..dd105f9be79 100644 --- a/developer/src/kmc-kmn/test/test-messages.ts +++ b/developer/src/kmc-kmn/test/test-messages.ts @@ -110,9 +110,9 @@ describe('KmnCompilerMessages', function () { // ERROR_VirtualKeyExpansionTooLong - it('should generate ERROR_VirtualKeyExpansionTooLong if a virtual key expansion is too long (more than GLOBAL_BUFSIZE elements)', async function() { + it('should generate ERROR_VirtualKeyExpansionTooLong if a virtual key expansion is too long and would overflow the buffer', async function() { await testForMessage(this, ['invalid-keyboards', 'error_virtual_key_expansion_too_long.kmn'], KmnCompilerMessages.ERROR_VirtualKeyExpansionTooLong); - // callbacks.printMessages(); + assert.equal(callbacks.messages[0].message, "Virtual key expansion is too large"); }); // ERROR_CharacterRangeTooLong From 81c5ff4207f3d65c2b08fdc376ff49ecd0093903 Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 22 Apr 2024 17:04:40 +0100 Subject: [PATCH 5/6] chore(developer): correct ERROR_CharacterRangeTooLong test following fix #11137 --- .../invalid-keyboards/error_character_range_too_long.kmn | 1 - developer/src/kmc-kmn/test/test-messages.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_character_range_too_long.kmn b/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_character_range_too_long.kmn index e19e3ab9f87..8b8c0e402fd 100644 --- a/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_character_range_too_long.kmn +++ b/developer/src/kmc-kmn/test/fixtures/invalid-keyboards/error_character_range_too_long.kmn @@ -8,7 +8,6 @@ group(main) using keys c maximum store length is 4096 UTF-16 code units, including U+0000 terminator c #define GLOBAL_BUFSIZE 4096 // compfile.h c so we need 0x101E - 0x0020 + 1 = 0x0FFF --> 4095 words -c See #11136 for calculation adjustment TODO store(x) U+0020 .. U+101E diff --git a/developer/src/kmc-kmn/test/test-messages.ts b/developer/src/kmc-kmn/test/test-messages.ts index dd105f9be79..78f4870fafb 100644 --- a/developer/src/kmc-kmn/test/test-messages.ts +++ b/developer/src/kmc-kmn/test/test-messages.ts @@ -117,9 +117,9 @@ describe('KmnCompilerMessages', function () { // ERROR_CharacterRangeTooLong - it('should generate ERROR_CharacterRangeTooLong if a character range would expand to be too long (more than GLOBAL_BUFSIZE elements)', async function() { + it('should generate ERROR_CharacterRangeTooLong if a character range would expand to be too long and would overflow the buffer', async function() { await testForMessage(this, ['invalid-keyboards', 'error_character_range_too_long.kmn'], KmnCompilerMessages.ERROR_CharacterRangeTooLong); - // callbacks.printMessages(); + assert.equal(callbacks.messages[0].message, "Character range is too large and cannot be expanded"); }); }); From 23069398bf62aec95337d86f64f98719af7a4d9c Mon Sep 17 00:00:00 2001 From: "Dr Mark C. Sinclair" Date: Mon, 20 May 2024 10:28:13 +0100 Subject: [PATCH 6/6] chore(developer): remove all message text assertions --- developer/src/kmc-kmn/test/test-messages.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/developer/src/kmc-kmn/test/test-messages.ts b/developer/src/kmc-kmn/test/test-messages.ts index 78f4870fafb..1ba46033d8c 100644 --- a/developer/src/kmc-kmn/test/test-messages.ts +++ b/developer/src/kmc-kmn/test/test-messages.ts @@ -55,21 +55,18 @@ describe('KmnCompilerMessages', function () { it('should generate ERROR_DuplicateGroup if the kmn contains two groups with the same name', async function() { await testForMessage(this, ['invalid-keyboards', 'error_duplicate_group.kmn'], KmnCompilerMessages.ERROR_DuplicateGroup); - assert.equal(callbacks.messages[0].message, "A group with this name has already been defined. Group 'ខ្មែរ' declared on line 9"); }); // ERROR_DuplicateStore it('should generate ERROR_DuplicateStore if the kmn contains two stores with the same name', async function() { await testForMessage(this, ['invalid-keyboards', 'error_duplicate_store.kmn'], KmnCompilerMessages.ERROR_DuplicateStore); - assert.equal(callbacks.messages[0].message, "A store with this name has already been defined. Store 'ខ្មែរ' declared on line 11"); }); // ERROR_VirtualKeyInContext it('should generate ERROR_VirtualKeyInContext if a virtual key is found in the context part of a rule', async function() { await testForMessage(this, ['invalid-keyboards', 'error_virtual_key_in_context.kmn'], KmnCompilerMessages.ERROR_VirtualKeyInContext); - assert.equal(callbacks.messages[0].message, "Virtual keys are not permitted in context"); }); // WARN_TouchLayoutUnidentifiedKey @@ -77,49 +74,42 @@ describe('KmnCompilerMessages', function () { it('should generate WARN_TouchLayoutUnidentifiedKey if a key has no identifier in the touch layout', async function() { await testForMessage(this, ['invalid-keyboards', 'warn_touch_layout_unidentified_key.kmn'], KmnCompilerMessages.WARN_TouchLayoutUnidentifiedKey); // TODO(lowpri): that message could be slightly more helpful! - assert.equal(callbacks.messages[0].message, "A key on layer \"default\" has no identifier."); }); // ERROR_NotSupportedInKeymanWebOutput it('should generate ERROR_NotSupportedInKeymanWebOutput if a rule has `return` in the output', async function() { await testForMessage(this, ['invalid-keyboards', 'error_not_supported_in_keyman_web_output.kmn'], KmnCompilerMessages.ERROR_NotSupportedInKeymanWebOutput); - assert.equal(callbacks.messages[0].message, "Statement 'return' is not currently supported in output for web and touch targets"); }); // WARN_VirtualKeyInOutput it('should generate WARN_VirtualKeyInOutput if a virtual key is found in the output part of a rule', async function() { await testForMessage(this, ['invalid-keyboards', 'warn_virtual_key_in_output.kmn'], KmnCompilerMessages.WARN_VirtualKeyInOutput); - assert.equal(callbacks.messages[0].message, "Virtual keys are not supported in output"); }); // ERROR_OutsTooLong it('should generate ERROR_OutsTooLong if a store referenced in outs() is too long and would overflow the buffer', async function() { await testForMessage(this, ['invalid-keyboards', 'error_outs_too_long.kmn'], KmnCompilerMessages.ERROR_OutsTooLong); - assert.equal(callbacks.messages[0].message, "Store cannot be inserted with outs() as it makes the extended string too long character offset: 5"); }); // ERROR_ExtendedStringTooLong it('should generate ERROR_ExtendedStringTooLong if an extended string is too long and would overflow the buffer', async function() { await testForMessage(this, ['invalid-keyboards', 'error_extended_string_too_long.kmn'], KmnCompilerMessages.ERROR_ExtendedStringTooLong); - assert.equal(callbacks.messages[0].message, "Extended string is too long character offset: 9"); }); // ERROR_VirtualKeyExpansionTooLong it('should generate ERROR_VirtualKeyExpansionTooLong if a virtual key expansion is too long and would overflow the buffer', async function() { await testForMessage(this, ['invalid-keyboards', 'error_virtual_key_expansion_too_long.kmn'], KmnCompilerMessages.ERROR_VirtualKeyExpansionTooLong); - assert.equal(callbacks.messages[0].message, "Virtual key expansion is too large"); }); // ERROR_CharacterRangeTooLong it('should generate ERROR_CharacterRangeTooLong if a character range would expand to be too long and would overflow the buffer', async function() { await testForMessage(this, ['invalid-keyboards', 'error_character_range_too_long.kmn'], KmnCompilerMessages.ERROR_CharacterRangeTooLong); - assert.equal(callbacks.messages[0].message, "Character range is too large and cannot be expanded"); }); });