Skip to content

Commit

Permalink
Merge pull request #9835 from keymanapp/fix/common/models/prediction-…
Browse files Browse the repository at this point in the history
…test-mode-use

fix(web): proper disabling of prediction timeout for prediction unit tests
  • Loading branch information
jahorton authored Oct 24, 2023
2 parents 42f826d + 5ba60e9 commit a75cd6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Custom Punctuation', function () {

// The model compositor is responsible for adding this to the display as
// string.
var composite = new ModelCompositor(model);
var composite = new ModelCompositor(model, true);
var suggestions = composite.predict([{ sample: { insert: 'o', deleteLeft: 0 }, p: 1.00 }], {
left: 'Hrll', startOfBuffer: false, endOfBuffer: true
});
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('Custom Punctuation', function () {

// The model compositor is responsible for adding this to the display as
// string.
var composite = new ModelCompositor(model);
var composite = new ModelCompositor(model, true);
var suggestions = composite.predict([{ sample: { insert: 'ᚋ', deleteLeft: 0 }, p: 1.00 }], {
left: '᚛ᚈᚑ', startOfBuffer: false, endOfBuffer: true
});
Expand Down
44 changes: 22 additions & 22 deletions common/web/lm-worker/src/test/cases/worker-model-compositor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('ModelCompositor', function() {
);

it('generates suggestions with expected properties', function() {
let compositor = new ModelCompositor(plainModel);
let compositor = new ModelCompositor(plainModel, true);
let context = {
left: 'th', startOfBuffer: true, endOfBuffer: true,
};
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('ModelCompositor', function() {
});

it('strongly avoids corrections for single-character roots', function() {
let compositor = new ModelCompositor(plainModel);
let compositor = new ModelCompositor(plainModel, true);
let context = {
left: '', startOfBuffer: true, endOfBuffer: true,
};
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('ModelCompositor', function() {
});

it('properly handles suggestions after a backspace', function() {
let compositor = new ModelCompositor(plainModel);
let compositor = new ModelCompositor(plainModel, true);
let context = {
left: 'the ', startOfBuffer: true, endOfBuffer: true,
};
Expand All @@ -118,7 +118,7 @@ describe('ModelCompositor', function() {
});

it('properly handles suggestions for the first letter after a ` `', function() {
let compositor = new ModelCompositor(plainModel);
let compositor = new ModelCompositor(plainModel, true);
let context = {
left: 'the', startOfBuffer: true, endOfBuffer: true,
};
Expand All @@ -137,7 +137,7 @@ describe('ModelCompositor', function() {
});

it('properly handles suggestions for the first letter after a `\'`', function() {
let compositor = new ModelCompositor(plainModel);
let compositor = new ModelCompositor(plainModel, true);
let context = {
left: "the '", startOfBuffer: true, endOfBuffer: true,
};
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('ModelCompositor', function() {
);

it('properly cases suggestions with no suggestion root', function() {
var compositor = new ModelCompositor(plainCasedModel);
var compositor = new ModelCompositor(plainCasedModel, true);

let suggestion = {
transform: {
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('ModelCompositor', function() {
});

it('properly cases suggestions that fully replace the suggestion root', function() {
var compositor = new ModelCompositor(plainCasedModel);
var compositor = new ModelCompositor(plainCasedModel, true);

let suggestion = {
transform: {
Expand Down Expand Up @@ -266,7 +266,7 @@ describe('ModelCompositor', function() {
});

it('properly cases suggestions that do not fully replace the suggestion root', function() {
var compositor = new ModelCompositor(plainCasedModel);
var compositor = new ModelCompositor(plainCasedModel, true);

let suggestion = {
transform: {
Expand Down Expand Up @@ -322,7 +322,7 @@ describe('ModelCompositor', function() {

it('should produce suggestions from uncased input', function() {
let model = uncasedModel;
var composite = new ModelCompositor(model);
var composite = new ModelCompositor(model, true);

// Initialize context
let context = {
Expand Down Expand Up @@ -350,7 +350,7 @@ describe('ModelCompositor', function() {

it('should not produce suggestions from cased input', function() {
let model = uncasedModel;
var composite = new ModelCompositor(model);
var composite = new ModelCompositor(model, true);

// Initialize context
let context = {
Expand Down Expand Up @@ -397,7 +397,7 @@ describe('ModelCompositor', function() {

it('should produce suggestions from uncased input', function() {
let model = casedModel;
var composite = new ModelCompositor(model);
var composite = new ModelCompositor(model, true);

// Initialize context
let context = {
Expand Down Expand Up @@ -425,7 +425,7 @@ describe('ModelCompositor', function() {

it('should produce capitalized suggestions from fully-uppercased input', function() {
let model = casedModel;
var composite = new ModelCompositor(model);
var composite = new ModelCompositor(model, true);

// Initialize context
let context = {
Expand Down Expand Up @@ -453,7 +453,7 @@ describe('ModelCompositor', function() {

it('should produce "initial-case" suggestions from input with an initial capital', function() {
let model = casedModel;
var composite = new ModelCompositor(model);
var composite = new ModelCompositor(model, true);

// Initialize context
let context = {
Expand Down Expand Up @@ -481,7 +481,7 @@ describe('ModelCompositor', function() {

it('also from input with partial capitalization when including an initial capital', function() {
let model = casedModel;
var composite = new ModelCompositor(model);
var composite = new ModelCompositor(model, true);

// Initialize context
let context = {
Expand Down Expand Up @@ -512,7 +512,7 @@ describe('ModelCompositor', function() {
var model = new TrieModel(
jsonFixture('models/tries/english-1000')
);
var composite = new ModelCompositor(model);
var composite = new ModelCompositor(model, true);

// Initialize context
let context = {
Expand Down Expand Up @@ -542,7 +542,7 @@ describe('ModelCompositor', function() {
var model = new TrieModel(
jsonFixture('models/tries/english-1000')
);
var composite = new ModelCompositor(model);
var composite = new ModelCompositor(model, true);

// Initialize context
let context = {
Expand Down Expand Up @@ -602,7 +602,7 @@ describe('ModelCompositor', function() {
};

let model = new models.DummyModel(options);
let compositor = new ModelCompositor(model);
let compositor = new ModelCompositor(model, true);

var keep;
if(quoteStyle) {
Expand Down Expand Up @@ -646,7 +646,7 @@ describe('ModelCompositor', function() {
};

let model = new models.DummyModel(options);
let compositor = new ModelCompositor(model);
let compositor = new ModelCompositor(model, true);

return compositor.acceptSuggestion(suggestion, context, postTransform);
}
Expand Down Expand Up @@ -829,7 +829,7 @@ describe('ModelCompositor', function() {

describe('acceptReversion', function() {
let executeAcceptance = function(model, suggestion, context, postTransform) {
let compositor = new ModelCompositor(model);
let compositor = new ModelCompositor(model, true);

return {compositor: compositor, reversion: compositor.acceptSuggestion(suggestion, context, postTransform)};
}
Expand Down Expand Up @@ -869,7 +869,7 @@ describe('ModelCompositor', function() {
}

let model = new models.DummyModel({punctuation: englishPunctuation});
let compositor = new ModelCompositor(model);
let compositor = new ModelCompositor(model, true);

let reversion = compositor.acceptSuggestion(baseSuggestion, baseContext, postTransform);
assert.equal(reversion.transformId, baseSuggestion.transformId);
Expand Down Expand Up @@ -909,7 +909,7 @@ describe('ModelCompositor', function() {
}

let model = new models.TrieModel(jsonFixture('models/tries/english-1000'), {punctuation: englishPunctuation});
let compositor = new ModelCompositor(model);
let compositor = new ModelCompositor(model, true);

let initialSuggestions = compositor.predict(postTransform, baseContext);
let keepSuggestion = initialSuggestions[0];
Expand Down Expand Up @@ -944,7 +944,7 @@ describe('ModelCompositor', function() {
}

let model = new models.TrieModel(jsonFixture('models/tries/english-1000'), {punctuation: englishPunctuation});
let compositor = new ModelCompositor(model);
let compositor = new ModelCompositor(model, true);

let initialSuggestions = compositor.predict(postTransform, baseContext);
let keepSuggestion = initialSuggestions[0];
Expand Down

0 comments on commit a75cd6d

Please sign in to comment.