import PlakCore
import Testing
@Suite struct PasteKindTests {
@Test("PHP starts with ") == .object(.php, "= $name ?>"))
}
@Test("JSON that parses is JSON; on one line it comes pretty-printed, on several lines as pasted")
func json() {
#expect(PasteKind(#"{"b":1,"a":[true,null]}"#) == .object(.json, "{\n \"b\": 1,\n \"a\": [\n true,\n null\n ]\n}"))
#expect(PasteKind("[1,\n2]") == .object(.json, "[1,\n2]"))
}
@Test("XML that parses is XML")
func xml() {
#expect(PasteKind(#""#) == .object(.xml, #""#))
#expect(PasteKind("\n") == .object(.xml, "\n"))
}
@Test("CSV needs two or more lines with the same field count, by comma, semicolon or tab")
func csv() {
#expect(PasteKind("a,b\n1,2\n") == .object(.csv, "a,b\n1,2"))
#expect(PasteKind("a;b\n1;2") == .object(.csv, "a;b\n1;2"))
#expect(PasteKind("a\tb\n1\t2") == .object(.csv, "a\tb\n1\t2"))
}
@Test("tab-separated text keeps its edge tabs, so an empty corner or last cell still makes a table")
func tsvEdges() {
#expect(PasteKind("\n\tQ1\tQ2\nA\t1\t\n") == .object(.csv, "\tQ1\tQ2\nA\t1\t"))
}
@Test("a sentence with commas, one CSV line, uneven lines, invalid JSON and broken XML stay text")
func negatives() {
#expect(PasteKind("Hello, world, this is a sentence.") == .text)
#expect(PasteKind("a,b,c") == .text)
#expect(PasteKind("a,b\n1,2,3") == .text)
#expect(PasteKind("{\"a\": }") == .text)
#expect(PasteKind("[1, 2") == .text)
#expect(PasteKind("bold and more") == .text)
#expect(PasteKind("just text") == .text)
#expect(PasteKind(" \n ") == .text)
}
@Test("nginx config and CSS split evenly on semicolons but hold braces, so they stay text")
func bracesStayText() {
let nginx = """
location = /favicon.svg { try_files $uri /index.php?$query_string; access_log off; log_not_found off; }
location = /favicon.ico { try_files $uri /index.php?$query_string; access_log off; log_not_found off; }
location = /robots.txt { try_files $uri /index.php?$query_string; access_log off; log_not_found off; }
"""
#expect(PasteKind(nginx) == .text)
#expect(PasteKind("a { color: red; margin: 0; }\nb { color: blue; margin: 1; }") == .text)
}
}