11import { compile } from '../../../packages/weex-template-compiler'
2+ import { strToRegExp } from '../helpers/index'
23
34describe ( 'compile basic' , ( ) => {
45 it ( 'should be compiled' , ( ) => {
@@ -29,6 +30,36 @@ describe('compile basic', () => {
2930 expect ( errors ) . toEqual ( [ ] )
3031 } )
3132
33+ it ( 'should compile unary tag' , ( ) => {
34+ const inputCase = compile ( `<div><input><text>abc</text></div>` )
35+ expect ( inputCase . render ) . toMatch ( strToRegExp ( `return _m(0)` ) )
36+ expect ( inputCase . staticRenderFns ) . toMatch ( strToRegExp ( `_c('div',[_c('input'),_c('text',[_v("abc")])])` ) )
37+ expect ( inputCase . errors ) . toEqual ( [ ] )
38+
39+ const imageCase = compile ( `<div><image src="path"><text>abc</text></div>` )
40+ expect ( imageCase . render ) . toMatch ( strToRegExp ( `return _m(0)` ) )
41+ expect ( imageCase . staticRenderFns ) . toMatch ( strToRegExp ( `_c('div',[_c('image',{attrs:{"src":"path"}}),_c('text',[_v("abc")])])` ) )
42+ expect ( imageCase . errors ) . toEqual ( [ ] )
43+
44+ const complexCase = compile ( `
45+ <div>
46+ <image src="path">
47+ <image></image>
48+ <div>
49+ <embed>
50+ <text>start</text>
51+ <input type="text">
52+ <input type="url" />
53+ <text>end</text>
54+ </div>
55+ </div>
56+ ` )
57+ expect ( complexCase . render ) . toMatch ( strToRegExp ( `return _m(0)` ) )
58+ expect ( complexCase . staticRenderFns ) . toMatch ( strToRegExp ( `_c('image',{attrs:{"src":"path"}}),_c('image'),_c('div'` ) )
59+ expect ( complexCase . staticRenderFns ) . toMatch ( strToRegExp ( `_c('div',[_c('embed'),_c('text',[_v("start")]),_c('input',{attrs:{"type":"text"}}),_c('input',{attrs:{"type":"url"}}),_c('text',[_v("end")])]` ) )
60+ expect ( complexCase . errors ) . toEqual ( [ ] )
61+ } )
62+
3263 it ( 'should compile more complex situation' , ( ) => {
3364 // from examples of https://github.com/alibaba/weex
3465 const { render, staticRenderFns, errors } = compile ( `
@@ -38,7 +69,7 @@ describe('compile basic', () => {
3869 <text style="margin-left:36px;color:#eee;">Load more...</text>
3970 </refresh>
4071 ` )
41- expect ( render ) . toEqual ( `with(this){return _c('refresh',{staticClass:["refresh"],staticStyle:{flexDirection:"row"},attrs:{"display":displayRefresh},on:{"refresh":handleRefresh}},[_c('loading-indicator'),_c('text',{staticStyle:{marginLeft:"36px",color:"#eee"}},[_v("Load more...")])],1 )}` )
72+ expect ( render ) . toEqual ( `with(this){return _c('refresh',{staticClass:["refresh"],staticStyle:{flexDirection:"row"},attrs:{"display":displayRefresh},on:{"refresh":handleRefresh}},[_c('loading-indicator'),_c('text',{staticStyle:{marginLeft:"36px",color:"#eee"}},[_v("Load more...")])])}` )
4273 expect ( staticRenderFns ) . toEqual ( [ ] )
4374 expect ( errors ) . toEqual ( [ ] )
4475 } )
0 commit comments