-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathjsx-tests.js
54 lines (48 loc) · 1.36 KB
/
jsx-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
53
54
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>',
'(<div />) < x'
];
var results = [
'React.DOM.a(null)',
'React.DOM.a({ v: true })',
"React.DOM.a({ foo: 'bar' }, ' ', value, ' ', React.DOM.b(null, c(null)))",
"React.DOM.a({ b: ' ', c: ' ', d: '&'})",
'React.DOM.a(null)',
"AbC-def({\n test: '&&' }, \n'bar' + ' ' +\n 'baz'\n)",
'React.DOM.a({ b: x ? c(null) : d(null) })',
'React.DOM.a(null)',
"React.DOM.div(null, '@test content')",
"React.DOM.div(null, React.DOM.br(null), '7x invalid-js-identifier')",
'a.b(null)',
'a.b.c(null)',
'React.DOM.div(null) < x'
];
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');