From ad7a5cca0e413e7337f3500fa2a154b5740a0ef9 Mon Sep 17 00:00:00 2001 From: liminge Date: Sun, 28 Jan 2024 19:34:58 -0500 Subject: [PATCH 1/4] fix: use consistent predicate output format (#4112) --- src/predicate.ts | 10 +++++----- test/predicate.test.ts | 32 ++++++++++++++++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/predicate.ts b/src/predicate.ts index b981099e60..ea84bdf5bb 100644 --- a/src/predicate.ts +++ b/src/predicate.ts @@ -209,19 +209,19 @@ export function fieldFilterExpression(predicate: FieldPredicate, useInRange = tr : rawFieldExpr; if (isFieldEqualPredicate(predicate)) { - return `${fieldExpr}===${predicateValueExpr(predicate.equal, unit)}`; + return `${fieldExpr} === ${predicateValueExpr(predicate.equal, unit)}`; } else if (isFieldLTPredicate(predicate)) { const upper = predicate.lt; - return `${fieldExpr}<${predicateValueExpr(upper, unit)}`; + return `${fieldExpr} < ${predicateValueExpr(upper, unit)}`; } else if (isFieldGTPredicate(predicate)) { const lower = predicate.gt; - return `${fieldExpr}>${predicateValueExpr(lower, unit)}`; + return `${fieldExpr} > ${predicateValueExpr(lower, unit)}`; } else if (isFieldLTEPredicate(predicate)) { const upper = predicate.lte; - return `${fieldExpr}<=${predicateValueExpr(upper, unit)}`; + return `${fieldExpr} <= ${predicateValueExpr(upper, unit)}`; } else if (isFieldGTEPredicate(predicate)) { const lower = predicate.gte; - return `${fieldExpr}>=${predicateValueExpr(lower, unit)}`; + return `${fieldExpr} >= ${predicateValueExpr(lower, unit)}`; } else if (isFieldOneOfPredicate(predicate)) { return `indexof([${predicateValuesExpr(predicate.oneOf, unit).join(',')}], ${fieldExpr}) !== -1`; } else if (isFieldValidPredicate(predicate)) { diff --git a/test/predicate.test.ts b/test/predicate.test.ts index 208ec0f8f0..683dd1e49c 100644 --- a/test/predicate.test.ts +++ b/test/predicate.test.ts @@ -16,7 +16,7 @@ describe('filter', () => { const oneOfFilter = {field: 'color', oneOf: ['red', 'yellow']}; const rangeFilter = {field: 'x', range: [0, 5]}; const rangeSignalFilter = {field: 'x', range: {signal: 'range'}}; - const exprFilter = 'datum["x"]===5'; + const exprFilter = 'datum["x"] === 5'; const lessThanEqualsFilter = {field: 'x', lte: 'z'}; const validFilter: FieldValidPredicate = {field: 'x', valid: true}; @@ -96,27 +96,27 @@ describe('filter', () => { describe('expression', () => { it('should return a correct expression for an EqualFilter', () => { const expr = expression(null, {field: 'color', equal: 'red'}); - expect(expr).toBe('datum["color"]==="red"'); + expect(expr).toBe('datum["color"] === "red"'); }); it('should return correct expression for lessThan', () => { const expr = expression(null, {field: 'x', lt: 1}); - expect(expr).toBe('datum["x"]<1'); + expect(expr).toBe('datum["x"] < 1'); }); it('should return correct expression for greaterThan', () => { const expr = expression(null, {field: 'x', gt: 'aardvark'}); - expect(expr).toBe('datum["x"]>"aardvark"'); + expect(expr).toBe('datum["x"] > "aardvark"'); }); it('should return correct expression for lessThanEquals', () => { const expr = expression(null, {field: 'x', lte: 'zyzzyva'}); - expect(expr).toBe('datum["x"]<="zyzzyva"'); + expect(expr).toBe('datum["x"] <= "zyzzyva"'); }); it('should return correct expression for greaterThanEquals', () => { const expr = expression(null, {field: 'x', gte: 1}); - expect(expr).toBe('datum["x"]>=1'); + expect(expr).toBe('datum["x"] >= 1'); }); it('should return correct expression for valid', () => { @@ -131,7 +131,7 @@ describe('filter', () => { month: 'January' } }); - expect(expr).toBe('datum["date"]===time(datetime(2012, 0, 1, 0, 0, 0, 0))'); + expect(expr).toBe('datum["date"] === time(datetime(2012, 0, 1, 0, 0, 0, 0))'); }); it('should return a correct expression for an EqualFilter with time unit and datetime object', () => { @@ -143,7 +143,7 @@ describe('filter', () => { } }); expect(expr).toBe( - 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0))===time(datetime(2012, 0, 1, 0, 0, 0, 0))' + 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0)) === time(datetime(2012, 0, 1, 0, 0, 0, 0))' ); }); @@ -154,7 +154,7 @@ describe('filter', () => { equal: 'January' }); expect(expr).toBe( - 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0))===time(datetime(2012, 0, 1, 0, 0, 0, 0))' + 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0)) === time(datetime(2012, 0, 1, 0, 0, 0, 0))' ); }); @@ -165,7 +165,7 @@ describe('filter', () => { month: 'February' } }); - expect(expr).toBe('datum["date"] { @@ -177,7 +177,7 @@ describe('filter', () => { } }); expect(expr).toBe( - 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0))>time(datetime(2012, 0, 1, 0, 0, 0, 0))' + 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0)) > time(datetime(2012, 0, 1, 0, 0, 0, 0))' ); }); @@ -188,7 +188,7 @@ describe('filter', () => { gte: 'January' }); expect(expr).toBe( - 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0))>=time(datetime(2012, 0, 1, 0, 0, 0, 0))' + 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0)) >= time(datetime(2012, 0, 1, 0, 0, 0, 0))' ); }); @@ -230,7 +230,7 @@ describe('filter', () => { it('generates expressions for composed filters', () => { let expr = expression(null, {not: {field: 'color', equal: 'red'}}); - expect(expr).toBe('!(datum["color"]==="red")'); + expect(expr).toBe('!(datum["color"] === "red")'); expr = expression(null, { and: [ @@ -239,20 +239,20 @@ describe('filter', () => { ] }); - expect(expr).toBe('(datum["color"]==="red") && (inrange(datum["x"], [0, 5]))'); + expect(expr).toBe('(datum["color"] === "red") && (inrange(datum["x"], [0, 5]))'); expr = expression(null, { and: [ {field: 'color', oneOf: ['red', 'yellow']}, { - or: [{field: 'x', range: [0, null]}, 'datum.price > 10', {not: 'datum["x"]===5'}] + or: [{field: 'x', range: [0, null]}, 'datum.price > 10', {not: 'datum["x"] === 5'}] } ] }); expect(expr).toEqual( '(indexof(["red","yellow"], datum["color"]) !== -1) && ' + - '((datum["x"] >= 0) || (datum.price > 10) || (!(datum["x"]===5)))' + '((datum["x"] >= 0) || (datum.price > 10) || (!(datum["x"] === 5)))' ); }); From f87403df742197ef147f76a16c36265b13ace651 Mon Sep 17 00:00:00 2001 From: liminge Date: Sun, 28 Jan 2024 21:05:03 -0500 Subject: [PATCH 2/4] output single quotation marks instead of double quotation marks. --- src/predicate.ts | 9 +++++--- src/util.ts | 10 +++++--- test/predicate.test.ts | 52 +++++++++++++++++++++--------------------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/predicate.ts b/src/predicate.ts index ea84bdf5bb..c2b2833917 100644 --- a/src/predicate.ts +++ b/src/predicate.ts @@ -209,7 +209,8 @@ export function fieldFilterExpression(predicate: FieldPredicate, useInRange = tr : rawFieldExpr; if (isFieldEqualPredicate(predicate)) { - return `${fieldExpr} === ${predicateValueExpr(predicate.equal, unit)}`; + const equal = predicate.equal; + return `${fieldExpr} === ${predicateValueExpr(equal, unit)}`; } else if (isFieldLTPredicate(predicate)) { const upper = predicate.lt; return `${fieldExpr} < ${predicateValueExpr(upper, unit)}`; @@ -223,9 +224,11 @@ export function fieldFilterExpression(predicate: FieldPredicate, useInRange = tr const lower = predicate.gte; return `${fieldExpr} >= ${predicateValueExpr(lower, unit)}`; } else if (isFieldOneOfPredicate(predicate)) { - return `indexof([${predicateValuesExpr(predicate.oneOf, unit).join(',')}], ${fieldExpr}) !== -1`; + const oneOf = predicate.oneOf; + return `indexof([${predicateValuesExpr(oneOf, unit).join(',')}], ${fieldExpr}) !== -1`; } else if (isFieldValidPredicate(predicate)) { - return fieldValidPredicate(fieldExpr, predicate.valid); + const valid = predicate.valid; + return fieldValidPredicate(fieldExpr, valid); } else if (isFieldRangePredicate(predicate)) { const {range} = predicate; const lower = isSignalRef(range) ? {signal: `${range.signal}[0]`} : range[0]; diff --git a/src/util.ts b/src/util.ts index 832043a667..9330439282 100644 --- a/src/util.ts +++ b/src/util.ts @@ -288,13 +288,17 @@ export function accessPathWithDatum(path: string, datum = 'datum') { * @param datum The string to use for `datum`. */ export function flatAccessWithDatum(path: string, datum: 'datum' | 'parent' | 'datum.datum' = 'datum') { - return `${datum}[${stringValue(splitAccessPath(path).join('.'))}]`; + return `${datum}[${doubleQuotes2Single(stringValue(splitAccessPath(path).join('.')))}]`; } function escapePathAccess(string: string) { return string.replace(/(\[|\]|\.|'|")/g, '\\$1'); } +function doubleQuotes2Single(string: string) { + return string.replace(/"/g, "'"); +} + /** * Replaces path accesses with access to non-nested field. * For example, `foo["bar"].baz` becomes `foo\\.bar\\.baz`. @@ -476,7 +480,7 @@ export function stringify(data: any) { if (node === undefined) return undefined; if (typeof node == 'number') return isFinite(node) ? '' + node : 'null'; - if (typeof node !== 'object') return JSON.stringify(node); + if (typeof node !== 'object') return doubleQuotes2Single(JSON.stringify(node)); let i, out; if (Array.isArray(node)) { @@ -503,7 +507,7 @@ export function stringify(data: any) { if (!value) continue; if (out) out += ','; - out += JSON.stringify(key) + ':' + value; + out += doubleQuotes2Single(JSON.stringify(key)) + ':' + value; } seen.splice(seenIndex, 1); return `{${out}}`; diff --git a/test/predicate.test.ts b/test/predicate.test.ts index 683dd1e49c..d25cd8fd20 100644 --- a/test/predicate.test.ts +++ b/test/predicate.test.ts @@ -16,7 +16,7 @@ describe('filter', () => { const oneOfFilter = {field: 'color', oneOf: ['red', 'yellow']}; const rangeFilter = {field: 'x', range: [0, 5]}; const rangeSignalFilter = {field: 'x', range: {signal: 'range'}}; - const exprFilter = 'datum["x"] === 5'; + const exprFilter = "datum['x'] === 5"; const lessThanEqualsFilter = {field: 'x', lte: 'z'}; const validFilter: FieldValidPredicate = {field: 'x', valid: true}; @@ -96,32 +96,32 @@ describe('filter', () => { describe('expression', () => { it('should return a correct expression for an EqualFilter', () => { const expr = expression(null, {field: 'color', equal: 'red'}); - expect(expr).toBe('datum["color"] === "red"'); + expect(expr).toBe("datum['color'] === 'red'"); }); it('should return correct expression for lessThan', () => { const expr = expression(null, {field: 'x', lt: 1}); - expect(expr).toBe('datum["x"] < 1'); + expect(expr).toBe("datum['x'] < 1"); }); it('should return correct expression for greaterThan', () => { const expr = expression(null, {field: 'x', gt: 'aardvark'}); - expect(expr).toBe('datum["x"] > "aardvark"'); + expect(expr).toBe("datum['x'] > 'aardvark'"); }); it('should return correct expression for lessThanEquals', () => { const expr = expression(null, {field: 'x', lte: 'zyzzyva'}); - expect(expr).toBe('datum["x"] <= "zyzzyva"'); + expect(expr).toBe("datum['x'] <= 'zyzzyva'"); }); it('should return correct expression for greaterThanEquals', () => { const expr = expression(null, {field: 'x', gte: 1}); - expect(expr).toBe('datum["x"] >= 1'); + expect(expr).toBe("datum['x'] >= 1"); }); it('should return correct expression for valid', () => { const expr = expression(null, {field: 'x', valid: true}); - expect(expr).toBe('isValid(datum["x"]) && isFinite(+datum["x"])'); + expect(expr).toBe("isValid(datum['x']) && isFinite(+datum['x'])"); }); it('should return a correct expression for an EqualFilter with datetime object', () => { @@ -131,7 +131,7 @@ describe('filter', () => { month: 'January' } }); - expect(expr).toBe('datum["date"] === time(datetime(2012, 0, 1, 0, 0, 0, 0))'); + expect(expr).toBe("datum['date'] === time(datetime(2012, 0, 1, 0, 0, 0, 0))"); }); it('should return a correct expression for an EqualFilter with time unit and datetime object', () => { @@ -143,7 +143,7 @@ describe('filter', () => { } }); expect(expr).toBe( - 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0)) === time(datetime(2012, 0, 1, 0, 0, 0, 0))' + "time(datetime(2012, month(datum['date']), 1, 0, 0, 0, 0)) === time(datetime(2012, 0, 1, 0, 0, 0, 0))" ); }); @@ -154,7 +154,7 @@ describe('filter', () => { equal: 'January' }); expect(expr).toBe( - 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0)) === time(datetime(2012, 0, 1, 0, 0, 0, 0))' + "time(datetime(2012, month(datum['date']), 1, 0, 0, 0, 0)) === time(datetime(2012, 0, 1, 0, 0, 0, 0))" ); }); @@ -165,7 +165,7 @@ describe('filter', () => { month: 'February' } }); - expect(expr).toBe('datum["date"] < time(datetime(2012, 1, 1, 0, 0, 0, 0))'); + expect(expr).toBe("datum['date'] < time(datetime(2012, 1, 1, 0, 0, 0, 0))"); }); it('should return a correct expression for an greaterThanFilter with time unit and datetime object', () => { @@ -177,7 +177,7 @@ describe('filter', () => { } }); expect(expr).toBe( - 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0)) > time(datetime(2012, 0, 1, 0, 0, 0, 0))' + "time(datetime(2012, month(datum['date']), 1, 0, 0, 0, 0)) > time(datetime(2012, 0, 1, 0, 0, 0, 0))" ); }); @@ -188,33 +188,33 @@ describe('filter', () => { gte: 'January' }); expect(expr).toBe( - 'time(datetime(2012, month(datum["date"]), 1, 0, 0, 0, 0)) >= time(datetime(2012, 0, 1, 0, 0, 0, 0))' + "time(datetime(2012, month(datum['date']), 1, 0, 0, 0, 0)) >= time(datetime(2012, 0, 1, 0, 0, 0, 0))" ); }); it('should return a correct expression for an InFilter', () => { const expr = expression(null, {field: 'color', oneOf: ['red', 'yellow']}); - expect(expr).toBe('indexof(["red","yellow"], datum["color"]) !== -1'); + expect(expr).toBe("indexof(['red','yellow'], datum['color']) !== -1"); }); it('should return a correct expression for a RangeFilter', () => { const expr = expression(null, {field: 'x', range: [0, 5]}); - expect(expr).toBe('inrange(datum["x"], [0, 5])'); + expect(expr).toBe("inrange(datum['x'], [0, 5])"); }); it('should return a correct expression for a RangeFilter with signal range', () => { const expr = expression(null, {field: 'x', range: {signal: 'r'}}); - expect(expr).toBe('inrange(datum["x"], [r[0], r[1]])'); + expect(expr).toBe("inrange(datum['x'], [r[0], r[1]])"); }); it('should return a correct expression for a RangeFilter with no lower bound', () => { const expr = expression(null, {field: 'x', range: [null, 5]}); - expect(expr).toBe('datum["x"] <= 5'); + expect(expr).toBe("datum['x'] <= 5"); }); it('should return a correct expression for a RangeFilter with no upper bound', () => { const expr = expression(null, {field: 'x', range: [0, null]}); - expect(expr).toBe('datum["x"] >= 0'); + expect(expr).toBe("datum['x'] >= 0"); }); it('should return true for a RangeFilter with no bound', () => { @@ -223,14 +223,14 @@ describe('filter', () => { }); it('should return a correct expression for an expression filter', () => { - const expr = expression(null, 'datum["x"]===5'); - expect(expr).toBe('datum["x"]===5'); + const expr = expression(null, "datum['x']===5"); + expect(expr).toBe("datum['x']===5"); }); }); it('generates expressions for composed filters', () => { let expr = expression(null, {not: {field: 'color', equal: 'red'}}); - expect(expr).toBe('!(datum["color"] === "red")'); + expect(expr).toBe("!(datum['color'] === 'red')"); expr = expression(null, { and: [ @@ -239,27 +239,27 @@ describe('filter', () => { ] }); - expect(expr).toBe('(datum["color"] === "red") && (inrange(datum["x"], [0, 5]))'); + expect(expr).toBe("(datum['color'] === 'red') && (inrange(datum['x'], [0, 5]))"); expr = expression(null, { and: [ {field: 'color', oneOf: ['red', 'yellow']}, { - or: [{field: 'x', range: [0, null]}, 'datum.price > 10', {not: 'datum["x"] === 5'}] + or: [{field: 'x', range: [0, null]}, 'datum.price > 10', {not: "datum['x'] === 5"}] } ] }); expect(expr).toEqual( - '(indexof(["red","yellow"], datum["color"]) !== -1) && ' + - '((datum["x"] >= 0) || (datum.price > 10) || (!(datum["x"] === 5)))' + "(indexof(['red','yellow'], datum['color']) !== -1) && " + + "((datum['x'] >= 0) || (datum.price > 10) || (!(datum['x'] === 5)))" ); }); describe('fieldFilterExpression', () => { it('generates a range predicate using inequalities when useInRange=false', () => { const expr = fieldFilterExpression({field: 'x', range: [0, 5]}, false); - expect(expr).toBe('datum["x"] >= 0 && datum["x"] <= 5'); + expect(expr).toBe("datum['x'] >= 0 && datum['x'] <= 5"); }); }); }); From ccd43a2fbc89ba92386d4c74013fa01d0ebf9275 Mon Sep 17 00:00:00 2001 From: liminge Date: Tue, 30 Jan 2024 19:13:23 -0500 Subject: [PATCH 3/4] swap single and double quotation marks in unit test part 1. --- test/channeldef.test.ts | 12 ++++----- test/compile/axis/assemble.test.ts | 2 +- test/compile/axis/encode.test.ts | 8 +++--- test/compile/axis/parse.test.ts | 4 +-- test/compile/data/calculate.test.ts | 4 +-- test/compile/data/density.test.ts | 2 +- test/compile/data/extent.test.ts | 2 +- test/compile/data/filter.test.ts | 4 +-- test/compile/data/filterinvalid.test.ts | 4 +-- test/compile/data/flatten.test.ts | 2 +- test/compile/data/fold.test.ts | 2 +- test/compile/data/impute.test.ts | 2 +- test/compile/data/loess.test.ts | 2 +- test/compile/data/lookup.test.ts | 2 +- test/compile/data/pivot.test.ts | 2 +- test/compile/data/quantile.test.ts | 2 +- test/compile/data/sample.test.ts | 2 +- test/compile/data/stack.test.ts | 4 +-- test/compile/data/timeunit.test.ts | 6 ++--- test/compile/data/window.test.ts | 2 +- test/compile/format.test.ts | 28 ++++++++++---------- test/compile/header/assemble.test.ts | 4 +-- test/compile/legend/assemble.test.ts | 2 +- test/compile/legend/encode.test.ts | 6 ++--- test/compile/mark/encode/valueref.test.ts | 2 +- test/compile/mark/mark.test.ts | 8 +++--- test/compile/mark/point.test.ts | 8 +++--- test/compile/mark/text.test.ts | 6 ++--- test/compile/scale/domain.test.ts | 8 +++--- test/compile/signal.test.ts | 2 +- test/timeunit.test.ts | 32 +++++++++++------------ test/util.test.ts | 14 +++++----- 32 files changed, 95 insertions(+), 95 deletions(-) diff --git a/test/channeldef.test.ts b/test/channeldef.test.ts index c25574932c..5ed7ebd8a7 100644 --- a/test/channeldef.test.ts +++ b/test/channeldef.test.ts @@ -22,20 +22,20 @@ describe('fieldDef', () => { }); it('should access flattened fields in expression', () => { - expect(vgField({field: 'foo.bar\\.baz'}, {expr: 'datum'})).toBe('datum["foo.bar.baz"]'); + expect(vgField({field: 'foo.bar\\.baz'}, {expr: 'datum'})).toBe("datum['foo.bar.baz']"); }); it('should access argmin/argmax fields in expression', () => { - expect(vgField({aggregate: {argmin: 'b'}, field: 'a'})).toBe('argmin_b["a"]'); - expect(vgField({aggregate: {argmax: 'b'}, field: 'a'})).toBe('argmax_b["a"]'); + expect(vgField({aggregate: {argmin: 'b'}, field: 'a'})).toBe("argmin_b['a']"); + expect(vgField({aggregate: {argmax: 'b'}, field: 'a'})).toBe("argmax_b['a']"); }); it('should support argmin/argmax field names with space', () => { expect(vgField({aggregate: {argmin: 'foo bar'}, field: 'bar baz'}, {expr: 'datum'})).toBe( - 'datum["argmin_foo bar"]["bar baz"]' + "datum['argmin_foo bar']['bar baz']" ); expect(vgField({aggregate: {argmax: 'foo bar'}, field: 'bar baz'}, {expr: 'datum'})).toBe( - 'datum["argmax_foo bar"]["bar baz"]' + "datum['argmax_foo bar']['bar baz']" ); }); @@ -48,7 +48,7 @@ describe('fieldDef', () => { }); it('should support fields with space in datum', () => { - expect(vgField({field: 'foo bar'}, {expr: 'datum'})).toBe('datum["foo bar"]'); + expect(vgField({field: 'foo bar'}, {expr: 'datum'})).toBe("datum['foo bar']"); }); }); diff --git a/test/compile/axis/assemble.test.ts b/test/compile/axis/assemble.test.ts index 303ab1a62a..df3b01d88c 100644 --- a/test/compile/axis/assemble.test.ts +++ b/test/compile/axis/assemble.test.ts @@ -121,7 +121,7 @@ describe('compile/axis/assemble', () => { const axes = model.assembleAxes(); expect(axes[1].encode.labels.update.text).toEqual({ - signal: 'myFormat(datum.value, {"a":"b"})[0]' + signal: "myFormat(datum.value, {'a':'b'})[0]" }); }); }); diff --git a/test/compile/axis/encode.test.ts b/test/compile/axis/encode.test.ts index 8b64e8b900..c2cbe61ba7 100644 --- a/test/compile/axis/encode.test.ts +++ b/test/compile/axis/encode.test.ts @@ -35,7 +35,7 @@ describe('compile/axis/encode', () => { config: {customFormatTypes: true} }); const labels = encode.labels(model, 'x', {}); - expect(labels.text.signal).toBe('customNumberFormat(datum.value, "abc")'); + expect(labels.text.signal).toBe("customNumberFormat(datum.value, 'abc')"); }); it('applies custom format type without format', () => { @@ -59,7 +59,7 @@ describe('compile/axis/encode', () => { config: {customFormatTypes: true, numberFormat: 'abc', numberFormatType: 'customNumberFormat'} }); const labels = encode.labels(model, 'x', {}); - expect(labels.text.signal).toBe('customNumberFormat(datum.value, "abc")'); + expect(labels.text.signal).toBe("customNumberFormat(datum.value, 'abc')"); }); it('applies custom format type from a normalized stack', () => { @@ -75,7 +75,7 @@ describe('compile/axis/encode', () => { } }); const labels = encode.labels(model, 'x', {}); - expect(labels.text.signal).toBe('customNumberFormat(datum.value, "abc")'); + expect(labels.text.signal).toBe("customNumberFormat(datum.value, 'abc')"); }); it('applies custom timeFormatType from config', () => { @@ -87,7 +87,7 @@ describe('compile/axis/encode', () => { config: {customFormatTypes: true, timeFormat: 'abc', timeFormatType: 'customTimeFormat'} }); const labels = encode.labels(model, 'x', {}); - expect(labels.text.signal).toBe('customTimeFormat(datum.value, "abc")'); + expect(labels.text.signal).toBe("customTimeFormat(datum.value, 'abc')"); }); it('prefers timeUnit over timeFormatType from config', () => { diff --git a/test/compile/axis/parse.test.ts b/test/compile/axis/parse.test.ts index 29b437dc37..c243fc46b4 100644 --- a/test/compile/axis/parse.test.ts +++ b/test/compile/axis/parse.test.ts @@ -406,7 +406,7 @@ describe('Axis', () => { const axisComponent = parseUnitAxes(model); expect(axisComponent['x']).toHaveLength(1); expect(axisComponent['x'][0].get('format')).toEqual({ - signal: 'timeUnitSpecifier(["quarter"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "})' + signal: "timeUnitSpecifier(['quarter'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '})" }); }); @@ -446,7 +446,7 @@ describe('Axis', () => { const axisComponent = parseUnitAxes(model); expect(axisComponent['x']).toHaveLength(1); expect(axisComponent['x'][0].get('format')).toEqual({ - signal: 'timeUnitSpecifier(["year","quarter","month"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "})' + signal: "timeUnitSpecifier(['year','quarter','month'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '})" }); }); }); diff --git a/test/compile/data/calculate.test.ts b/test/compile/data/calculate.test.ts index 5ffefff77c..704413eb7f 100644 --- a/test/compile/data/calculate.test.ts +++ b/test/compile/data/calculate.test.ts @@ -28,7 +28,7 @@ describe('compile/data/calculate', () => { const nodes = assembleFromSortArray(model); expect(nodes).toEqual({ type: 'formula', - expr: 'datum["a"]==="B" ? 0 : datum["a"]==="A" ? 1 : datum["a"]==="C" ? 2 : 3', + expr: "datum['a'] === 'B' ? 0 : datum[\'a\'] === 'A' ? 1 : datum['a'] === 'C' ? 2 : 3", as: 'x_a_sort_index' }); }); @@ -64,7 +64,7 @@ describe('compile/data/calculate', () => { }); const node = CalculateNode.parseAllForSortIndex(null, model) as CalculateNode; expect(node.hash()).toBe( - 'Calculate {"as":"x_a_sort_index","calculate":"datum[\\"a\\"]===\\"B\\" ? 0 : datum[\\"a\\"]===\\"A\\" ? 1 : datum[\\"a\\"]===\\"C\\" ? 2 : 3"}' + "Calculate {'as':'x_a_sort_index','calculate':'datum[\'a\'] === \\'B\\' ? 0 : datum[\'a\'] === \\'A\\' ? 1 : datum[\'a\'] === \\'C\\' ? 2 : 3'}" ); }); }); diff --git a/test/compile/data/density.test.ts b/test/compile/data/density.test.ts index 911510c88f..3f5e19457a 100644 --- a/test/compile/data/density.test.ts +++ b/test/compile/data/density.test.ts @@ -119,7 +119,7 @@ describe('compile/data/fold', () => { as: ['A', 'B'] }; const density = new DensityTransformNode(null, transform); - expect(density.hash()).toBe('DensityTransform {"as":["A","B"],"density":"v"}'); + expect(density.hash()).toBe("DensityTransform {'as':['A','B'],'density':'v'}"); }); }); diff --git a/test/compile/data/extent.test.ts b/test/compile/data/extent.test.ts index 94c31a1690..908e60adf6 100644 --- a/test/compile/data/extent.test.ts +++ b/test/compile/data/extent.test.ts @@ -36,7 +36,7 @@ describe('compile/data/extent', () => { param: 'A' }; const extent = new ExtentTransformNode(null, transform); - expect(extent.hash()).toBe('ExtentTransform {"extent":"a","param":"A"}'); + expect(extent.hash()).toBe("ExtentTransform {'extent':'a','param':'A'}"); }); }); diff --git a/test/compile/data/filter.test.ts b/test/compile/data/filter.test.ts index 10cd9cc511..0003f95db8 100644 --- a/test/compile/data/filter.test.ts +++ b/test/compile/data/filter.test.ts @@ -63,7 +63,7 @@ describe('compile/data/filter', () => { describe('hash', () => { it('should generate the correct hash', () => { const filterNode = new FilterNode(null, null, {field: 'a', equal: {year: 2000}}); - expect(filterNode.hash()).toBe('Filter datum["a"]===time(datetime(2000, 0, 1, 0, 0, 0, 0))'); + expect(filterNode.hash()).toBe("Filter datum['a'] === time(datetime(2000, 0, 1, 0, 0, 0, 0))"); }); }); @@ -78,7 +78,7 @@ describe('compile/data/filter', () => { describe('assemble()', () => { it('converts expr in predicates correctly', () => { const node = new FilterNode(null, null, {field: 'foo', equal: {expr: 'bar'}}); - expect(node.assemble().expr).toBe('datum["foo"]===bar'); + expect(node.assemble().expr).toBe("datum['foo'] === bar"); }); }); }); diff --git a/test/compile/data/filterinvalid.test.ts b/test/compile/data/filterinvalid.test.ts index 3eaddce808..7a97d556ab 100644 --- a/test/compile/data/filterinvalid.test.ts +++ b/test/compile/data/filterinvalid.test.ts @@ -99,7 +99,7 @@ describe('compile/data/filterinvalid', () => { expect(parse(model).assemble()).toEqual({ type: 'filter', - expr: 'isValid(datum["foo"]) && isFinite(+datum["foo"])' + expr: "isValid(datum['foo']) && isFinite(+datum['foo'])" }); }); @@ -113,7 +113,7 @@ describe('compile/data/filterinvalid', () => { expect(parse(model).assemble()).toEqual({ type: 'filter', - expr: 'isValid(datum["foo.bar"]) && isFinite(+datum["foo.bar"])' + expr: "isValid(datum['foo.bar']) && isFinite(+datum['foo.bar'])" }); }); }); diff --git a/test/compile/data/flatten.test.ts b/test/compile/data/flatten.test.ts index 9ae60209b7..df678ed60b 100644 --- a/test/compile/data/flatten.test.ts +++ b/test/compile/data/flatten.test.ts @@ -78,7 +78,7 @@ describe('compile/data/flatten', () => { flatten: ['a', 'b'] }; const flatten = new FlattenTransformNode(null, transform); - expect(flatten.hash()).toBe('FlattenTransform {"as":["a","b"],"flatten":["a","b"]}'); + expect(flatten.hash()).toBe("FlattenTransform {'as':['a','b'],'flatten':['a','b']}"); }); }); }); diff --git a/test/compile/data/fold.test.ts b/test/compile/data/fold.test.ts index adb5338e91..a4a05f3b24 100644 --- a/test/compile/data/fold.test.ts +++ b/test/compile/data/fold.test.ts @@ -80,7 +80,7 @@ describe('compile/data/fold', () => { as: ['A', 'B'] }; const fold = new FoldTransformNode(null, transform); - expect(fold.hash()).toBe('FoldTransform {"as":["A","B"],"fold":["a","b"]}'); + expect(fold.hash()).toBe("FoldTransform {'as':['A','B'],'fold':['a','b']}"); }); }); diff --git a/test/compile/data/impute.test.ts b/test/compile/data/impute.test.ts index 8209a53555..1afa2fed53 100644 --- a/test/compile/data/impute.test.ts +++ b/test/compile/data/impute.test.ts @@ -210,7 +210,7 @@ describe('compile/data/impute', () => { value: 200 }; const impute = new ImputeNode(null, transform); - expect(impute.hash()).toBe('Impute {"impute":"y","key":"x","method":"value","value":200}'); + expect(impute.hash()).toBe("Impute {'impute':'y','key':'x','method':'value','value':200}"); }); }); diff --git a/test/compile/data/loess.test.ts b/test/compile/data/loess.test.ts index 9eee9116c1..7e94a603cd 100644 --- a/test/compile/data/loess.test.ts +++ b/test/compile/data/loess.test.ts @@ -104,7 +104,7 @@ describe('compile/data/fold', () => { as: ['A', 'B'] }; const loess = new LoessTransformNode(null, transform); - expect(loess.hash()).toBe('LoessTransform {"as":["A","B"],"loess":"y","on":"x"}'); + expect(loess.hash()).toBe("LoessTransform {'as':['A','B'],'loess':'y','on':'x'}"); }); }); diff --git a/test/compile/data/lookup.test.ts b/test/compile/data/lookup.test.ts index 24ce16b45a..8ff26b07ba 100644 --- a/test/compile/data/lookup.test.ts +++ b/test/compile/data/lookup.test.ts @@ -205,7 +205,7 @@ describe('compile/data/lookup', () => { lookup.assemble(); expect(lookup.hash()).toBe( - 'Lookup {"secondary":"lookup_0","transform":{"as":"lookedup","from":{"data":{"url":"data/lookup_people.csv"},"key":"name"},"lookup":"person"}}' + "Lookup {'secondary':'lookup_0','transform':{'as':'lookedup','from':{'data':{'url':'data/lookup_people.csv'},'key':'name'},'lookup':'person'}}" ); }); }); diff --git a/test/compile/data/pivot.test.ts b/test/compile/data/pivot.test.ts index 8b4b77d96f..6b756735f7 100644 --- a/test/compile/data/pivot.test.ts +++ b/test/compile/data/pivot.test.ts @@ -70,7 +70,7 @@ describe('compile/data/pivot', () => { value: 'b' }; const pivot = new PivotTransformNode(null, transform); - expect(pivot.hash()).toBe('PivotTransform {"pivot":"a","value":"b"}'); + expect(pivot.hash()).toBe("PivotTransform {'pivot':'a','value':'b'}"); }); describe('clone', () => { diff --git a/test/compile/data/quantile.test.ts b/test/compile/data/quantile.test.ts index 4c422eff59..350509962a 100644 --- a/test/compile/data/quantile.test.ts +++ b/test/compile/data/quantile.test.ts @@ -93,7 +93,7 @@ describe('compile/data/fold', () => { as: ['A', 'B'] }; const quantile = new QuantileTransformNode(null, transform); - expect(quantile.hash()).toBe('QuantileTransform {"as":["A","B"],"quantile":"x"}'); + expect(quantile.hash()).toBe("QuantileTransform {'as':['A','B'],'quantile':'x'}"); }); }); diff --git a/test/compile/data/sample.test.ts b/test/compile/data/sample.test.ts index 5216a6b19e..5ebe4a1e4a 100644 --- a/test/compile/data/sample.test.ts +++ b/test/compile/data/sample.test.ts @@ -25,7 +25,7 @@ describe('compile/data/sample', () => { describe('producedFields', () => { it('should generate the correct hash', () => { const sample = new SampleTransformNode(null, transform); - expect(sample.hash()).toBe('SampleTransform {"sample":500}'); + expect(sample.hash()).toBe("SampleTransform {'sample':500}"); }); it('should produce different hashes for different samples', () => { diff --git a/test/compile/data/stack.test.ts b/test/compile/data/stack.test.ts index 11d0d1f04e..aafbbe0d9a 100644 --- a/test/compile/data/stack.test.ts +++ b/test/compile/data/stack.test.ts @@ -202,7 +202,7 @@ describe('compile/data/stack', () => { expect(assemble(model)).toEqual([ { type: 'formula', - expr: '0.5*datum["bin_maxbins_10_b"]+0.5*datum["bin_maxbins_10_b_end"]', + expr: "0.5*datum['bin_maxbins_10_b']+0.5*datum['bin_maxbins_10_b_end']", as: 'bin_maxbins_10_b_mid' }, { @@ -350,7 +350,7 @@ describe('compile/data/stack', () => { }); const stack = StackNode.makeFromEncoding(null, model); expect(stack.hash()).toBe( - 'Stack {"as":["sum_a_start","sum_a_end"],"dimensionFieldDefs":[{"field":"b","type":"nominal"}],"facetby":[],"impute":false,"offset":"zero","sort":{"field":["c"],"order":["ascending"]},"stackField":"sum_a","stackby":["c"]}' + "Stack {'as':['sum_a_start','sum_a_end'],'dimensionFieldDefs':[{'field':'b','type':'nominal'}],'facetby':[],'impute':false,'offset':'zero','sort':{'field':['c'],'order':['ascending']},'stackField':'sum_a','stackby':['c']}" ); }); diff --git a/test/compile/data/timeunit.test.ts b/test/compile/data/timeunit.test.ts index 85cce49580..e0e8456ab4 100644 --- a/test/compile/data/timeunit.test.ts +++ b/test/compile/data/timeunit.test.ts @@ -247,7 +247,7 @@ describe('compile/data/timeunit', () => { }); const timeUnitNode = TimeUnitNode.makeFromEncoding(null, model); expect(timeUnitNode.hash()).toBe( - 'TimeUnit {"{\\"as\\":\\"month_a\\",\\"field\\":\\"a\\",\\"timeUnit\\":{\\"unit\\":\\"month\\"}}":{"as":"month_a","field":"a","timeUnit":{"unit":"month"}}}' + "TimeUnit {'{'as':'month_a','field':'a','timeUnit':{'unit':'month'}}':{'as':'month_a','field':'a','timeUnit':{'unit':'month'}}}" ); }); it('should generate the correct hash for bar', () => { @@ -260,7 +260,7 @@ describe('compile/data/timeunit', () => { }); const timeUnitNode = TimeUnitNode.makeFromEncoding(null, model); expect(timeUnitNode.hash()).toBe( - 'TimeUnit {"{\\"as\\":\\"month_a\\",\\"field\\":\\"a\\",\\"timeUnit\\":{\\"unit\\":\\"month\\"}}":{"as":"month_a","field":"a","timeUnit":{"unit":"month"}}}' + "TimeUnit {'{'as':'month_a','field':'a','timeUnit':{'unit':'month'}}':{'as':'month_a','field':'a','timeUnit':{'unit':'month'}}}" ); }); @@ -274,7 +274,7 @@ describe('compile/data/timeunit', () => { }); const timeUnitNode = TimeUnitNode.makeFromEncoding(null, model); expect(timeUnitNode.hash()).toBe( - 'TimeUnit {"{\\"as\\":\\"utcmonth_step_10_a\\",\\"field\\":\\"a\\",\\"timeUnit\\":{\\"step\\":10,\\"unit\\":\\"month\\",\\"utc\\":true}}":{"as":"utcmonth_step_10_a","field":"a","timeUnit":{"step":10,"unit":"month","utc":true}}}' + "TimeUnit {'{'as':'utcmonth_step_10_a','field':'a','timeUnit':{'step':10,'unit':'month','utc':true}}':{'as':'utcmonth_step_10_a','field':'a','timeUnit':{'step':10,'unit':'month','utc':true}}}" ); }); }); diff --git a/test/compile/data/window.test.ts b/test/compile/data/window.test.ts index 49151ed6a8..6a10c409ea 100644 --- a/test/compile/data/window.test.ts +++ b/test/compile/data/window.test.ts @@ -190,7 +190,7 @@ describe('compile/data/window', () => { const window = new WindowTransformNode(null, transform); const hash = window.hash(); expect(hash).toBe( - 'WindowTransform {"frame":[null,0],"groupby":["f"],"ignorePeers":false,"sort":[{"field":"f","order":"ascending"}],"window":[{"as":"ordered_row_number","op":"row_number"}]}' + "WindowTransform {'frame':[null,0],'groupby':['f'],'ignorePeers':false,'sort':[{'field':'f','order':'ascending'}],'window':[{'as':'ordered_row_number','op':'row_number'}]}" ); }); }); diff --git a/test/compile/format.test.ts b/test/compile/format.test.ts index ada7be09f4..5521490f93 100644 --- a/test/compile/format.test.ts +++ b/test/compile/format.test.ts @@ -20,7 +20,7 @@ describe('Format', () => { rawTimeFormat: defaultConfig.timeFormat }); expect(expression).toBe( - 'timeFormat(datum["month_a"], timeUnitSpecifier(["month"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "timeFormat(datum['month_a'], timeUnitSpecifier(['month'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); @@ -32,7 +32,7 @@ describe('Format', () => { format: '%Y', rawTimeFormat: defaultConfig.timeFormat }); - expect(expression).toBe(`timeFormat(datum["yearmonth_a"], '%Y')`); + expect(expression).toBe(`timeFormat(datum['yearmonth_a'], '%Y')`); }); it('should get the right time expression for quarter', () => { @@ -43,7 +43,7 @@ describe('Format', () => { rawTimeFormat: defaultConfig.timeFormat }); expect(expression).toBe( - 'timeFormat(datum["quarter_a"], timeUnitSpecifier(["quarter"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "timeFormat(datum['quarter_a'], timeUnitSpecifier(['quarter'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); @@ -54,7 +54,7 @@ describe('Format', () => { rawTimeFormat: defaultConfig.timeFormat }); expect(expression).toBe( - 'timeFormat(datum["data"], timeUnitSpecifier(["year","quarter"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "timeFormat(datum['data'], timeUnitSpecifier(['year','quarter'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); @@ -67,7 +67,7 @@ describe('Format', () => { rawTimeFormat: defaultConfig.timeFormat, isUTCScale: true }); - expect(expression).toBe(`utcFormat(datum["yearmonth_a"], '%Y')`); + expect(expression).toBe(`utcFormat(datum['yearmonth_a'], '%Y')`); }); it('should get the right time expression for with a custom timeFormatType', () => { @@ -77,7 +77,7 @@ describe('Format', () => { format: '%Y', formatType: 'customFormat' }); - expect(expression).toBe(`customFormat(datum["a"], '%Y')`); + expect(expression).toBe(`customFormat(datum['a'], '%Y')`); }); it('should prefer timeUnit over timeFormatType', () => { @@ -88,7 +88,7 @@ describe('Format', () => { timeUnit: 'date', formatType: 'customFormat' }); - expect(expression).toBe(`timeFormat(datum["date_a"], '%Y')`); + expect(expression).toBe(`timeFormat(datum['date_a'], '%Y')`); }); }); @@ -101,7 +101,7 @@ describe('Format', () => { it('returns the the formatted timeUnitExpression', () => { const formatted = timeFormat({timeUnit: 'date', config: {}}); expect(formatted).toEqual({ - signal: 'timeUnitSpecifier(["date"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "})' + signal: "timeUnitSpecifier(['date'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '})" }); }); @@ -167,7 +167,7 @@ describe('Format', () => { config: {} }) ).toEqual({ - signal: 'format(parent["foo"], ".2f")' + signal: "format(parent['foo'], '.2f')" }); }); @@ -182,7 +182,7 @@ describe('Format', () => { }) ).toEqual({ signal: - '!isValid(parent["bin_maxbins_10_foo"]) || !isFinite(+parent["bin_maxbins_10_foo"]) ? "null" : format(parent["bin_maxbins_10_foo"], "abc") + " – " + format(parent["bin_maxbins_10_foo_end"], "abc")' + "!isValid(parent['bin_maxbins_10_foo']) || !isFinite(+parent['bin_maxbins_10_foo']) ? 'null' : format(parent['bin_maxbins_10_foo'], 'abc') + ' – ' + format(parent['bin_maxbins_10_foo_end'], 'abc')" }); }); @@ -196,7 +196,7 @@ describe('Format', () => { config: {} }) ).toEqual({ - signal: 'format(200, ".2f")' + signal: "format(200, '.2f')" }); }); @@ -238,7 +238,7 @@ describe('Format', () => { config: {timeFormat: 'abc', timeFormatType: 'customFormatter', customFormatTypes: true} }) ).toEqual({ - signal: 'customFormatter(parent["date"], "abc")' + signal: "customFormatter(parent['date'], 'abc')" }); }); @@ -278,7 +278,7 @@ describe('Format', () => { } }) ).toEqual({ - signal: 'customFormatter(200, "abc")' + signal: "customFormatter(200, 'abc')" }); }); }); @@ -335,7 +335,7 @@ describe('Format', () => { false ); expect(format).toEqual({ - signal: 'timeUnitSpecifier(["hours"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "})' + signal: "timeUnitSpecifier(['hours'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '})" }); }); diff --git a/test/compile/header/assemble.test.ts b/test/compile/header/assemble.test.ts index 25fc13103f..1227117935 100644 --- a/test/compile/header/assemble.test.ts +++ b/test/compile/header/assemble.test.ts @@ -99,7 +99,7 @@ describe('compile/header/index', () => { model.parseAxesAndHeaders(); const rowHeaderGroups = assembleHeaderGroups(model, 'row'); - expect(rowHeaderGroups[0].sort.field).toBe('datum["min_d"]'); + expect(rowHeaderGroups[0].sort.field).toBe("datum['min_d']"); }); }); @@ -320,7 +320,7 @@ describe('compile/header/index', () => { } ); - expect(title.text).toEqual({signal: 'parent["foo"][0]'}); + expect(title.text).toEqual({signal: "parent['foo'][0]"}); }); }); }); diff --git a/test/compile/legend/assemble.test.ts b/test/compile/legend/assemble.test.ts index e13affea92..fab96bf1f8 100644 --- a/test/compile/legend/assemble.test.ts +++ b/test/compile/legend/assemble.test.ts @@ -48,7 +48,7 @@ describe('legend/assemble', () => { const legends = model.assembleLegends(); expect(legends[0].encode.labels.update.text).toEqual({ - signal: 'myFormat(datum.value, {"a":"b"})[0]' + signal: "myFormat(datum.value, {'a':'b'})[0]" }); }); diff --git a/test/compile/legend/encode.test.ts b/test/compile/legend/encode.test.ts index d36bbaae7f..71284270d1 100644 --- a/test/compile/legend/encode.test.ts +++ b/test/compile/legend/encode.test.ts @@ -163,7 +163,7 @@ describe('compile/legend', () => { {}, {fieldOrDatumDef: fieldDef, model, channel: COLOR, legendCmpt: symbolLegend, legendType: 'symbol'} ); - expect(label.text).toEqual({signal: 'customDateFormat(datum.value, "abc")'}); + expect(label.text).toEqual({signal: "customDateFormat(datum.value, 'abc')"}); }); }); @@ -183,7 +183,7 @@ describe('compile/legend', () => { {}, {fieldOrDatumDef: fieldDef, model, channel: COLOR, legendCmpt: symbolLegend, legendType: 'symbol'} ); - expect(label.text).toEqual({signal: 'customDateFormat(datum.value, "abc")'}); + expect(label.text).toEqual({signal: "customDateFormat(datum.value, 'abc')"}); }); it('returns correct expression for custom format Type from config.timeFormatType', () => { @@ -202,7 +202,7 @@ describe('compile/legend', () => { {}, {fieldOrDatumDef: fieldDef, model, channel: COLOR, legendCmpt: symbolLegend, legendType: 'symbol'} ); - expect(label.text).toEqual({signal: 'customDateFormat(datum.value, "abc")'}); + expect(label.text).toEqual({signal: "customDateFormat(datum.value, 'abc')"}); }); it('prefers timeUnit over config.timeFormatType', () => { diff --git a/test/compile/mark/encode/valueref.test.ts b/test/compile/mark/encode/valueref.test.ts index e662f3e7c8..0812d65e52 100644 --- a/test/compile/mark/encode/valueref.test.ts +++ b/test/compile/mark/encode/valueref.test.ts @@ -70,7 +70,7 @@ describe('compile/mark/encode/valueref', () => { scale: undefined, defaultRef }); - expect(ref).toEqual({signal: 'scale("x", 0.5 * datum["bin_start"] + 0.5 * datum["bin_end"])'}); + expect(ref).toEqual({signal: "scale('x', 0.5 * datum['bin_start'] + 0.5 * datum['bin_end'])"}); }); }); diff --git a/test/compile/mark/mark.test.ts b/test/compile/mark/mark.test.ts index 00815dedc2..b32c4707e5 100644 --- a/test/compile/mark/mark.test.ts +++ b/test/compile/mark/mark.test.ts @@ -336,7 +336,7 @@ describe('Mark', () => { } }); expect(getSort(model)).toEqual({ - field: ['datum["year"]'], + field: ["datum['year']"], order: ['ascending'] }); }); @@ -375,7 +375,7 @@ describe('Mark', () => { } }); expect(getSort(model)).toEqual({ - field: 'datum["bin_maxbins_10_IMDB_Rating"]' + field: "datum['bin_maxbins_10_IMDB_Rating']" }); }); @@ -416,7 +416,7 @@ describe('Mark', () => { } }); expect(getSort(model)).toEqual({ - field: 'datum["x_Name_sort_index"]' + field: "datum['x_Name_sort_index']" }); }); @@ -434,7 +434,7 @@ describe('Mark', () => { } }); expect(getSort(model)).toEqual({ - field: 'datum["Score"]' + field: "datum['Score']" }); }); diff --git a/test/compile/mark/point.test.ts b/test/compile/mark/point.test.ts index ba91472b95..c2425ee62a 100644 --- a/test/compile/mark/point.test.ts +++ b/test/compile/mark/point.test.ts @@ -104,7 +104,7 @@ describe('Mark: Point', () => { const props = point.encodeEntry(model); - expect(props.x).toEqual({signal: 'scale("x", 0.5 * datum["a_start"] + 0.5 * datum["a_end"])'}); + expect(props.x).toEqual({signal: "scale('x', 0.5 * datum['a_start'] + 0.5 * datum['a_end'])"}); }); it('interpolates binned x with band = 0.6', () => { @@ -121,7 +121,7 @@ describe('Mark: Point', () => { const props = point.encodeEntry(model); expect(props.x).toEqual({ - signal: 'scale("x", 0.4 * datum["bin_maxbins_10_a"] + 0.6 * datum["bin_maxbins_10_a_end"])' + signal: "scale('x', 0.4 * datum['bin_maxbins_10_a'] + 0.6 * datum['bin_maxbins_10_a_end'])" }); }); it('interpolates x timeUnit with timeUnitBand = 0.5', () => { @@ -139,7 +139,7 @@ describe('Mark: Point', () => { }); const props = point.encodeEntry(model); - expect(props.x).toEqual({signal: 'scale("x", 0.5 * datum["year_a"] + 0.5 * datum["year_a_end"])'}); + expect(props.x).toEqual({signal: "scale('x', 0.5 * datum['year_a'] + 0.5 * datum['year_a_end'])"}); }); it('interpolates nominal x on a band scale with band = 0.6', () => { @@ -238,7 +238,7 @@ describe('Mark: Point', () => { it('should test for invalid values on y', () => { expect(props.y).toEqual([ - {field: {group: 'height'}, test: '!isValid(datum["yield"]) || !isFinite(+datum["yield"])'}, + {field: {group: 'height'}, test: "!isValid(datum['yield']) || !isFinite(+datum['yield'])"}, {scale: Y, field: 'yield'} ]); }); diff --git a/test/compile/mark/text.test.ts b/test/compile/mark/text.test.ts index 338b103183..3ab0b37827 100644 --- a/test/compile/mark/text.test.ts +++ b/test/compile/mark/text.test.ts @@ -149,7 +149,7 @@ describe('Mark: Text', () => { }); it('should map to text without template', () => { - expect(props.text).toEqual({signal: `isValid(datum["Origin"]) ? datum["Origin"] : ""+datum["Origin"]`}); + expect(props.text).toEqual({signal: `isValid(datum['Origin']) ? datum['Origin'] : ''+datum['Origin']`}); }); }); @@ -237,14 +237,14 @@ describe('Mark: Text', () => { it('should map text to expression', () => { expect(props.text).toEqual({ - signal: `format(datum["mean_Acceleration"], "")` + signal: `format(datum['mean_Acceleration'], '')` }); }); it('should map color to fill', () => { expect(props.fill).toEqual([ { - test: '!isValid(datum["mean_Acceleration"]) || !isFinite(+datum["mean_Acceleration"])', + test: "!isValid(datum['mean_Acceleration']) || !isFinite(+datum['mean_Acceleration'])", value: null }, { diff --git a/test/compile/scale/domain.test.ts b/test/compile/scale/domain.test.ts index afc4973fa8..292a649740 100644 --- a/test/compile/scale/domain.test.ts +++ b/test/compile/scale/domain.test.ts @@ -665,8 +665,8 @@ describe('compile/scale', () => { const _domain = testParseDomainForChannel(model, 'y'); expect(_domain).toEqual([ - {signal: `{data: datetime("Jan 1, 2007")}`}, - {signal: `{data: datetime("Jan 1, 2009")}`} + {signal: `{data: datetime('Jan 1, 2007')}`}, + {signal: `{data: datetime('Jan 1, 2009')}`} ]); }); @@ -685,8 +685,8 @@ describe('compile/scale', () => { const _domain = testParseDomainForChannel(model, 'y'); expect(_domain).toEqual([ - {signal: `{data: datetime("Jan 1, 2007")}`}, - {signal: `{data: datetime("Jan 1, 2009")}`} + {signal: `{data: datetime('Jan 1, 2007')}`}, + {signal: `{data: datetime('Jan 1, 2009')}`} ]); }); diff --git a/test/compile/signal.test.ts b/test/compile/signal.test.ts index 315398a0ec..f4d266924a 100644 --- a/test/compile/signal.test.ts +++ b/test/compile/signal.test.ts @@ -11,7 +11,7 @@ describe('SignalRefWrapper', () => { }); it('should serialize correctly', () => { - expect(stringify(s)).toBe('{"signal":"hello world"}'); + expect(stringify(s)).toBe("{'signal':'hello world'}"); }); it('should look like a signal', () => { diff --git a/test/timeunit.test.ts b/test/timeunit.test.ts index 80e028bed8..20244b52a5 100644 --- a/test/timeunit.test.ts +++ b/test/timeunit.test.ts @@ -49,73 +49,73 @@ describe('timeUnit', () => { describe('fieldExpr', () => { it('should return correct field expression for yearmonthdatehoursminutesseconds', () => { expect(fieldExpr('yearmonthdatehoursminutesseconds', 'x')).toBe( - 'datetime(year(datum["x"]), month(datum["x"]), date(datum["x"]), hours(datum["x"]), minutes(datum["x"]), seconds(datum["x"]), 0)' + "datetime(year(datum['x']), month(datum['x']), date(datum['x']), hours(datum['x']), minutes(datum['x']), seconds(datum['x']), 0)" ); }); it('should return correct field expression for quarter', () => { - expect(fieldExpr('quarter', 'x')).toBe('datetime(2012, (quarter(datum["x"])-1)*3, 1, 0, 0, 0, 0)'); + expect(fieldExpr('quarter', 'x')).toBe("datetime(2012, (quarter(datum['x'])-1)*3, 1, 0, 0, 0, 0)"); }); it('should return correct field expression for day', () => { - expect(fieldExpr('day', 'x')).toBe('datetime(2012, 0, day(datum["x"])+1, 0, 0, 0, 0)'); + expect(fieldExpr('day', 'x')).toBe("datetime(2012, 0, day(datum['x'])+1, 0, 0, 0, 0)"); }); it('should return correct field expression for milliseconds', () => { - expect(fieldExpr('milliseconds', 'x')).toBe('datetime(2012, 0, 1, 0, 0, 0, milliseconds(datum["x"]))'); + expect(fieldExpr('milliseconds', 'x')).toBe("datetime(2012, 0, 1, 0, 0, 0, milliseconds(datum['x']))"); }); it('should return correct field expression for monthdate', () => { - expect(fieldExpr('monthdate', 'x')).toBe('datetime(2012, month(datum["x"]), date(datum["x"]), 0, 0, 0, 0)'); + expect(fieldExpr('monthdate', 'x')).toBe("datetime(2012, month(datum['x']), date(datum['x']), 0, 0, 0, 0)"); }); it('should return correct field expression with utc for milliseconds', () => { - expect(fieldExpr('utcquarter', 'x')).toBe('datetime(2012, (utcquarter(datum["x"])-1)*3, 1, 0, 0, 0, 0)'); + expect(fieldExpr('utcquarter', 'x')).toBe("datetime(2012, (utcquarter(datum['x'])-1)*3, 1, 0, 0, 0, 0)"); - expect(fieldExpr('utcmilliseconds', 'x')).toBe('datetime(2012, 0, 1, 0, 0, 0, utcmilliseconds(datum["x"]))'); + expect(fieldExpr('utcmilliseconds', 'x')).toBe("datetime(2012, 0, 1, 0, 0, 0, utcmilliseconds(datum['x']))"); }); }); describe('template', () => { it('should return correct template for yearmonthdatehoursminutesseconds', () => { expect(formatExpression('yearmonthdatehoursminutesseconds', 'datum.x', false)).toBe( - 'timeFormat(datum.x, timeUnitSpecifier(["year","month","date","hours","minutes","seconds"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "timeFormat(datum.x, timeUnitSpecifier(['year','month','date','hours','minutes','seconds'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); it('should return correct template for yearmonth (No comma)', () => { expect(formatExpression('yearmonth', 'datum.x', false)).toBe( - 'timeFormat(datum.x, timeUnitSpecifier(["year","month"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "timeFormat(datum.x, timeUnitSpecifier(['year','month'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); it('should return correct template for day', () => { expect(formatExpression('day', 'datum.x', false)).toBe( - 'timeFormat(datum.x, timeUnitSpecifier(["day"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "timeFormat(datum.x, timeUnitSpecifier(['day'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); it('should return correct template for day (shortened)', () => { expect(formatExpression('day', 'datum.x', false)).toBe( - 'timeFormat(datum.x, timeUnitSpecifier(["day"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "timeFormat(datum.x, timeUnitSpecifier(['day'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); it('should return correct template for QUARTER', () => { expect(formatExpression('quarter', 'datum.x', false)).toBe( - 'timeFormat(datum.x, timeUnitSpecifier(["quarter"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "timeFormat(datum.x, timeUnitSpecifier(['quarter'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); it('should return correct template for yearquarter', () => { expect(formatExpression('yearquarter', 'datum.x', false)).toBe( - 'timeFormat(datum.x, timeUnitSpecifier(["year","quarter"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "timeFormat(datum.x, timeUnitSpecifier(['year','quarter'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); it('should return correct template for milliseconds', () => { expect(formatExpression('milliseconds', 'datum.x', false)).toBe( - 'timeFormat(datum.x, timeUnitSpecifier(["milliseconds"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "timeFormat(datum.x, timeUnitSpecifier(['milliseconds'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); @@ -125,13 +125,13 @@ describe('timeUnit', () => { it('should return correct template for yearmonth (No comma) with utc scale', () => { expect(formatExpression('yearmonth', 'datum.x', true)).toBe( - 'utcFormat(datum.x, timeUnitSpecifier(["year","month"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "utcFormat(datum.x, timeUnitSpecifier(['year','month'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); it('should return correct template for utcyearmonth (No comma)', () => { expect(formatExpression('utcyearmonth', 'datum.x', true)).toBe( - 'utcFormat(datum.x, timeUnitSpecifier(["year","month"], {"year-month":"%b %Y ","year-month-date":"%b %d, %Y "}))' + "utcFormat(datum.x, timeUnitSpecifier(['year','month'], {'year-month':'%b %Y ','year-month-date':'%b %d, %Y '}))" ); }); }); diff --git a/test/util.test.ts b/test/util.test.ts index 852bc39bc6..65a761d259 100644 --- a/test/util.test.ts +++ b/test/util.test.ts @@ -45,11 +45,11 @@ describe('util', () => { }); it('stringifies strings', () => { - expect(stringify('foo')).toBe('"foo"'); + expect(stringify('foo')).toBe("'foo'"); }); it('stringifies objects', () => { - expect(stringify({foo: 42})).toBe('{"foo":42}'); + expect(stringify({foo: 42})).toBe("{'foo':42}"); }); }); @@ -67,7 +67,7 @@ describe('util', () => { }); it('hashes objects', () => { - expect(hash({foo: 42})).toBe('{"foo":42}'); + expect(hash({foo: 42})).toBe("{'foo':42}"); }); }); @@ -142,19 +142,19 @@ describe('util', () => { describe('flatAccessWithDatum', () => { it('should parse foo.bar', () => { - expect(flatAccessWithDatum('foo.bar')).toBe('datum["foo.bar"]'); + expect(flatAccessWithDatum('foo.bar')).toBe("datum['foo.bar']"); }); it('should return string value of field name', () => { - expect(flatAccessWithDatum('foo["bar"].baz')).toBe('datum["foo.bar.baz"]'); + expect(flatAccessWithDatum('foo["bar"].baz')).toBe("datum['foo.bar.baz']"); }); it('should support custom datum', () => { - expect(flatAccessWithDatum('foo', 'parent')).toBe('parent["foo"]'); + expect(flatAccessWithDatum('foo', 'parent')).toBe("parent['foo']"); }); it('should support escaped brackets', () => { - expect(flatAccessWithDatum('y\\[foo\\]')).toBe('datum["y[foo]"]'); + expect(flatAccessWithDatum('y\\[foo\\]')).toBe("datum['y[foo]']"); }); }); From ccfafffaaa85338bd1205a1ed38679d60d5a99b5 Mon Sep 17 00:00:00 2001 From: liminge Date: Sun, 18 Feb 2024 01:07:06 -0500 Subject: [PATCH 4/4] Is this modification aligned with the expectation? --- test/compile/mark/encoding/aria.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/compile/mark/encoding/aria.test.ts b/test/compile/mark/encoding/aria.test.ts index a26aaa3c3a..aaf1a803f8 100644 --- a/test/compile/mark/encoding/aria.test.ts +++ b/test/compile/mark/encoding/aria.test.ts @@ -23,7 +23,7 @@ describe('compile/mark/encoding/aria', () => { expect(ariaMixins).toEqual({ description: { signal: - '"category: " + (isValid(datum["category"]) ? datum["category"] : ""+datum["category"]) + "; value: " + (format(datum["value"], ""))' + "\"category: \" + (isValid(datum['category']) ? datum['category'] : \"\"+datum['category']) + \"; value: \" + (format(datum['value'], \"\"))" }, ariaRoleDescription: { value: 'bar' @@ -125,7 +125,7 @@ describe('compile/mark/encoding/aria', () => { value: 'mark' }, description: { - signal: '"category: " + (isValid(datum["category"]) ? datum["category"] : ""+datum["category"])' + signal: "\"category: \" + (isValid(datum['category']) ? datum['category'] : \"\"+datum['category'])" } }); });