66//
77
88@testable import SourceMapper
9- import XCTest
9+ import Testing
10+ import Foundation
11+
12+ extension Tag {
13+ @Tag static var basics : Self
14+ }
1015
1116/// Basic flows of the use cases
12- class TestBasics : XCTestCase {
17+ @Suite ( . tags( . basics) )
18+ final class TestBasics {
19+ @Test
1320 func testEmptyRoundTrip( ) throws {
1421 let empty = SourceMap ( )
1522 let serialized = try empty. encode ( )
1623 let deserialized = try SourceMap ( serialized)
17- XCTAssertEqual ( empty, deserialized)
18- try XCTAssertEqual ( empty. encodeString ( ) , deserialized. encodeString ( ) )
24+ #expect ( empty == deserialized)
25+ #expect ( try empty. encodeString ( ) == deserialized. encodeString ( ) )
1926 }
2027
21- func testLoading( ) throws {
22- let files = [ " jazzy.css.map.dart " , " jazzy.css.map.libsass " ]
23- try files. forEach { fixtureName in
24- let map = try SourceMap ( fixtureName: fixtureName)
25- XCTAssertEqual ( SourceMap . VERSION, map. version)
26- let file = try XCTUnwrap ( map. file)
27- XCTAssertEqual ( fixtureName. replacingOccurrences ( of: " .map " , with: " " ) , file)
28- XCTAssertEqual ( 1 , map. sources. count)
29- XCTAssertTrue ( map. sources [ 0 ] . url. hasSuffix ( " jazzy.css.scss " ) )
28+ @Test ( arguments: [ " jazzy.css.map.dart " , " jazzy.css.map.libsass " ] )
29+ func testLoading( fixtureName: String ) throws {
30+ let map = try SourceMap ( fixtureName: fixtureName)
31+ #expect( map. version == SourceMap . VERSION)
32+ let file = try #require( map. file)
33+ #expect( file == fixtureName. replacingOccurrences ( of: " .map " , with: " " ) )
34+ #expect( map. sources. count == 1 )
35+ #expect( map. sources [ 0 ] . url. hasSuffix ( " jazzy.css.scss " ) )
3036
31- print ( map)
32- let unpackedMap = try UnpackedSourceMap ( map)
33- print ( unpackedMap. segmentsDescription)
37+ print ( map)
38+ let unpackedMap = try UnpackedSourceMap ( map)
39+ print ( unpackedMap. segmentsDescription)
3440
35- // Check a couple of mapping positions, one towards the start and
36- // one at the end to check the mapping accumulators.
41+ // Check a couple of mapping positions, one towards the start and
42+ // one at the end to check the mapping accumulators.
3743
38- let mapped1 = try XCTUnwrap ( unpackedMap. map ( line: 26 , column: 22 ) )
39- let pos1 = try XCTUnwrap ( mapped1. sourcePos)
40- XCTAssertEqual ( 25 , pos1. line)
41- XCTAssertTrue ( pos1. column >= 14 )
44+ let mapped1 = try #require ( unpackedMap. map ( line: 26 , column: 22 ) )
45+ let pos1 = try #require ( mapped1. sourcePos)
46+ #expect ( pos1. line == 25 )
47+ #expect ( pos1. column >= 14 )
4248
43- let mapped2 = try XCTUnwrap ( unpackedMap. map ( line: 465 , column: 12 ) )
44- let pos2 = try XCTUnwrap ( mapped2. sourcePos)
45- XCTAssertEqual ( 601 , pos2. line)
46- XCTAssertTrue ( pos2. column >= 4 )
47- }
49+ let mapped2 = try #require( unpackedMap. map ( line: 465 , column: 12 ) )
50+ let pos2 = try #require( mapped2. sourcePos)
51+ #expect( pos2. line == 601 )
52+ #expect( pos2. column >= 4 )
4853 }
4954
55+ @Test
5056 func testPrinting( ) throws {
5157 var map = SourceMap ( )
52- XCTAssertTrue ( try UnpackedSourceMap ( map) . segmentsDescription. isEmpty)
53- XCTAssertEqual ( #"SourceMap(v=3 #sources=0 mappings="")"# , map . description )
58+ try #expect ( UnpackedSourceMap ( map) . segmentsDescription. isEmpty)
59+ #expect ( map . description == #"SourceMap(v=3 #sources=0 mappings="")"# )
5460
5561 map. file = " myfile.css "
5662 map. sourceRoot = " ../dist "
5763 map. sources = [ . init( url: " a.scss " ) ]
5864 map. names = [ " fred " , " barney " ]
59- XCTAssertEqual ( #"SourceMap(v=3 file="myfile.css" sourceRoot="../dist" #sources=1 #names=2 mappings="")"# , map . description )
65+ #expect ( map . description == #"SourceMap(v=3 file="myfile.css" sourceRoot="../dist" #sources=1 #names=2 mappings="")"# )
6066
6167 try map. set ( segments: [
6268 [
@@ -65,15 +71,16 @@ class TestBasics: XCTestCase {
6571 ]
6672 ] )
6773 let segDesc = try UnpackedSourceMap ( map) . segmentsDescription
68- XCTAssertEqual ( """
69- line=0 col=0-12 (source=0 line=0 col=0 name=1)
70- col=13 (source=0 line=1 col=0 name=1)
71- """ , segDesc )
74+ #expect ( segDesc == """
75+ line=0 col=0-12 (source=0 line=0 col=0 name=1)
76+ col=13 (source=0 line=1 col=0 name=1)
77+ """ )
7278 _ = try map. encode ( ) // to encode the mapping string
7379 print ( map. description)
74- XCTAssertTrue ( map. description. hasSuffix ( #" mappings="AAAAC,aACAA")"# ) )
80+ #expect ( map. description. hasSuffix ( #" mappings="AAAAC,aACAA")"# ) )
7581 }
7682
83+ @Test
7784 func testSourceURL( ) throws {
7885 var map = SourceMap ( )
7986 map. sources = [ . init( url: " http://host/path/a.scss " ) ,
@@ -82,13 +89,13 @@ class TestBasics: XCTestCase {
8289 let mapURL = URL ( fileURLWithPath: " /web/main.map " )
8390
8491 let source1 = map. getSourceURL ( source: 0 , sourceMapURL: mapURL)
85- XCTAssertEqual ( " http://host/path/a.scss " , source1 . absoluteString )
92+ #expect ( source1 . absoluteString == " http://host/path/a.scss " )
8693
8794 let source2 = map. getSourceURL ( source: 1 , sourceMapURL: mapURL)
88- XCTAssertEqual ( " file:///dist/b.scss " , source2 . absoluteString )
95+ #expect ( source2 . absoluteString == " file:///dist/b.scss " )
8996
9097 map. sourceRoot = " ./../dist/ "
9198 let source3 = map. getSourceURL ( source: 2 , sourceMapURL: mapURL)
92- XCTAssertEqual ( " file:///dist/c.scss " , source3 . absoluteString )
99+ #expect ( source3 . absoluteString == " file:///dist/c.scss " )
93100 }
94101}
0 commit comments