Skip to content

Commit 633e7dc

Browse files
committed
re-enable reference tests
1 parent 1a4ec48 commit 633e7dc

File tree

2 files changed

+59
-67
lines changed

2 files changed

+59
-67
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"node": ">=14.5.0"
2929
},
3030
"scripts": {
31-
"test": "mkdir -p test/output && mocha -r module-alias/register 'test/**/parse-test.js' && eslint src test",
31+
"test": "mkdir -p test/output && mocha -r module-alias/register 'test/**/*-test.js' && eslint src test",
3232
"prepublishOnly": "rm -rf dist && rollup -c",
3333
"postpublish": "git push && git push --tags"
3434
},

test/references-test.js

Lines changed: 58 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,106 @@
1-
import {test} from "tap";
2-
import {parseCell} from "../src/index.js";
1+
import assert from "assert";
2+
import {parseCell} from "@observablehq/parser";
3+
import {Node} from "acorn";
34

4-
test("finds references in expressions", t => {
5-
t.deepEqual(parseCell(`foo + bar`).references, [
6-
{type: "Identifier", start: 0, end: 3, name: "foo"},
7-
{type: "Identifier", start: 6, end: 9, name: "bar"}
5+
function node(fields) {
6+
return Object.assign(Object.create(Node.prototype), fields);
7+
}
8+
9+
it("finds references in expressions", () => {
10+
assert.deepStrictEqual(parseCell(`foo + bar`).references, [
11+
node({type: "Identifier", start: 0, end: 3, name: "foo"}),
12+
node({type: "Identifier", start: 6, end: 9, name: "bar"})
813
]);
9-
t.end();
1014
});
1115

12-
test("finds references in blocks", t => {
13-
t.deepEqual(parseCell(`{ foo + bar; }`).references, [
14-
{type: "Identifier", start: 2, end: 5, name: "foo"},
15-
{type: "Identifier", start: 8, end: 11, name: "bar"}
16+
it("finds references in blocks", () => {
17+
assert.deepStrictEqual(parseCell(`{ foo + bar; }`).references, [
18+
node({type: "Identifier", start: 2, end: 5, name: "foo"}),
19+
node({type: "Identifier", start: 8, end: 11, name: "bar"})
1620
]);
17-
t.end();
1821
});
1922

20-
test("finds viewof references", t => {
21-
t.deepEqual(parseCell(`viewof foo + bar`).references, [
22-
{
23+
it("finds viewof references", () => {
24+
assert.deepStrictEqual(parseCell(`viewof foo + bar`).references, [
25+
node({
2326
type: "ViewExpression",
2427
start: 0,
2528
end: 10,
26-
id: {type: "Identifier", start: 7, end: 10, name: "foo"}
27-
},
28-
{type: "Identifier", start: 13, end: 16, name: "bar"}
29+
id: node({type: "Identifier", start: 7, end: 10, name: "foo"})
30+
}),
31+
node({type: "Identifier", start: 13, end: 16, name: "bar"})
2932
]);
30-
t.end();
3133
});
3234

33-
test("finds mutable references", t => {
34-
t.deepEqual(parseCell(`mutable foo + bar`).references, [
35-
{
35+
it.only("finds mutable references", () => {
36+
assert.deepStrictEqual(parseCell(`mutable foo + bar`).references, [
37+
node({
3638
type: "MutableExpression",
3739
start: 0,
3840
end: 11,
39-
id: {type: "Identifier", start: 8, end: 11, name: "foo"}
40-
},
41-
{type: "Identifier", start: 14, end: 17, name: "bar"}
41+
id: node({type: "Identifier", start: 8, end: 11, name: "foo"})
42+
}),
43+
node({type: "Identifier", start: 14, end: 17, name: "bar"})
4244
]);
43-
t.end();
4445
});
4546

46-
test("finds multiple references", t => {
47-
t.deepEqual(parseCell(`cell = {
47+
it("finds multiple references", () => {
48+
assert.deepStrictEqual(parseCell(`cell = {
4849
const a = b + c;
4950
const d = c - b;
5051
}`).references, [
51-
{type: "Identifier", start: 21, end: 22, name: "b"},
52-
{type: "Identifier", start: 25, end: 26, name: "c"},
53-
{type: "Identifier", start: 40, end: 41, name: "c"},
54-
{type: "Identifier", start: 44, end: 45, name: "b"}
52+
node({type: "Identifier", start: 21, end: 22, name: "b"}),
53+
node({type: "Identifier", start: 25, end: 26, name: "c"}),
54+
node({type: "Identifier", start: 40, end: 41, name: "c"}),
55+
node({type: "Identifier", start: 44, end: 45, name: "b"})
5556
]);
56-
t.end();
5757
});
5858

59-
test("doesn’t consider the identifier a reference", t => {
60-
t.deepEqual(parseCell(`foo = bar`).references, [
61-
{type: "Identifier", start: 6, end: 9, name: "bar"}
59+
it("doesn’t consider the identifier a reference", () => {
60+
assert.deepStrictEqual(parseCell(`foo = bar`).references, [
61+
node({type: "Identifier", start: 6, end: 9, name: "bar"})
6262
]);
63-
t.end();
6463
});
6564

66-
test("local variables can mask references", t => {
67-
t.deepEqual(parseCell(`{ let foo; foo + bar; }`).references, [
68-
{type: "Identifier", start: 17, end: 20, name: "bar"}
65+
it("local variables can mask references", () => {
66+
assert.deepStrictEqual(parseCell(`{ let foo; foo + bar; }`).references, [
67+
node({type: "Identifier", start: 17, end: 20, name: "bar"})
6968
]);
70-
t.end();
7169
});
7270

73-
test("local variables can not mask references", t => {
74-
t.deepEqual(parseCell(`{ foo + bar; { let foo; } }`).references, [
75-
{type: "Identifier", start: 2, end: 5, name: "foo"},
76-
{type: "Identifier", start: 8, end: 11, name: "bar"}
71+
it("local variables can not mask references", () => {
72+
assert.deepStrictEqual(parseCell(`{ foo + bar; { let foo; } }`).references, [
73+
node({type: "Identifier", start: 2, end: 5, name: "foo"}),
74+
node({type: "Identifier", start: 8, end: 11, name: "bar"})
7775
]);
78-
t.end();
7976
});
8077

81-
test("function parameters can mask references", t => {
82-
t.deepEqual(parseCell(`foo => foo + bar`).references, [
83-
{type: "Identifier", start: 13, end: 16, name: "bar"}
78+
it("function parameters can mask references", () => {
79+
assert.deepStrictEqual(parseCell(`foo => foo + bar`).references, [
80+
node({type: "Identifier", start: 13, end: 16, name: "bar"})
8481
]);
85-
t.end();
8682
});
8783

88-
test("function rest parameters can mask references", t => {
89-
t.deepEqual(parseCell(`(...foo) => foo + bar`).references, [
90-
{type: "Identifier", start: 18, end: 21, name: "bar"}
84+
it("function rest parameters can mask references", () => {
85+
assert.deepStrictEqual(parseCell(`(...foo) => foo + bar`).references, [
86+
node({type: "Identifier", start: 18, end: 21, name: "bar"})
9187
]);
92-
t.end();
9388
});
9489

95-
test("destructured variables can mask references", t => {
96-
t.deepEqual(parseCell(`{ let {foo} = null; foo + bar; }`).references, [
97-
{type: "Identifier", start: 26, end: 29, name: "bar"}
90+
it("destructured variables can mask references", () => {
91+
assert.deepStrictEqual(parseCell(`{ let {foo} = null; foo + bar; }`).references, [
92+
node({type: "Identifier", start: 26, end: 29, name: "bar"})
9893
]);
99-
t.end();
10094
});
10195

102-
test("destructured rest variables can mask references", t => {
103-
t.deepEqual(parseCell(`{ let {...foo} = null; foo + bar; }`).references, [
104-
{type: "Identifier", start: 29, end: 32, name: "bar"}
96+
it("destructured rest variables can mask references", () => {
97+
assert.deepStrictEqual(parseCell(`{ let {...foo} = null; foo + bar; }`).references, [
98+
node({type: "Identifier", start: 29, end: 32, name: "bar"})
10599
]);
106-
t.end();
107100
});
108101

109-
test("ignores globals", t => {
110-
t.deepEqual(parseCell(`foo + bar`, {globals: ["foo"]}).references, [
111-
{type: "Identifier", start: 6, end: 9, name: "bar"}
102+
it("ignores globals", () => {
103+
assert.deepStrictEqual(parseCell(`foo + bar`, {globals: ["foo"]}).references, [
104+
node({type: "Identifier", start: 6, end: 9, name: "bar"})
112105
]);
113-
t.end();
114106
});

0 commit comments

Comments
 (0)