6
6
//
7
7
8
8
@testable import SourceMapper
9
- import XCTest
9
+ import Testing
10
+ import Foundation
11
+
12
+ extension Tag {
13
+ @Tag static var basics : Self
14
+ }
10
15
11
16
/// Basic flows of the use cases
12
- class TestBasics : XCTestCase {
17
+ @Suite ( . tags( . basics) )
18
+ final class TestBasics {
19
+ @Test
13
20
func testEmptyRoundTrip( ) throws {
14
21
let empty = SourceMap ( )
15
22
let serialized = try empty. encode ( )
16
23
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 ( ) )
19
26
}
20
27
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 " ) )
30
36
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)
34
40
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.
37
43
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 )
42
48
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 )
48
53
}
49
54
55
+ @Test
50
56
func testPrinting( ) throws {
51
57
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="")"# )
54
60
55
61
map. file = " myfile.css "
56
62
map. sourceRoot = " ../dist "
57
63
map. sources = [ . init( url: " a.scss " ) ]
58
64
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="")"# )
60
66
61
67
try map. set ( segments: [
62
68
[
@@ -65,15 +71,16 @@ class TestBasics: XCTestCase {
65
71
]
66
72
] )
67
73
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
+ """ )
72
78
_ = try map. encode ( ) // to encode the mapping string
73
79
print ( map. description)
74
- XCTAssertTrue ( map. description. hasSuffix ( #" mappings="AAAAC,aACAA")"# ) )
80
+ #expect ( map. description. hasSuffix ( #" mappings="AAAAC,aACAA")"# ) )
75
81
}
76
82
83
+ @Test
77
84
func testSourceURL( ) throws {
78
85
var map = SourceMap ( )
79
86
map. sources = [ . init( url: " http://host/path/a.scss " ) ,
@@ -82,13 +89,13 @@ class TestBasics: XCTestCase {
82
89
let mapURL = URL ( fileURLWithPath: " /web/main.map " )
83
90
84
91
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 " )
86
93
87
94
let source2 = map. getSourceURL ( source: 1 , sourceMapURL: mapURL)
88
- XCTAssertEqual ( " file:///dist/b.scss " , source2 . absoluteString )
95
+ #expect ( source2 . absoluteString == " file:///dist/b.scss " )
89
96
90
97
map. sourceRoot = " ./../dist/ "
91
98
let source3 = map. getSourceURL ( source: 2 , sourceMapURL: mapURL)
92
- XCTAssertEqual ( " file:///dist/c.scss " , source3 . absoluteString )
99
+ #expect ( source3 . absoluteString == " file:///dist/c.scss " )
93
100
}
94
101
}
0 commit comments