|
| 1 | +import Foundation |
| 2 | +@testable import TablePro |
| 3 | +import Testing |
| 4 | + |
| 5 | +@Suite("TabQueryContent.Equatable") |
| 6 | +struct TabQueryContentEqualityTests { |
| 7 | + @Test("Equal when all fields match") |
| 8 | + func equalWhenIdentical() { |
| 9 | + let a = TabQueryContent(query: "SELECT * FROM users;") |
| 10 | + let b = TabQueryContent(query: "SELECT * FROM users;") |
| 11 | + #expect(a == b) |
| 12 | + } |
| 13 | + |
| 14 | + @Test("Not equal when the query changes length") |
| 15 | + func notEqualOnLengthChange() { |
| 16 | + var a = TabQueryContent(query: "SELECT 1") |
| 17 | + let b = TabQueryContent(query: "SELECT 12") |
| 18 | + #expect(a != b) |
| 19 | + a.query = "SELECT 12" |
| 20 | + #expect(a == b) |
| 21 | + } |
| 22 | + |
| 23 | + @Test("Not equal when the query changes at the same length") |
| 24 | + func notEqualOnSameLengthChange() { |
| 25 | + let a = TabQueryContent(query: "abc") |
| 26 | + let b = TabQueryContent(query: "abd") |
| 27 | + #expect(a != b) |
| 28 | + } |
| 29 | + |
| 30 | + @Test("Detects a single-character edit in a large query") |
| 31 | + func detectsEditInLargeQuery() { |
| 32 | + let base = String(repeating: "SELECT 1;\n", count: 100_000) |
| 33 | + let a = TabQueryContent(query: base) |
| 34 | + let b = TabQueryContent(query: base + "X") |
| 35 | + #expect(a != b) |
| 36 | + let c = TabQueryContent(query: base) |
| 37 | + #expect(a == c) |
| 38 | + } |
| 39 | + |
| 40 | + @Test("Not equal when a non-text field differs") |
| 41 | + func notEqualOnOtherField() { |
| 42 | + var a = TabQueryContent(query: "Q") |
| 43 | + let b = TabQueryContent(query: "Q") |
| 44 | + a.isParameterPanelVisible = true |
| 45 | + #expect(a != b) |
| 46 | + a.isParameterPanelVisible = false |
| 47 | + #expect(a == b) |
| 48 | + } |
| 49 | + |
| 50 | + @Test("savedFileContent participates in equality") |
| 51 | + func savedFileContentEquality() { |
| 52 | + var a = TabQueryContent(query: "Q") |
| 53 | + var b = TabQueryContent(query: "Q") |
| 54 | + #expect(a == b) |
| 55 | + a.savedFileContent = "disk" |
| 56 | + #expect(a != b) |
| 57 | + b.savedFileContent = "disk" |
| 58 | + #expect(a == b) |
| 59 | + b.savedFileContent = "other" |
| 60 | + #expect(a != b) |
| 61 | + } |
| 62 | +} |
0 commit comments