forked from jlongster/jsx-reader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmsx-tests.js
52 lines (46 loc) · 1.29 KB
/
msx-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var fs = require('fs');
var sweet = require('sweet.js');
sweet.setReadtable('./index.js');
var tests = [
'<a />',
'<a v />',
'<a foo="bar"> {value} <b><c /></b></a>',
'<a b={" "} c=" " d="&" />',
'<a\n/>',
'<AbC-def\n test="&&">\nbar\nbaz\n</AbC-def>',
'<a b={x ? <c /> : <d />} />',
'<a>{}</a>',
'<div>@test content</div>',
'<div><br />7x invalid-js-identifier</div>',
'<a.b></a.b>',
'<a.b.c></a.b.c>'
];
var results = [
"m('a', null)",
"m('a', { v: true })",
"m('a', { foo: 'bar' }, [ ' ', value, ' ', m('b', null, [m('c', null)])])",
"m('a', { b: ' ', c: ' ', d: '&'})",
"m('a', null)",
"m('AbC-def', { test: '&&' }, ['bar' + ' ' + 'baz'])",
"m('a', { b: x ? m('c', null) : m('d', null) })",
"m('a', null)",
"m('div', null, ['@test content'])",
"m('div', null, [ m('br', null), '7x invalid-js-identifier'])",
"m('a.b', null)",
"m('a.b.c', null)"
];
tests.forEach(function(test, i) {
var code = sweet.compile(test).code;
code = code.trim()
.replace(/;$/, '')
.replace(/\n/g, '')
.replace(/ +/g, ' ');
var result = results[i]
.replace(/\n/g, '')
.replace(/ +/g, ' ');
if(code !== result) {
throw new Error('Failed: expected ' + result +
' but got ' + code);
}
});
console.log('passed');