feat(developer): support normalization=disabled 🙀

- additional test changes
- turn off cooking the 'from' if disabled

#10554
This commit is contained in:
Steven R. Loomis 2024-02-01 15:19:19 -06:00
parent d77ed9099b
commit eaeb3e4284
3 changed files with 78 additions and 3 deletions

View file

@ -141,8 +141,10 @@ export abstract class TransformCompiler<T extends TransformCompilerType, TranBas
// don't unescape literals here, because we are going to pass them through into the regex
cookedFrom = util.unescapeStringToRegex(cookedFrom);
// nfd here.
cookedFrom = MarkerParser.nfd_markers(cookedFrom, true);
if (!sections.meta.normalizionDisabled) {
// nfd here.
cookedFrom = MarkerParser.nfd_markers(cookedFrom, true);
}
// cookedFrom is cooked above, since there's some special treatment
result.from = sections.strs.allocString(cookedFrom, {

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard3 SYSTEM "../../../../../../../resources/standards-data/ldml-keyboards/techpreview/dtd/ldmlKeyboard3.dtd">
<keyboard3 locale="mt" conformsTo="techpreview">
<info name="tran-vars"/>
<settings normalization="disabled" />
<keys />
<variables>
<string id="y" value="yes" /> <!-- a simple string-->
<string id="n" value="no" /> <!-- a simple string-->
<set id="upper" value="A B C D FF E" /> <!-- a set with 6 items. Purposely out of order.-->
<set id="lower" value="a b c d ƒ ƒ" /> <!-- a set with 6 items. Purposely out of order and with a dup.-->
<unicodeSet id="alpha" value="[a-z]" />
<unicodeSet id="vowels" value="[aeiou]" />
<unicodeSet id="consonants" value="[$[alpha]-$[vowels]]" />
</variables>
<transforms type="simple">
<transformGroup>
<transform from="${y}" to="${n}"/> <!-- g0t0 -->
<transform from="q$[upper]x"/> <!-- g0t1 -->
<transform from="$[consonants]"/> <!-- g0t2 -->
<transform from="($[upper])" to="$[1:lower]"/> <!-- g0t3 -->
<transform from="ι\m{a}\u{0344}" to="ἴ"/> <!-- g0t4: \u{03b9}\m{1}\u{0309}\u{0301} => \u{03b9}\u{0313}\u{0301} (\u1f34) -->
<transform from="ί\m{.}\u{033c}" to="ὶ\m{a}\u{033c}"/> <!-- g0t5 \u{03b9}\u{033c}\m{.}\u{0301} -->
</transformGroup>
</transforms>
</keyboard3>

View file

@ -9,7 +9,7 @@ import { KMXPlus, MarkerParser } from '@keymanapp/common-types';
import Tran = KMXPlus.Tran;// for tests…
import Bksp = KMXPlus.Bksp;// for tests…
import { constants } from '@keymanapp/ldml-keyboard-constants';
import { MetaCompiler } from './compiler/meta.js';
import { MetaCompiler } from '../src/compiler/meta.js';
const tranDependencies = [ ...BASIC_DEPENDENCIES, UsetCompiler, MetaCompiler ];
const bkspDependencies = tranDependencies;
@ -80,6 +80,48 @@ describe('tran', function () {
}
},
{
subpath: 'sections/tran/tran-vars-nfc.xml',
callback(sect) {
const m = MarkerParser.markerOutput;
const tran = <Tran> sect;
assert.ok(tran);
assert.lengthOf(compilerTestCallbacks.messages, 0);
// cautiously destructure
assert.lengthOf(tran.groups, 1);
const [ g0 ] = tran.groups;
assert.lengthOf(g0.transforms, 6);
const [ g0t0, g0t1, g0t2, g0t3, g0t4, g0t5 ] = g0.transforms;
assert.strictEqual(g0t0.from.value, "yes");
assert.strictEqual(g0t0.to.value, "no");
assert.strictEqual(g0t1.from.value, "q(?:A|B|C|D|FF|E)x");
const g0t1r = new RegExp(g0t1.from.value);
assert.ok(g0t1r.test('qFFx'));
assert.notOk(g0t1r.test('qZZx'));
assert.strictEqual(g0t2.from.value, "[b-df-hj-np-tv-z]");
const g0t2r = new RegExp(g0t2.from.value);
assert.ok(g0t2r.test('k'));
assert.notOk(g0t2r.test('e'));
assert.strictEqual(g0t3.from.value, "((?:A|B|C|D|FF|E))");
assert.equal(g0t3.mapFrom?.value, "upper");
assert.equal(g0t3.mapTo?.value, "lower");
assertCodePoints(g0t4.from.value,
`\u{03b9}${m(1, true)}\u{0344}`);
assertCodePoints(g0t4.to.value,
`\u{1f34}`);
assertCodePoints(g0t5.from.value,
`\u{03af}${MarkerParser.ANY_MARKER_MATCH}\u{033c}`);
assertCodePoints(g0t5.to.value,
`\u{1f76}${m(1,false)}\u{033c}`);
},
warnings: [
CompilerMessages.Hint_NormalizationDisabled()
],
}, {
subpath: 'sections/tran/fail-invalid-type.xml',
errors: true, // XML error
},