@@ -11,6 +11,28 @@ class EncoderTests: XCTestCase {
1111 var failed : Set < String > = [ ]
1212 }
1313
14+ private func checkMalformed( wast: URL , module: ModuleDirective , message: String , recordFail: ( ) -> Void ) {
15+ let diagnostic = {
16+ let ( line, column) = module. location. computeLineAndColumn ( )
17+ return " \( wast. path) : \( line) : \( column) should be malformed: \( message) "
18+ }
19+ switch module. source {
20+ case . text( var wat) :
21+ XCTAssertThrowsError (
22+ try {
23+ _ = try wat. encode ( )
24+ recordFail ( )
25+ } ( ) , diagnostic ( ) )
26+ case . quote( let bytes) :
27+ XCTAssertThrowsError (
28+ try {
29+ _ = try wat2wasm ( String ( decoding: bytes, as: UTF8 . self) )
30+ recordFail ( )
31+ } ( ) , diagnostic ( ) )
32+ case . binary: break
33+ }
34+ }
35+
1436 func checkWabtCompatibility(
1537 wast: URL , json: URL , stats parentStats: inout CompatibilityTestStats
1638 ) throws {
@@ -35,25 +57,7 @@ class EncoderTests: XCTestCase {
3557 case . module( let moduleDirective) :
3658 watModules. append ( moduleDirective)
3759 case . assertMalformed( let module, let message) :
38- let diagnostic = {
39- let ( line, column) = module. location. computeLineAndColumn ( )
40- return " \( wast. path) : \( line) : \( column) should be malformed: \( message) "
41- }
42- switch module. source {
43- case . text( var wat) :
44- XCTAssertThrowsError (
45- try {
46- _ = try wat. encode ( )
47- recordFail ( )
48- } ( ) , diagnostic ( ) )
49- case . quote( let bytes) :
50- XCTAssertThrowsError (
51- try {
52- _ = try wat2wasm ( String ( decoding: bytes, as: UTF8 . self) )
53- recordFail ( )
54- } ( ) , diagnostic ( ) )
55- case . binary: break
56- }
60+ checkMalformed ( wast: wast, module: module, message: message, recordFail: recordFail)
5761 default : break
5862 }
5963 }
@@ -141,6 +145,38 @@ class EncoderTests: XCTestCase {
141145 #endif
142146 }
143147
148+ func testFunctionReferencesProposal( ) throws {
149+ // NOTE: Perform smoke check for function-references proposal here without
150+ // bit-to-bit compatibility check with wabt as wabt does not support
151+ // function-references proposal yet.
152+ for wastFile in Spectest . wastFiles (
153+ path: [
154+ Spectest . testsuitePath. appendingPathComponent ( " proposals/function-references " )
155+ ] , include: [ ] , exclude: [ ]
156+ ) {
157+ print ( " Checking \( wastFile. path) " )
158+ var parser = WastParser (
159+ try String ( contentsOf: wastFile) ,
160+ features: Spectest . deriveFeatureSet ( wast: wastFile)
161+ )
162+ while let directive = try parser. nextDirective ( ) {
163+ switch directive {
164+ case . module( let directive) :
165+ guard case var . text( wat) = directive. source else {
166+ continue
167+ }
168+ _ = wat = wat
169+ // TODO: Enable smoke check for encoding
170+ // _ = try wat.encode()
171+ case . assertMalformed( let module, let message) :
172+ checkMalformed ( wast: wastFile, module: module, message: message, recordFail: { } )
173+ default :
174+ break
175+ }
176+ }
177+ }
178+ }
179+
144180 func testEncodeNameSection( ) throws {
145181 let bytes = try wat2wasm (
146182 """
0 commit comments