11import assert from "node:assert/strict" ;
22
33import { browser } from "./browser.js" ;
4- import {
5- RealSupportStatement ,
6- SupportStatement ,
7- statement ,
8- } from "./supportStatements.js" ;
4+ import { SupportStatement } from "./supportStatements.js" ;
95
106describe ( "statements" , function ( ) {
11- describe ( "statement()" , function ( ) {
12- it ( "upgrades support statements" , function ( ) {
13- const v1 = statement ( new SupportStatement ( { version_added : "1" } ) ) ;
14- assert ( v1 instanceof RealSupportStatement ) ;
15- } ) ;
16-
17- it ( "passes through real support statements" , function ( ) {
18- const original = new RealSupportStatement ( { version_added : "2" } ) ;
19- assert ( original === statement ( original ) ) ;
20- } ) ;
21-
22- it ( "accepts raw support statement objects" , function ( ) {
23- const v3 = statement ( { version_added : "3" } ) ;
24- assert ( v3 instanceof RealSupportStatement ) ;
25- } ) ;
26- } ) ;
27-
287 describe ( "SupportStatement" , function ( ) {
298 describe ( "#flags" , function ( ) {
309 const s = {
@@ -75,16 +54,6 @@ describe("statements", function () {
7554 } ) ;
7655 assert . equal ( s . version_added , "1" ) ;
7756 } ) ;
78-
79- it ( "returns false for undefined" , function ( ) {
80- const s = new SupportStatement ( { } ) ;
81- assert . equal ( s . version_added , false ) ;
82- } ) ;
83-
84- it ( "returns null for null" , function ( ) {
85- const s = new SupportStatement ( { version_added : null } ) ;
86- assert . equal ( s . version_added , null ) ;
87- } ) ;
8857 } ) ;
8958
9059 describe ( "#version_removed" , function ( ) {
@@ -96,85 +65,15 @@ describe("statements", function () {
9665 assert . equal ( s . version_removed , "2" ) ;
9766 } ) ;
9867
99- it ( "returns false" , function ( ) {
100- const s = new SupportStatement ( {
101- version_added : "1" ,
102- version_removed : false ,
103- } ) ;
104- assert . equal ( s . version_removed , false ) ;
105- } ) ;
106-
10768 it ( "returns undefined" , function ( ) {
10869 const s = new SupportStatement ( { version_added : "1" } ) ;
10970 assert . equal ( s . version_removed , undefined ) ;
11071 } ) ;
11172 } ) ;
112- } ) ;
113-
114- describe ( "RealSupportStatement" , function ( ) {
115- describe ( "#constructor" , function ( ) {
116- it ( "throws for empty support statement" , function ( ) {
117- assert . throws ( ( ) => new RealSupportStatement ( { } ) ) ;
118- } ) ;
119-
120- it ( "throws for missing version_added" , function ( ) {
121- assert . throws (
122- ( ) => new RealSupportStatement ( { version_removed : false } ) ,
123- ) ;
124- } ) ;
125-
126- it ( "throws for explicitly undefined version_added or version_removed" , function ( ) {
127- assert . throws (
128- ( ) => new RealSupportStatement ( { version_added : undefined } ) ,
129- ) ;
130- assert . throws (
131- ( ) =>
132- new RealSupportStatement ( {
133- version_added : "1" ,
134- version_removed : undefined ,
135- } ) ,
136- ) ;
137- } ) ;
138-
139- it ( "throws for null version_added or version_removed" , function ( ) {
140- assert . throws ( ( ) => new RealSupportStatement ( { version_added : null } ) ) ;
141- assert . throws (
142- ( ) =>
143- new RealSupportStatement ( {
144- version_added : "1" ,
145- version_removed : null ,
146- } ) ,
147- ) ;
148- } ) ;
149-
150- it ( "throws for true version_added or version_removed" , function ( ) {
151- assert . throws ( ( ) => new RealSupportStatement ( { version_added : true } ) ) ;
152- assert . throws (
153- ( ) =>
154- new RealSupportStatement ( {
155- version_added : "1" ,
156- version_removed : true ,
157- } ) ,
158- ) ;
159- } ) ;
160-
161- it ( "does not throw for false version_added or version_removed" , function ( ) {
162- assert . doesNotThrow (
163- ( ) => new RealSupportStatement ( { version_added : false } ) ,
164- ) ;
165- assert . doesNotThrow (
166- ( ) =>
167- new RealSupportStatement ( {
168- version_added : "1" ,
169- version_removed : false ,
170- } ) ,
171- ) ;
172- } ) ;
173- } ) ;
17473
17574 describe ( "#supportedBy" , function ( ) {
17675 it ( "returns an array of releases represented by the statement" , function ( ) {
177- const st = new RealSupportStatement (
76+ const st = new SupportStatement (
17877 { version_added : "1" } ,
17978 browser ( "chrome" ) ,
18079 ) ;
@@ -187,7 +86,7 @@ describe("statements", function () {
18786 // of that range? If so, you should be able to opt-in to warnings or
18887 // errors about it.
18988 it ( "handles ≤ gracefully" , function ( ) {
190- const st = new RealSupportStatement (
89+ const st = new SupportStatement (
19190 { version_added : "≤11" } ,
19291 browser ( "chrome" ) ,
19392 ) ;
@@ -199,12 +98,12 @@ describe("statements", function () {
19998 describe ( "supportedIn()" , function ( ) {
20099 it ( "throws when browser is undefined" , function ( ) {
201100 const cr = browser ( "chrome" ) ;
202- const statement = new RealSupportStatement ( { version_added : "1" } ) ;
101+ const statement = new SupportStatement ( { version_added : "1" } ) ;
203102 assert . throws ( ( ) => statement . supportedInDetails ( cr . current ( ) ) , Error ) ;
204103 } ) ;
205104
206105 it ( "throws when release does not correspond to the statement's browser" , function ( ) {
207- const statement = new RealSupportStatement (
106+ const statement = new SupportStatement (
208107 { version_added : "1" } ,
209108 browser ( "chrome" ) ,
210109 ) ;
@@ -216,8 +115,8 @@ describe("statements", function () {
216115
217116 it ( "returns supported when release is on after version_added" , function ( ) {
218117 const cr = browser ( "chrome" ) ;
219- const unranged = new RealSupportStatement ( { version_added : "100" } , cr ) ;
220- const ranged = new RealSupportStatement ( { version_added : "≤100" } , cr ) ;
118+ const unranged = new SupportStatement ( { version_added : "100" } , cr ) ;
119+ const ranged = new SupportStatement ( { version_added : "≤100" } , cr ) ;
221120
222121 assert . equal (
223122 unranged . supportedInDetails ( cr . version ( "100" ) ) . supported ,
@@ -254,11 +153,11 @@ describe("statements", function () {
254153
255154 it ( "returns supported when release is on after version_added and before version_removed" , function ( ) {
256155 const cr = browser ( "chrome" ) ;
257- const unranged = new RealSupportStatement (
156+ const unranged = new SupportStatement (
258157 { version_added : "100" , version_removed : "125" } ,
259158 cr ,
260159 ) ;
261- const ranged = new RealSupportStatement (
160+ const ranged = new SupportStatement (
262161 { version_added : "≤100" , version_removed : "125" } ,
263162 cr ,
264163 ) ;
@@ -308,11 +207,8 @@ describe("statements", function () {
308207
309208 it ( "returns unknown support when release is before ranged version_added" , function ( ) {
310209 const cr = browser ( "chrome" ) ;
311- const rangedOpen = new RealSupportStatement (
312- { version_added : "≤100" } ,
313- cr ,
314- ) ;
315- const rangedClosed = new RealSupportStatement (
210+ const rangedOpen = new SupportStatement ( { version_added : "≤100" } , cr ) ;
211+ const rangedClosed = new SupportStatement (
316212 { version_added : "≤100" , version_removed : "125" } ,
317213 cr ,
318214 ) ;
@@ -329,7 +225,7 @@ describe("statements", function () {
329225
330226 it ( "returns unknown support when release is after version_added and before ranged version_removed" , function ( ) {
331227 const cr = browser ( "chrome" ) ;
332- const rangedEnd = new RealSupportStatement (
228+ const rangedEnd = new SupportStatement (
333229 { version_added : "100" , version_removed : "≤125" } ,
334230 cr ,
335231 ) ;
@@ -354,10 +250,7 @@ describe("statements", function () {
354250
355251 it ( "returns unsupported when statement is version_added false" , function ( ) {
356252 const cr = browser ( "chrome" ) ;
357- const statement = new RealSupportStatement (
358- { version_added : false } ,
359- cr ,
360- ) ;
253+ const statement = new SupportStatement ( { version_added : false } , cr ) ;
361254
362255 for ( const release of cr . releases ) {
363256 assert . equal ( statement . supportedInDetails ( release ) . supported , false ) ;
@@ -366,7 +259,7 @@ describe("statements", function () {
366259
367260 it ( "returns unsupported when release is before fixed version_added" , function ( ) {
368261 const cr = browser ( "chrome" ) ;
369- const unranged = new RealSupportStatement ( { version_added : "100" } , cr ) ;
262+ const unranged = new SupportStatement ( { version_added : "100" } , cr ) ;
370263 assert . equal (
371264 unranged . supportedInDetails ( cr . version ( "99" ) ) . supported ,
372265 false ,
@@ -376,7 +269,7 @@ describe("statements", function () {
376269 it ( "returns unsupported when release is on or after version_removed" , function ( ) {
377270 const cr = browser ( "chrome" ) ;
378271
379- const unranged = new RealSupportStatement (
272+ const unranged = new SupportStatement (
380273 { version_added : "1" , version_removed : "10" } ,
381274 cr ,
382275 ) ;
@@ -397,7 +290,7 @@ describe("statements", function () {
397290 false ,
398291 ) ;
399292
400- const ranged = new RealSupportStatement (
293+ const ranged = new SupportStatement (
401294 { version_added : "≤5" , version_removed : "10" } ,
402295 cr ,
403296 ) ;
0 commit comments