Add RSCoreTests scheme. Stop running legacy strip HTML function in tests (but leave code in place in case needed later for performance comparison testing).

This commit is contained in:
Brent Simmons committed 2025-10-21 09:38:27 -07:00
1 parent f472a5ba54
commit c3fd92dd99
4 files changed
+157 -109

No files matched your search

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>classNames</key>
<dict>
<key>StripHTMLTests</key>
<dict>
<key>testStrippingHTMLPerformanceLegacySwift()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.004283</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
</dict>
</dict>
</plist>
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>runDestinationsByUUID</key>
<dict>
<key>D26AA97C-48FA-4894-9BED-6D2CFAD9147C</key>
<dict>
<key>localComputer</key>
<dict>
<key>busSpeedInMHz</key>
<integer>0</integer>
<key>cpuCount</key>
<integer>1</integer>
<key>cpuKind</key>
<string>Apple M1 Max</string>
<key>cpuSpeedInMHz</key>
<integer>0</integer>
<key>logicalCPUCoresPerPackage</key>
<integer>10</integer>
<key>modelCode</key>
<string>Mac13,1</string>
<key>physicalCPUCoresPerPackage</key>
<integer>10</integer>
<key>platformIdentifier</key>
<string>com.apple.platform.macosx</string>
</dict>
<key>targetArchitecture</key>
<string>arm64e</string>
</dict>
</dict>
</dict>
</plist>
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1620"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "RSCoreTests"
BuildableName = "RSCoreTests"
BlueprintName = "RSCoreTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
@@ -79,107 +79,61 @@ final class StripHTMLTests: XCTestCase {
func testStrippingHTMLBasic() {
let html = "<p>Hello <b>world</b>!</p>"
let legacyResult = html.legacyStrippingHTML()
let result = html.strippingHTML()
// Note: C implementation trims leading/trailing whitespace, legacy Swift doesn't
// Both should strip tags and collapse whitespace
XCTAssertFalse(legacyResult.contains("<"))
XCTAssertFalse(result.contains("<"))
XCTAssertTrue(legacyResult.contains("Hello"))
XCTAssertTrue(legacyResult.contains("world"))
XCTAssertTrue(result.contains("Hello"))
XCTAssertTrue(result.contains("world"))
XCTAssertEqual(result, "Hello world!")
}
func testStrippingHTMLWithScript() {
let html = "<p>Before</p><script>alert('test');</script><p>After</p>"
let legacyResult = html.legacyStrippingHTML()
let result = html.strippingHTML()
// Note: C implementation trims leading/trailing whitespace, legacy Swift doesn't
// Both should remove script content
XCTAssertFalse(legacyResult.contains("alert"))
XCTAssertFalse(result.contains("alert"))
XCTAssertTrue(legacyResult.contains("Before"))
XCTAssertTrue(legacyResult.contains("After"))
XCTAssertTrue(result.contains("Before"))
XCTAssertTrue(result.contains("After"))
XCTAssertEqual(result, "Before After")
}
func testStrippingHTMLWithStyle() {
let html = "<p>Content</p><style>body { color: red; }</style><p>More</p>"
let legacyResult = html.legacyStrippingHTML()
let result = html.strippingHTML()
// Note: C implementation trims leading/trailing whitespace, legacy Swift doesn't
// Both should remove style content
XCTAssertFalse(legacyResult.contains("color"))
XCTAssertFalse(result.contains("color"))
XCTAssertTrue(legacyResult.contains("Content"))
XCTAssertTrue(legacyResult.contains("More"))
XCTAssertTrue(result.contains("Content"))
XCTAssertTrue(result.contains("More"))
XCTAssertEqual(result, "Content More")
}
func testStrippingHTMLWithMaxCharacters() {
let html = "<p>This is a long piece of text that should be truncated at some point.</p>"
let legacyResult = html.legacyStrippingHTML(maxCharacters: 20)
let result = html.strippingHTML(maxCharacters: 20)
// Note: C implementation trims leading/trailing whitespace, legacy Swift doesn't
// Both should respect maxCharacters limit
XCTAssertLessThanOrEqual(legacyResult.count, 20)
XCTAssertLessThanOrEqual(result.count, 20)
XCTAssertEqual(result, "This is a long piece")
}
func testStrippingHTMLWithUTF8() {
let html = "<p>Hello 世界 🌍</p>"
let legacyResult = html.legacyStrippingHTML()
let result = html.strippingHTML()
// Note: C implementation trims leading/trailing whitespace, legacy Swift doesn't
// Both should handle UTF-8 correctly
XCTAssertTrue(legacyResult.contains("世界"))
XCTAssertTrue(legacyResult.contains("🌍"))
XCTAssertTrue(result.contains("世界"))
XCTAssertTrue(result.contains("🌍"))
XCTAssertEqual(result, "Hello 世界 🌍")
}
func testStrippingHTMLWhitespaceCollapsing() {
let html = "<p>Too many\n\n\nspaces</p>"
let legacyResult = html.legacyStrippingHTML()
let result = html.strippingHTML()
// Note: C implementation trims leading/trailing whitespace, legacy Swift doesn't
// Both should collapse consecutive whitespace
XCTAssertFalse(legacyResult.contains(" "))
XCTAssertFalse(result.contains(" "))
XCTAssertEqual(result, "Too many spaces")
}
func testStrippingHTMLPerformanceLegacySwift() {
let html = """
<html><body>
<p>This is a test article with <b>bold text</b> and <i>italic text</i>.</p>
<script>console.log('test');</script>
<style>body { margin: 0; }</style>
<p>More content with <a href="http://example.com">links</a> and other tags.</p>
<div>Nested <span>tags</span> are common in HTML.</div>
</body></html>
"""
self.measure {
for _ in 0..<1000 {
let _ = html.legacyStrippingHTML(maxCharacters: 300)
}
}
}
// Commented out because this doesn’t need to run every time.
// Un-comment it when you want to compare legacy performance to C performance.
// func testStrippingHTMLPerformanceLegacySwift() {
// let html = """
// <html><body>
// <p>This is a test article with <b>bold text</b> and <i>italic text</i>.</p>
// <script>console.log('test');</script>
// <style>body { margin: 0; }</style>
// <p>More content with <a href="http://example.com">links</a> and other tags.</p>
// <div>Nested <span>tags</span> are common in HTML.</div>
// </body></html>
// """
//
// self.measure {
// for _ in 0..<1000 {
// let _ = html.legacyStrippingHTML(maxCharacters: 300)
// }
// }
// }
func testStrippingHTMLPerformance() {
let html = """
@@ -211,52 +165,38 @@ final class StripHTMLTests: XCTestCase {
let html = try String(contentsOf: url, encoding: .utf8)
// Test both implementations can process real-world HTML
let legacyResult = html.legacyStrippingHTML(maxCharacters: 300)
let result = html.strippingHTML(maxCharacters: 300)
// Note: Results may differ slightly because the legacy Swift implementation's regex-based
// script removal (<script>[\s\S]*?</script>) doesn't handle script tags with attributes
// like <script type="text/javascript">, while the C implementation correctly removes them.
// Both produce usable output for article previews.
// Both should produce non-empty results
XCTAssertFalse(legacyResult.isEmpty, "\(testFile): Legacy result should not be empty")
XCTAssertFalse(result.isEmpty, "\(testFile): Result should not be empty")
// Both should respect the maxCharacters limit
XCTAssertLessThanOrEqual(legacyResult.count, 300, "\(testFile): Legacy result should respect maxCharacters")
XCTAssertLessThanOrEqual(result.count, 300, "\(testFile): Result should respect maxCharacters")
// Both should strip HTML tags
XCTAssertFalse(legacyResult.contains("<"), "\(testFile): Legacy result should not contain HTML tags")
XCTAssertFalse(result.contains("<"), "\(testFile): Result should not contain HTML tags")
// C implementation should not contain script artifacts
XCTAssertFalse(result.contains("//"), "\(testFile): Should fully remove script content")
}
}
func testStrippingHTMLPerformanceRealWorldLegacySwift() throws {
let testFiles = ["daringfireball", "apple", "inessential", "scripting"]
var htmlFiles: [String] = []
for testFile in testFiles {
guard let url = Bundle.module.url(forResource: testFile, withExtension: "html", subdirectory: "Resources") else {
XCTFail("Could not find \(testFile).html")
return
}
let html = try String(contentsOf: url, encoding: .utf8)
htmlFiles.append(html)
}
self.measure {
for _ in 0..<100 {
for html in htmlFiles {
let _ = html.legacyStrippingHTML(maxCharacters: 300)
}
}
}
}
// Commented out because this doesn’t need to run every time.
// Un-comment it when you want to compare legacy performance to C performance.
// func testStrippingHTMLPerformanceRealWorldLegacySwift() throws {
// let testFiles = ["daringfireball", "apple", "inessential", "scripting"]
// var htmlFiles: [String] = []
//
// for testFile in testFiles {
// guard let url = Bundle.module.url(forResource: testFile, withExtension: "html", subdirectory: "Resources") else {
// XCTFail("Could not find \(testFile).html")
// return
// }
// let html = try String(contentsOf: url, encoding: .utf8)
// htmlFiles.append(html)
// }
//
// self.measure {
// for _ in 0..<100 {
// for html in htmlFiles {
// let _ = html.legacyStrippingHTML(maxCharacters: 300)
// }
// }
// }
// }
func testStrippingHTMLPerformanceRealWorld() throws {
let testFiles = ["daringfireball", "apple", "inessential", "scripting"]
@@ -303,5 +243,4 @@ final class StripHTMLTests: XCTestCase {
XCTAssertEqual(result, expectedOutput, "\(testFile): Implementation should match expected output")
}
}
}