Skip to content

Commit

Permalink
BONNIEMAT-1696
Browse files Browse the repository at this point in the history
- fixed case...when...then calculation issue
- fixed null & false literal calculation issue
  • Loading branch information
adongare committed Feb 8, 2024
1 parent 244f799 commit 3f8de27
Show file tree
Hide file tree
Showing 9 changed files with 2,965 additions and 4,101 deletions.
16 changes: 14 additions & 2 deletions dist/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,15 @@ module.exports = class MeasureHelpers {
// the sourceLocalId is the FunctionRef itself to match how library statement references work.
localIds[libraryClauseLocalId] = { localId: libraryClauseLocalId, sourceLocalId: statement.localId };
}
// else if they key is localId push the value
// handle the `when` pieces of Case expression aka CaseItems.
// They have a `when` key that should be mapped to get a result from the expression that defines them
} else if (k === 'type' && v === 'Null' && statement.localId) {
// If this is a "Null" expression, mark that it `isFalsyLiteral` so we can interpret final results differently.
localIds[statement.localId] = { localId: statement.localId, isFalsyLiteral: true };
} else if (k === 'type' && v === 'Literal' && statement.localId && statement.value === 'false') {
// If this is a "Literal" expression whose value is false, mark that it `isFalsyLiteral` so we can interpret final results differently
localIds[statement.localId] = { localId: statement.localId, isFalsyLiteral: true };
// else if the key is localId, push the value
} else if (k === 'localId') {
localIds[v] = { localId: v };
// if the value is an array or object, recurse
Expand Down Expand Up @@ -1423,8 +1431,12 @@ module.exports = class ResultsHelpers {
finalResult = 'UNHIT';
} else if (
params.clause.isFalsyLiteral
&& Object.prototype.hasOwnProperty.call(params.rawClauseResults[params.libraryName], params.clause.localId)
&& Object.prototype.hasOwnProperty.call(params.rawClauseResults[params.library_name], params.clause.localId)
) {
// If this clause is a Null or Literal False we need to look for the existence of a result for the localId in the
// rawClauseResults instead. If the key for the localId exists then it was executed, and we will want to treat the
// `final` result as `TRUE` instead of `FALSE`. If the key is totally absent then it was not executed therefore
// `final` result should stay `FALSE`.
finalResult = 'TRUE';
} else if (this.doesResultPass(params.rawResult)) {
finalResult = 'TRUE';
Expand Down
10 changes: 9 additions & 1 deletion lib/helpers/measure_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,15 @@ module.exports = class MeasureHelpers {
// the sourceLocalId is the FunctionRef itself to match how library statement references work.
localIds[libraryClauseLocalId] = { localId: libraryClauseLocalId, sourceLocalId: statement.localId };
}
// else if they key is localId push the value
// handle the `when` pieces of Case expression aka CaseItems.
// They have a `when` key that should be mapped to get a result from the expression that defines them
} else if (k === 'type' && v === 'Null' && statement.localId) {
// If this is a "Null" expression, mark that it `isFalsyLiteral` so we can interpret final results differently.
localIds[statement.localId] = { localId: statement.localId, isFalsyLiteral: true };
} else if (k === 'type' && v === 'Literal' && statement.localId && statement.value === 'false') {
// If this is a "Literal" expression whose value is false, mark that it `isFalsyLiteral` so we can interpret final results differently
localIds[statement.localId] = { localId: statement.localId, isFalsyLiteral: true };
// else if the key is localId, push the value
} else if (k === 'localId') {
localIds[v] = { localId: v };
// if the value is an array or object, recurse
Expand Down
6 changes: 5 additions & 1 deletion lib/helpers/results_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,12 @@ module.exports = class ResultsHelpers {
finalResult = 'UNHIT';
} else if (
params.clause.isFalsyLiteral
&& Object.prototype.hasOwnProperty.call(params.rawClauseResults[params.libraryName], params.clause.localId)
&& Object.prototype.hasOwnProperty.call(params.rawClauseResults[params.library_name], params.clause.localId)
) {
// If this clause is a Null or Literal False we need to look for the existence of a result for the localId in the
// rawClauseResults instead. If the key for the localId exists then it was executed, and we will want to treat the
// `final` result as `TRUE` instead of `FALSE`. If the key is totally absent then it was not executed therefore
// `final` result should stay `FALSE`.
finalResult = 'TRUE';
} else if (this.doesResultPass(params.rawResult)) {
finalResult = 'TRUE';
Expand Down
File renamed without changes.
Loading

0 comments on commit 3f8de27

Please sign in to comment.