Skip to content

Commit bb119c5

Browse files
committed
Add rudimentary tests for cljParser.getNamespace
These are fairly minimal, just testing one function in a table-driven style, but hopefully they can give us some confidence next time we update the parsing regex. I've tried to test tabs, newlines, spaces, and a few optional parameters to 'ns', making sure that we're robust to all of these. Also added one test that checks we work with the 'in-ns' form. You can run these tests from VS Code's debug tag using the 'Launch Tests' task. Later on, we could work at getting these tests to run without spinning up an entire VS Code instance (they're unit tests, they shouldn't need a VS Code UI to run).
1 parent a77f59f commit bb119c5

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

test/cljParser.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as assert from 'assert';
2+
import {cljParser} from '../src/cljParser';
3+
4+
suite('cljParser', () => {
5+
let cases = [
6+
['user', ''],
7+
['foo', '(ns foo)'],
8+
['foo', '\n(ns foo)'],
9+
['foo', '\t(ns foo)'],
10+
['foo', '\t(ns\tfoo)'],
11+
['foo-bar', '(ns foo-bar)'],
12+
['bar', '(ns bar)'],
13+
['baz', '(ns baz "docstring")'],
14+
['qux', `(ns qux
15+
"docstring")`],
16+
['foo.bar', '(ns foo.bar)'],
17+
['foo.bar-baz', '(ns foo.bar-baz)'],
18+
['foo.bar', `(ns foo.bar
19+
(:refer-clojure :exclude [ancestors printf])
20+
(:require (clojure.contrib sql combinatorics))
21+
(:use (my.lib this that))
22+
(:import (java.util Date Timer Random)
23+
(java.sql Connection Statement)))`],
24+
['bar', '(in-ns \'bar)'],
25+
];
26+
for (let [want, input] of cases) {
27+
test(`getNamespace("${input}") should be "${want}"`, () => {
28+
assert.equal(cljParser.getNamespace(input), want);
29+
});
30+
}
31+
});

0 commit comments

Comments
 (0)