@@ -10,61 +10,149 @@ import { HAS_NATIVE_SYMBOL } from '@ember/-internals/utils';
10
10
import { constructStyleDeprecationMessage } from '@ember/-internals/views' ;
11
11
import { Component , SafeString , htmlSafe } from '../utils/helpers' ;
12
12
13
- moduleFor (
14
- 'Static content tests' ,
15
- class extends RenderingTestCase {
16
- [ '@test it can render a static text node' ] ( ) {
17
- this . render ( 'hello' ) ;
18
- let text1 = this . assertTextNode ( this . firstChild , 'hello' ) ;
13
+ const EMPTY = Object . freeze ( { } ) ;
19
14
20
- runTask ( ( ) => this . rerender ( ) ) ;
15
+ const LITERALS = [
16
+ [ 'foo' , 'foo' , '"foo"' ] ,
17
+ [ undefined , EMPTY ] ,
18
+ [ null , EMPTY ] ,
19
+ [ true , 'true' ] ,
20
+ [ false , 'false' ] ,
21
+ [ 0 , '0' ] ,
22
+ [ - 0 , '0' , '-0' ] ,
23
+ [ 1 , '1' ] ,
24
+ [ - 1 , '-1' ] ,
25
+ [ 0.0 , '0' , '0.0' ] ,
26
+ [ 0.5 , '0.5' , '0.5' ] ,
27
+ [ 0.5 , '0.5' , '0.500000000000000000000000000000' ] ,
28
+
29
+ // Kris Selden: that is a good one because it is above that 3 bit area,
30
+ // but the shifted < 0 check doesn't return true:
31
+ // https://github.com/glimmerjs/glimmer-vm/blob/761e78b2bef5de8b9b19ae5fb296380c21959ef8/packages/%40glimmer/opcode-compiler/lib/opcode-builder/encoder.ts#L277
32
+ [ 536870912 , '536870912' ] ,
33
+
34
+ // Kris Selden: various other 10000000 and 1111111 combos
35
+ [ 4294967296 , '4294967296' ] ,
36
+ [ 4294967295 , '4294967295' ] ,
37
+ [ 4294967294 , '4294967294' ] ,
38
+ [ 536870913 , '536870913' ] ,
39
+ [ 536870911 , '536870911' ] ,
40
+ [ 268435455 , '268435455' ] ,
41
+ ] ;
42
+
43
+ let i = Number . MAX_SAFE_INTEGER ;
44
+
45
+ while ( i > 1 ) {
46
+ LITERALS . push ( [ i , `${ i } ` , `${ i } ` ] ) ;
47
+ i = Math . round ( i / 2 ) ;
48
+ }
21
49
22
- let text2 = this . assertTextNode ( this . firstChild , 'hello' ) ;
50
+ i = Number . MIN_SAFE_INTEGER ;
23
51
24
- this . assertSameNode ( text1 , text2 ) ;
25
- }
52
+ while ( i < - 1 ) {
53
+ LITERALS . push ( [ i , `${ i } ` , `${ i } ` ] ) ;
54
+ i = Math . round ( i / 2 ) ;
55
+ }
26
56
27
- [ '@test it can render a static element' ] ( ) {
28
- this . render ( '<p>hello</p>' ) ;
29
- let p1 = this . assertElement ( this . firstChild , { tagName : 'p' } ) ;
30
- let text1 = this . assertTextNode ( this . firstChild . firstChild , 'hello' ) ;
57
+ class StaticContentTest extends RenderingTestCase {
58
+ [ '@test it can render a static text node' ] ( ) {
59
+ this . render ( 'hello' ) ;
60
+ let text1 = this . assertTextNode ( this . firstChild , 'hello' ) ;
31
61
32
- runTask ( ( ) => this . rerender ( ) ) ;
62
+ runTask ( ( ) => this . rerender ( ) ) ;
33
63
34
- let p2 = this . assertElement ( this . firstChild , { tagName : 'p' } ) ;
35
- let text2 = this . assertTextNode ( this . firstChild . firstChild , 'hello' ) ;
64
+ let text2 = this . assertTextNode ( this . firstChild , 'hello' ) ;
36
65
37
- this . assertSameNode ( p1 , p2 ) ;
38
- this . assertSameNode ( text1 , text2 ) ;
39
- }
66
+ this . assertSameNode ( text1 , text2 ) ;
67
+ }
40
68
41
- [ '@test it can render a static template' ] ( ) {
42
- let template = `
43
- <div class="header">
44
- <h1>Welcome to Ember.js</h1>
45
- </div>
46
- <div class="body">
47
- <h2>Why you should use Ember.js?</h2>
48
- <ol>
49
- <li>It's great</li>
50
- <li>It's awesome</li>
51
- <li>It's Ember.js</li>
52
- </ol>
53
- </div>
54
- <div class="footer">
55
- Ember.js is free, open source and always will be.
56
- </div>
57
- ` ;
69
+ [ '@test it can render a static element' ] ( ) {
70
+ this . render ( '<p>hello</p>' ) ;
71
+ let p1 = this . assertElement ( this . firstChild , { tagName : 'p' } ) ;
72
+ let text1 = this . assertTextNode ( this . firstChild . firstChild , 'hello' ) ;
58
73
59
- this . render ( template ) ;
60
- this . assertHTML ( template ) ;
74
+ runTask ( ( ) => this . rerender ( ) ) ;
61
75
62
- runTask ( ( ) => this . rerender ( ) ) ;
76
+ let p2 = this . assertElement ( this . firstChild , { tagName : 'p' } ) ;
77
+ let text2 = this . assertTextNode ( this . firstChild . firstChild , 'hello' ) ;
63
78
64
- this . assertHTML ( template ) ;
65
- }
79
+ this . assertSameNode ( p1 , p2 ) ;
80
+ this . assertSameNode ( text1 , text2 ) ;
66
81
}
67
- ) ;
82
+
83
+ [ '@test it can render a static template' ] ( ) {
84
+ let template = `
85
+ <div class="header">
86
+ <h1>Welcome to Ember.js</h1>
87
+ </div>
88
+ <div class="body">
89
+ <h2>Why you should use Ember.js?</h2>
90
+ <ol>
91
+ <li>It's great</li>
92
+ <li>It's awesome</li>
93
+ <li>It's Ember.js</li>
94
+ </ol>
95
+ </div>
96
+ <div class="footer">
97
+ Ember.js is free, open source and always will be.
98
+ </div>
99
+ ` ;
100
+
101
+ this . render ( template ) ;
102
+ this . assertHTML ( template ) ;
103
+
104
+ runTask ( ( ) => this . rerender ( ) ) ;
105
+
106
+ this . assertHTML ( template ) ;
107
+ }
108
+ }
109
+
110
+ class StaticContentTestGenerator {
111
+ constructor ( cases , tag = '@test' ) {
112
+ this . cases = cases ;
113
+ this . tag = tag ;
114
+ }
115
+
116
+ generate ( [ value , expected , label ] ) {
117
+ let tag = this . tag ;
118
+ label = label || value ;
119
+
120
+ return {
121
+ [ `${ tag } rendering {{${ label } }}` ] ( ) {
122
+ this . render ( `{{${ label } }}` ) ;
123
+
124
+ if ( expected === EMPTY ) {
125
+ this . assertHTML ( '' ) ;
126
+ } else {
127
+ this . assertHTML ( expected ) ;
128
+ }
129
+
130
+ this . assertStableRerender ( ) ;
131
+ } ,
132
+
133
+ [ `${ tag } rendering {{to-js ${ label } }}` ] ( assert ) {
134
+ this . registerHelper ( 'to-js' , ( [ actual ] ) => {
135
+ assert . strictEqual ( actual , value ) ;
136
+ return actual ;
137
+ } ) ;
138
+
139
+ this . render ( `{{to-js ${ label } }}` ) ;
140
+
141
+ if ( expected === EMPTY ) {
142
+ this . assertHTML ( '' ) ;
143
+ } else {
144
+ this . assertHTML ( expected ) ;
145
+ }
146
+
147
+ this . assertStableRerender ( ) ;
148
+ } ,
149
+ } ;
150
+ }
151
+ }
152
+
153
+ applyMixins ( StaticContentTest , new StaticContentTestGenerator ( LITERALS ) ) ;
154
+
155
+ moduleFor ( 'Static content tests' , StaticContentTest ) ;
68
156
69
157
class DynamicContentTest extends RenderingTestCase {
70
158
/* abstract */
@@ -588,9 +676,7 @@ class DynamicContentTest extends RenderingTestCase {
588
676
}
589
677
}
590
678
591
- const EMPTY = { } ;
592
-
593
- class ContentTestGenerator {
679
+ class DynamicContentTestGenerator {
594
680
constructor ( cases , tag = '@test' ) {
595
681
this . cases = cases ;
596
682
this . tag = tag ;
@@ -639,18 +725,8 @@ class ContentTestGenerator {
639
725
}
640
726
}
641
727
642
- const SharedContentTestCases = new ContentTestGenerator ( [
643
- [ 'foo' , 'foo' ] ,
644
- [ 0 , '0' ] ,
645
- [ - 0 , '0' , '-0' ] ,
646
- [ 1 , '1' ] ,
647
- [ - 1 , '-1' ] ,
648
- [ 0.0 , '0' , '0.0' ] ,
649
- [ 0.5 , '0.5' ] ,
650
- [ undefined , EMPTY ] ,
651
- [ null , EMPTY ] ,
652
- [ true , 'true' ] ,
653
- [ false , 'false' ] ,
728
+ const SharedContentTestCases = new DynamicContentTestGenerator ( [
729
+ ...LITERALS ,
654
730
[ NaN , 'NaN' ] ,
655
731
[ new Date ( 2000 , 0 , 1 ) , String ( new Date ( 2000 , 0 , 1 ) ) , 'a Date object' ] ,
656
732
[ Infinity , 'Infinity' ] ,
@@ -679,7 +755,7 @@ const SharedContentTestCases = new ContentTestGenerator([
679
755
[ '<b>Max</b><b>James</b>' , '<b>Max</b><b>James</b>' ] ,
680
756
] ) ;
681
757
682
- let GlimmerContentTestCases = new ContentTestGenerator ( [
758
+ let GlimmerContentTestCases = new DynamicContentTestGenerator ( [
683
759
[ Object . create ( null ) , EMPTY , 'an object with no toString' ] ,
684
760
] ) ;
685
761
0 commit comments