Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
(fix) Adjust generate text, some more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <jeromesimeon@me.com>
  • Loading branch information
jeromesimeon committed May 20, 2019
1 parent 34de550 commit 04cad77
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 261 deletions.
17 changes: 8 additions & 9 deletions backends/javascript/ergo-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ function arithMean(b) {
}
}
function toString(v) {
return toStringQ(v, "");
return toStringQ(v, "", true);
}
function toStringQ(v, quote) {
function toStringQ(v, quote, generateText) {
if (v === null)
return "null";
var t = typeof v;
Expand All @@ -217,13 +217,13 @@ function toStringQ(v, quote) {
if ({}.toString.apply(v) == "[object Array]") {
v = v.slice();
v.sort();
var result = "[";
var result = generateText ? "" : "[";
for (var i=0, n=v.length; i<n; i++) {
if (i > 0)
result += ", ";
generateText ? result += "" : result += ", ";
result += toStringQ(v[i], quote);
}
return result + "]";
return generateText ? result + "" : result + "]";
}
if (moment.isMoment(v)) {
return v.format();
Expand Down Expand Up @@ -591,8 +591,8 @@ function dateTimeFromString(stringDate) {
return moment.parseZone(stringDate).utcOffset(utcOffset, false);
}

const minDateTime = moment.parseZone("0001-01-01 00:00:00").utcOffset(utcOffset, false);
const maxDateTime = moment.parseZone("3268-01-21 23:59:59").utcOffset(utcOffset, false);
var minDateTime = moment.parseZone("0001-01-01 00:00:00").utcOffset(utcOffset, false);
var maxDateTime = moment.parseZone("3268-01-21 23:59:59").utcOffset(utcOffset, false);

function dateTimeMax(v) {
var v1 = mustBeDateArray(v);
Expand Down Expand Up @@ -636,7 +636,7 @@ function dateTimePeriodFromString(stringDuration) {

function dateTimeDurationFromNat(part, v) {
mustBeUnit(part);
let num;
var num;
if (v.hasOwnProperty('nat')) { num = v.nat; } else { num = v; }
// 'quarters' not built into durations
if (part === QUARTERS) {
Expand Down Expand Up @@ -771,4 +771,3 @@ function unwrapError(result) {
throw new Error("[Ergo] " + message);
}
}

2 changes: 2 additions & 0 deletions examples/interests/params2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
5 changes: 3 additions & 2 deletions examples/volumediscounttable/logic.ergo
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ define function findRate(volume: Double, rateTable: RateRange[]) : Double? {
contract VolumeDiscount over VolumeDiscountContract {
// Generate text
clause generateText() : String {
let rate = contract.rates;
return {{
Volume-Based Card Acceptance Agreement [Abbreviated]

Expand All @@ -52,8 +53,8 @@ a) Settlement Amount. Our agent will pay you according to your payment plan, as
b) Discount. The Discount is determined according to the following table:

| Annual Dollar Volume | Discount |
{{ foreach r in contract.rates
return {{| Between {{ r.volumeAbove }} and {{ r.volumeUpTo }} | {{ r.rate }} |
{{ foreach r in rates
return {{| Between {{ r.volumeAbove ?? 0.0 }} and {{ r.volumeUpTo ?? infinity }} | {{ r.rate }} |
}}
}}
}}
Expand Down
Loading

0 comments on commit 04cad77

Please sign in to comment.