parser tests

This commit is contained in:
Scott Davis 2016-11-23 17:10:56 -05:00
parent 62c5a1e5ee
commit 219f9cd744
7 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,13 @@
[
{
"name": "greetings",
"value": "require(\"./greetings\")"
},
{
"name": "hi",
"value":{
"object": "greetings",
"property": "hello"
}
}
]

View File

@ -0,0 +1 @@
import { hello as hi } from "./greetings"

View File

@ -0,0 +1,13 @@
[
{
"name": "$",
"value": "require(\"jquery\")"
},
{
"name": "fn",
"value": {
"object": "$",
"property": "fn"
}
}
]

View File

@ -0,0 +1 @@
import $, { fn } from "jquery"

View File

@ -0,0 +1,6 @@
[
{
"name": "$",
"value": "require(\"jquery\")"
}
]

View File

@ -0,0 +1 @@
import $ from "jquery"

37
test/parseImport-test.js Normal file
View File

@ -0,0 +1,37 @@
'use strict';
require('./util/patch-module');
var chai = require('chai');
chai.config.includeStack = true;
var parseFor = require('../taglibs/core/util/parseImport.js');
var autotest = require('./autotest');
var fs = require('fs');
var path = require('path');
describe('parseImport' , function() {
var autoTestDir = path.join(__dirname, 'autotests/parseImport');
autotest.scanDir(
autoTestDir,
function run(dir, helpers, done) {
let inputPath = path.join(dir, 'input.txt');
let input = fs.readFileSync(inputPath, {encoding: 'utf8'});
try {
let parsed = parseFor(input);
helpers.compare(parsed, '.json');
return done();
} catch(e) {
if (e.code === 'INVALID_FOR') {
helpers.compare({
error: e.message
}, '.json');
return done();
} else {
throw e;
}
}
});
});