From 40c6dcc53fa6c7a0b16b3822c0287435b6b6d789 Mon Sep 17 00:00:00 2001 From: Liam Nichols Date: Thu, 4 Apr 2019 15:39:53 +0100 Subject: [PATCH] Add test to ensure that all valid pattern sequences exist within each format object provided --- Tests/FormatProviderTests.swift | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Tests/FormatProviderTests.swift b/Tests/FormatProviderTests.swift index 85e6a8b..7d8cd76 100644 --- a/Tests/FormatProviderTests.swift +++ b/Tests/FormatProviderTests.swift @@ -67,3 +67,40 @@ class FormatProviderTests: XCTestCase { XCTAssertNil(format) } } + +class FormatProviderPatternTests: XCTestCase { + + func testAllPatternsInBundle() throws { + + let bundle = Bundle(for: ListItemFormatter.self) + + let localeInformation = try LocaleInformation(bundle: bundle) + let provider = FormatProvider(bundle: bundle) + + XCTAssertFalse(localeInformation.localeIdentifiers.isEmpty) + + let combinations: [(ListItemFormatter.Mode, ListItemFormatter.Style)] = [ + (.standard, .default), + (.standard, .short), + (.standard, .narrow), + (.or, .default), + (.or, .short), + (.or, .narrow), + (.unit, .default), + (.unit, .short), + (.unit, .narrow), + ] + + for identifier in localeInformation.localeIdentifiers { + for (mode, style) in combinations { + + let locale = Locale(identifier: identifier) + let format = provider.format(for: locale) + let patterns = format?.getPatterns(for: style, mode: mode) + + XCTAssertNotNil(format) + XCTAssertNotNil(patterns) + } + } + } +}