Fixture.swift (4403B)
1 // SPDX-License-Identifier: GPL-2.0-only 2 import Foundation 3 import GitLite 4 import GitTestSupport 5 6 /// Small logbook in Subsurface's git format, written with the real git. 7 /// The sample data (site names, notes, tags) is deliberately in French: it exercises accented text. 8 enum Fixture { 9 static let branch = "jean@example.com" 10 11 static let settings = """ 12 version 3 13 divecomputerid "Shearwater Petrel 3" deviceid=4d1b2c3a serial="1234" nickname="Petrel" 14 autogroup 15 units METRIC 16 prefs TANKBAR 17 18 """ 19 20 static let site = """ 21 name "Carrière Morrison" 22 description "Carrière inondée" 23 notes "Accès par le quai 24 \tPlateformes à 6 m et 12 m" 25 gps 45.650000 -75.916667 26 geo cat 2 origin 0 "Canada" 27 28 """ 29 30 static let dive41 = """ 31 duration 45:30 min 32 rating 4 33 visibility 3 34 tags "bateau", "épave" 35 divesiteid 7f3a1b2c 36 divemaster "Alex" 37 buddy "Sam, Max" 38 suit "7 mm" 39 notes "Belle plongée. 40 \tTortue \\"verte\\" au palier. 41 42 \tFin." 43 cylinder vol=11.1l workpressure=207.0bar description="AL80" o2=32.0% start=200.0bar end=60.0bar depth=33.998m 44 cylinder vol=5.7l description="AL40" o2=50.0% use="not used" 45 weightsystem weight=6.0kg description="ceinture" 46 watertemp 24.5°C 47 futurekeyword 42 "inconnu de cette app" 48 49 """ 50 51 static let computer41 = """ 52 model "Shearwater Petrel 3" 53 deviceid 4d1b2c3a 54 diveid 5e6f7a8b 55 maxdepth 30.5m 56 meandepth 16.2m 57 airtemp 28.0°C 58 watertemp 24.0°C 59 surfacepressure 1.013bar 60 salinity 1025g/l 61 keyvalue "Serial" "1234" 62 event 0:00 type=25 flags=1 name="gaschange" cylinder=0 o2=32.0% 63 event 12:10 type=3 value=1 name="ascent" 64 0:00 0.0m 26.0°C 200.0bar:0 ndl=99:00 65 0:10 3.2m 66 1:00 12.0m 25.0°C 195.0bar:0 ndl=45:00 cns=1% 67 20:00 30.5m 24.0°C in_deco=1 stopdepth=3.0m stoptime=2:00 tts=8:00 68 30:00 15.0m in_deco=0 stopdepth=0.0m 69 45:30 0.0m 60.0bar:0 70 71 """ 72 73 static let trip = """ 74 date 2024-08-02 75 time 09:00:00 76 location "Bonaire" 77 notes "Semaine de plongée du bord" 78 79 """ 80 81 static func simpleDive(buddy: String) -> String { 82 "duration 50:00 min\nbuddy \"\(buddy)\"\n" 83 } 84 85 static func simpleComputer(model: String, depth: String) -> String { 86 "model \"\(model)\"\nmaxdepth \(depth)m\nmeandepth 9.0m\nwatertemp 27.0°C\n 0:00 0.0m\n 25:00 \(depth)m\n 50:00 0.0m\n" 87 } 88 89 /// Bare "server" repository, with the user's branch, and the working repository that filled it. 90 static func makeRemote() throws -> (remote: LocalGit, work: LocalGit) { 91 let work = try LocalGit.create(name: "work") 92 try work.write("00-Subsurface", settings) 93 try work.write("01-Divesites/Site-7f3a1b2c", site) 94 try work.write("2024/07/13-Sat-10=15=30/Dive-41", dive41) 95 try work.write("2024/07/13-Sat-10=15=30/Divecomputer", computer41) 96 try work.write("2024/08/02-Bonaire~1a2b3c4/00-Trip", trip) 97 try work.write("2024/08/02-Bonaire~1a2b3c4/02-Fri-09=00=00/Dive-42", simpleDive(buddy: "Sam")) 98 try work.write("2024/08/02-Bonaire~1a2b3c4/02-Fri-09=00=00/Divecomputer", simpleComputer(model: "Shearwater Petrel 3", depth: "18.0")) 99 // Dive of the trip that fell in the following month: the month is repeated in the directory name. 100 try work.write("2024/08/02-Bonaire~1a2b3c4/09-01-Sun-08=30=00~abcdef1/Dive-43", simpleDive(buddy: "Max")) 101 try work.write("2024/08/02-Bonaire~1a2b3c4/09-01-Sun-08=30=00~abcdef1/Divecomputer-001", simpleComputer(model: "Shearwater Petrel 3", depth: "21.5")) 102 try work.write("2024/08/02-Bonaire~1a2b3c4/09-01-Sun-08=30=00~abcdef1/Divecomputer-002", simpleComputer(model: "Suunto D5", depth: "21.9")) 103 try work.commitAll("carnet de test") 104 let remote = try LocalGit.create(bare: true, name: "remote") 105 try work.git(["remote", "add", "origin", remote.directory.path]) 106 try work.git(["push", "-q", "origin", "main:refs/heads/\(branch)"]) 107 return (remote, work) 108 } 109 110 static func when(_ y: Int, _ mo: Int, _ d: Int, _ h: Int, _ mi: Int, _ s: Int) -> Int { 111 var calendar = Calendar(identifier: .gregorian) 112 calendar.timeZone = TimeZone(identifier: "UTC")! 113 return Int(calendar.date(from: DateComponents(year: y, month: mo, day: d, hour: h, minute: mi, second: s))!.timeIntervalSince1970) 114 } 115 }