IceCubesApp/Packages/Models/Tests/ModelsTests/HTMLStringTests.swift
Thomas Ricouard 6297a428a3
Full Xcode 16 supports + iOS 18 support (#2100)
* Compile on iOS 18

* Fix more warnings

* Tweak build settings

* Migrate to Swift Tests

* better tests

* Fix

* Fix tests

* More TabView cleanup

Bump to iOS 18 only + remove custom sidebar

* Revert "More TabView cleanup"

This reverts commit e051437fcb.

* Tabbar fix + bump to iOS 18

* Remove popToRoot

* Cleanup scrollToTop

* Support both TapBar

* Better TabView support

* Better TabView support

* Cleanup

* Disable TabView animations

* Remove id in ForEach

* Remove external init for StatusRowView

* Cleanup

* More Swift 6 concurrency

* Swift 6 mode

* Fixes

* Full Swift 6 packages support

* For now compile env in Swift 5 mode

* Fix archive

* More fix to Archive

* Address `dispatch_assert_queue_fail` (#2161)

See https://twitter.com/dimillian/status/1823089444397724003?s=61&t=SC3rvyJQWn1NQqAgMVrT0Q

* Bump Env to Swift 6

* Fix push notification

* Remove unecessary workaround

* Cleanup

* Move to @Entry

* Fix TabView on Catalyst

* Fix build

* Fix build 2

* fix warning

* Fix icons for iOS 18

---------

Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
2024-09-10 06:53:19 +02:00

88 lines
4.6 KiB
Swift

@testable import Models
import Testing
import Foundation
@Test
func testURLInit() throws {
let simpleUrl = URL(string: "https://www.google.com", encodePath: true)
#expect("https://www.google.com" == simpleUrl?.absoluteString)
let urlWithTrailingSlash = URL(string: "https://www.google.com/", encodePath: true)
#expect("https://www.google.com/" == urlWithTrailingSlash?.absoluteString)
let extendedCharPath = URL(string: "https://en.wikipedia.org/wiki/Elbbrücken_station", encodePath: true)
#expect("https://en.wikipedia.org/wiki/Elbbr%C3%BCcken_station" == extendedCharPath?.absoluteString)
let extendedCharQuery = URL(string: "http://test.com/blah/city?name=京都市", encodePath: true)
#expect("http://test.com/blah/city?name=%E4%BA%AC%E9%83%BD%E5%B8%82" == extendedCharQuery?.absoluteString)
// Double encoding will happen if you ask to encodePath on an already encoded string
let alreadyEncodedPath = URL(string: "https://en.wikipedia.org/wiki/Elbbr%C3%BCcken_station", encodePath: true)
#expect("https://en.wikipedia.org/wiki/Elbbr%25C3%25BCcken_station" == alreadyEncodedPath?.absoluteString)
}
@Test
func testHTMLStringInit() throws {
let decoder = JSONDecoder()
let basicContent = "\"<p>This is a test</p>\""
var htmlString = try decoder.decode(HTMLString.self, from: Data(basicContent.utf8))
#expect("This is a test" == htmlString.asRawText)
#expect("<p>This is a test</p>" == htmlString.htmlValue)
#expect("This is a test" == htmlString.asMarkdown)
#expect(0 == htmlString.statusesURLs.count)
#expect(0 == htmlString.links.count)
let basicLink = "\"<p>This is a <a href=\\\"https://test.com\\\">test</a></p>\""
htmlString = try decoder.decode(HTMLString.self, from: Data(basicLink.utf8))
#expect("This is a test" == htmlString.asRawText)
#expect("<p>This is a <a href=\"https://test.com\">test</a></p>" == htmlString.htmlValue)
#expect("This is a [test](https://test.com)" == htmlString.asMarkdown)
#expect(0 == htmlString.statusesURLs.count)
#expect(1 == htmlString.links.count)
#expect("https://test.com" == htmlString.links[0].url.absoluteString)
#expect("test" == htmlString.links[0].displayString)
let extendedCharLink = "\"<p>This is a <a href=\\\"https://test.com/goßëña\\\">test</a></p>\""
htmlString = try decoder.decode(HTMLString.self, from: Data(extendedCharLink.utf8))
#expect("This is a test" == htmlString.asRawText)
#expect("<p>This is a <a href=\"https://test.com/goßëña\">test</a></p>" == htmlString.htmlValue)
#expect("This is a [test](https://test.com/go%C3%9F%C3%AB%C3%B1a)" == htmlString.asMarkdown)
#expect(0 == htmlString.statusesURLs.count)
#expect(1 == htmlString.links.count)
#expect("https://test.com/go%C3%9F%C3%AB%C3%B1a" == htmlString.links[0].url.absoluteString)
#expect("test" == htmlString.links[0].displayString)
let alreadyEncodedLink = "\"<p>This is a <a href=\\\"https://test.com/go%C3%9F%C3%AB%C3%B1a\\\">test</a></p>\""
htmlString = try decoder.decode(HTMLString.self, from: Data(alreadyEncodedLink.utf8))
#expect("This is a test" == htmlString.asRawText)
#expect("<p>This is a <a href=\"https://test.com/go%C3%9F%C3%AB%C3%B1a\">test</a></p>" == htmlString.htmlValue)
#expect("This is a [test](https://test.com/go%C3%9F%C3%AB%C3%B1a)" == htmlString.asMarkdown)
#expect(0 == htmlString.statusesURLs.count)
#expect(1 == htmlString.links.count)
#expect("https://test.com/go%C3%9F%C3%AB%C3%B1a" == htmlString.links[0].url.absoluteString)
#expect("test" == htmlString.links[0].displayString)
}
@Test
func testHTMLStringInit_markdownEscaping() throws {
let decoder = JSONDecoder()
let stdMarkdownContent = "\"<p>This [*is*] `a`\\n**test**</p>\""
var htmlString = try decoder.decode(HTMLString.self, from: Data(stdMarkdownContent.utf8))
#expect("This [*is*] `a`\n**test**" == htmlString.asRawText)
#expect("<p>This [*is*] `a`\n**test**</p>" == htmlString.htmlValue)
#expect("This \\[\\*is\\*] \\`a\\` \\*\\*test\\*\\*" == htmlString.asMarkdown)
let underscoreContent = "\"<p>This _is_ an :emoji_maybe:</p>\""
htmlString = try decoder.decode(HTMLString.self, from: Data(underscoreContent.utf8))
#expect("This _is_ an :emoji_maybe:" == htmlString.asRawText)
#expect("<p>This _is_ an :emoji_maybe:</p>" == htmlString.htmlValue)
#expect("This \\_is\\_ an :emoji_maybe:" == htmlString.asMarkdown)
let strikeContent = "\"<p>This ~is~ a\\n`test`</p>\""
htmlString = try decoder.decode(HTMLString.self, from: Data(strikeContent.utf8))
#expect("This ~is~ a\n`test`" == htmlString.asRawText)
#expect("<p>This ~is~ a\n`test`</p>" == htmlString.htmlValue)
#expect("This \\~is\\~ a \\`test\\`" == htmlString.asMarkdown)
}