1'use strict';
2
3var assert = require('assert');
4var testit = require('testit');
5var isExpression = require('./');
6
7function passes(src, options) {
8  testit(JSON.stringify(src, options), function () {
9    options = options || {};
10    assert(isExpression(src, options));
11  });
12}
13
14testit('passes', function () {
15  passes('myVar');
16  passes('["an", "array", "\'s"].indexOf("index")');
17  passes('\npublic');
18  passes('abc // my comment', {lineComment: true});
19  passes('() => a');
20  passes('function (a = "default") {"use strict";}', {ecmaVersion: 6});
21});
22
23function error(src, line, col, options) {
24  testit(JSON.stringify(src), function () {
25    options = options || {};
26    assert(!isExpression(src, options));
27    options.throw = true;
28    assert.throws(function () {
29      isExpression(src, options);
30    }, function (err) {
31      assert.equal(err.loc.line, line);
32      assert.equal(err.loc.column, col);
33      assert(err.message);
34      return true;
35    });
36  });
37}
38
39testit('fails', function () {
40  error('', 1, 0);
41  error('var', 1, 0);
42  error('weird error', 1, 6);
43  error('asdf}', 1, 4);
44  error('\npublic', 2, 0, {strict: true});
45  error('abc // my comment', 1, 4);
46  error('() => a', 1, 1, {ecmaVersion: 5});
47  error('function (a = "default") {"use strict";}', 1, 26);
48});
49