SPB Git

Repository Public MIT

GlassL10nTests.swift 4.5 KB 107 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Tests/SPGlassCoreTests/GlassL10nTests.swift8// Module           : SPGlassCoreTests9// Repository       : https://git.spboucher.ai/sp-glasskit10// Project Website  : https://glass.spboucher.ai11// Created          : 2026-12-0212// Last Modified    : 2026-12-0213//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Foundation42import Testing43@testable import SPGlassCore4445@Suite("Localisation")46struct GlassL10nTests {47    @Test("Every key is translated in each supported localisation", arguments: GlassL10n.supportedLocalizations)48    func everyKeyIsTranslated(localization: String) {49        for key in GlassL10n.Key.allCases {50            let value = GlassL10n.string(key, localization: localization)51            #expect(value != key.rawValue, "\(key.rawValue) is missing in \(localization)")52            #expect(!value.isEmpty)53        }54    }5556    @Test("String files define exactly the declared keys", arguments: GlassL10n.supportedLocalizations)57    func noOrphanKeys(localization: String) throws {58        let path = try #require(GlassL10n.bundle.path(forResource: "GlassKit", ofType: "strings", inDirectory: nil, forLocalization: localization))59        let table = try #require(NSDictionary(contentsOfFile: path) as? [String: String])60        #expect(Set(table.keys) == Set(GlassL10n.Key.allCases.map(\.rawValue)))61    }6263    @Test("French and English use the same format specifiers")64    func formatSpecifiersMatch() {65        func specifiers(_ text: String) -> [String] {66            let regex = /%(\d+\$)?(lld|@|d)/67            return text.matches(of: regex).map { String($0.output.0) }.sorted()68        }69        for key in GlassL10n.Key.allCases {70            #expect(specifiers(GlassL10n.string(key, localization: "en")) == specifiers(GlassL10n.string(key, localization: "fr")), "\(key.rawValue)")71        }72    }7374    @Test("Formatted strings substitute their arguments")75    func formatting() {76        let text = String(format: GlassL10n.string(.charactersOfLimit, localization: "en"), 12, 140)77        #expect(text == "12 of 140 characters")78    }79}8081@Suite("Core types")82struct GlassCoreTypesTests {83    @Test func densityMultipliersAreOrdered() {84        #expect(GlassDensity.compact.spacingMultiplier < GlassDensity.regular.spacingMultiplier)85        #expect(GlassDensity.regular.spacingMultiplier < GlassDensity.comfortable.spacingMultiplier)86        #expect(GlassDensity.regular.spacingMultiplier == 1)87    }8889    @Test func loadStateAccessors() {90        #expect(GlassLoadState<Int>.loaded(3).value == 3)91        #expect(GlassLoadState<Int>.loading.isLoading)92        #expect(GlassLoadState<Int>.empty.value == nil)93        #expect(GlassLoadState<Int>.failed(message: "x") != .idle)94    }9596    @Test func kindRawValuesMatchTheRegistrySchema() {97        #expect(GlassComponentKind.nativeWrapper.rawValue == "native-wrapper")98        #expect(GlassComponentKind.customGlass.rawValue == "custom-glass")99        #expect(GlassComponentKind.contentComponent.rawValue == "content-component")100    }101102    @Test func accessibilityOverridesDefaultToNoSimulation() {103        #expect(GlassAccessibilityOverrides.none.reduceMotion == nil)104        #expect(GlassAccessibilityOverrides.none.reduceTransparency == nil)105    }106}107
Files main
Menu

Theme