Add first Web test. Add WebTests to test plans.

This commit is contained in:
Brent Simmons
2024-05-20 22:56:55 -07:00
parent ad61c01ad4
commit 72e83becb1
6 changed files with 43 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
//
// Dictionary+RSWeb.swift
// Dictionary+Web.swift
// RSWeb
//
// Created by Brent Simmons on 1/13/18.
@@ -13,12 +13,13 @@ public extension Dictionary where Key == String, Value == String {
/// Translates a dictionary into a string like `foo=bar&param2=some%20thing`.
var urlQueryString: String? {
var components = URLComponents()
components.queryItems = self.reduce(into: [URLQueryItem]()) {
$0.append(URLQueryItem(name: $1.key, value: $1.value))
var queryItems = [URLQueryItem]()
for (key, value) in self {
queryItems.append(URLQueryItem(name: key, value: value))
}
var components = URLComponents()
components.queryItems = queryItems
let s = components.percentEncodedQuery
return s == nil || s!.isEmpty ? nil : s

View File

@@ -0,0 +1,20 @@
//
// DictionaryWebTests.swift
//
//
// Created by Brent Simmons on 5/20/24.
//
import XCTest
import Web
final class DictionaryWebTests: XCTestCase {
func testURLQueryString_oneItemNoEscaping() {
let d = ["parameterName" : "value"]
let queryString = d.urlQueryString
let expectedQueryString = "parameterName=value"
XCTAssertEqual(queryString, expectedQueryString)
}
}

View File

@@ -1,12 +0,0 @@
import XCTest
@testable import Web
final class WebTests: XCTestCase {
func testExample() throws {
// XCTest Documentation
// https://developer.apple.com/documentation/xctest
// Defining Test Cases and Test Methods
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
}
}