Skip to content

Commit a39ba07

Browse files
committed
test: run evaluateSync in tests
1 parent 143e9e1 commit a39ba07

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/evaluator/operators.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const operators: {[key in OpCall]: GroqOperatorFn} = {
7474
},
7575

7676
// eslint-disable-next-line func-name-matching
77-
'in': async function inop(left, right) {
77+
'in': function inop(left, right) {
7878
if (right.type === 'path') {
7979
if (left.type !== 'string') {
8080
return NULL_VALUE
@@ -83,16 +83,28 @@ export const operators: {[key in OpCall]: GroqOperatorFn} = {
8383
return right.data.matches(left.data) ? TRUE_VALUE : FALSE_VALUE
8484
}
8585

86-
if (right.isArray()) {
87-
for await (const b of right) {
88-
if (isEqual(left, b)) {
86+
if (right.type === 'array') {
87+
for (const b of right.data) {
88+
if (isEqual(left, fromJS(b))) {
8989
return TRUE_VALUE
9090
}
9191
}
9292

9393
return FALSE_VALUE
9494
}
9595

96+
if (right.type === 'stream') {
97+
return (async () => {
98+
for await (const b of right) {
99+
if (isEqual(left, b)) {
100+
return TRUE_VALUE
101+
}
102+
}
103+
104+
return FALSE_VALUE
105+
})()
106+
}
107+
96108
return NULL_VALUE
97109
},
98110

test/generate.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const DISABLED_TESTS = [
1818
/score\(\) function \/ Illegal use/, // we're missing validation here
1919
]
2020

21+
const IS_SYNCHRONOUS = (test) => !/changed(Any|Only)/.test(test.query)
22+
2123
const WHITESPACE_REGEX = /\s+/g
2224

2325
const OUTPUT = process.stdout
@@ -48,7 +50,7 @@ function space() {
4850
write(`const fs = require('fs')`)
4951
write(`const ndjson = require('ndjson')`)
5052
write(`const tap = require('tap')`)
51-
write(`const {evaluate, parse} = require('../src/1')`)
53+
write(`const {evaluate, parse, evaluateSync, toJS} = require('../src/1')`)
5254
space()
5355

5456
write(`tap.setTimeout(0)`)
@@ -233,6 +235,13 @@ process.stdin
233235
write(`data = JSON.parse(JSON.stringify(data))`)
234236
write(`replaceScoreWithPos(data)`)
235237
write(`tt.match(data, result)`)
238+
if (IS_SYNCHRONOUS(entry)) {
239+
write(`// Sync`)
240+
write(`let syncValue = evaluateSync(tree, {dataset, params})`)
241+
write(`let syncData = toJS(syncValue)`)
242+
write(`replaceScoreWithPos(syncData)`)
243+
write(`tt.match(syncData, result)`)
244+
}
236245
} else {
237246
write(`tt.throws(() => parse(query))`)
238247
}

0 commit comments

Comments
 (0)