2018-01-14 02:40:27 +01:00
|
|
|
//
|
|
|
|
// DictionaryTests.swift
|
|
|
|
// RSWebTests
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 1/13/18.
|
|
|
|
// Copyright © 2018 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
|
|
|
|
class DictionaryTests: XCTestCase {
|
|
|
|
|
|
|
|
func testSimpleQueryString() {
|
|
|
|
|
|
|
|
let d = ["foo": "bar", "param1": "This is a value."]
|
|
|
|
let s = d.urlQueryString()
|
|
|
|
|
2018-01-14 20:11:53 +01:00
|
|
|
XCTAssertTrue(s == "foo=bar¶m1=This%20is%20a%20value." || s == "param1=This%20is%20a%20value.&foo=bar")
|
2018-01-14 02:40:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func testQueryStringWithAmpersand() {
|
|
|
|
|
|
|
|
let d = ["fo&o": "bar", "param1": "This is a&value."]
|
|
|
|
let s = d.urlQueryString()
|
|
|
|
|
2018-01-14 20:11:53 +01:00
|
|
|
XCTAssertTrue(s == "fo%38o=bar¶m1=This%20is%20a%38value." || s == "param1=This%20is%20a%38value.&fo%38o=bar")
|
2018-01-14 02:40:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func testQueryStringWithAccentedCharacters() {
|
|
|
|
|
|
|
|
let d = ["fée": "bør"]
|
|
|
|
let s = d.urlQueryString()
|
|
|
|
|
|
|
|
XCTAssertTrue(s == "f%C3%A9e=b%C3%B8r")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testQueryStringWithEmoji() {
|
|
|
|
|
|
|
|
let d = ["🌴e": "bar🎩🌴"]
|
|
|
|
let s = d.urlQueryString()
|
|
|
|
|
|
|
|
XCTAssertTrue(s == "%F0%9F%8C%B4e=bar%F0%9F%8E%A9%F0%9F%8C%B4")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|