2023-01-25 18:06:23 +00:00
@ testable import Views
import XCTest
final class LocalTextTests : XCTestCase {
func testThatLocalTextFindsStrings ( ) {
// M a k e s u r e t h a t t h e s a m e k e y i s n o t r e t u r n e d w h e n l o o k i n g u p a l o c a l i z e d s t r i n g b y k e y
2023-02-17 19:37:58 +00:00
// T e s t i n g t h e f i r s t a n d l a s t e n t r y i n t h e s t r i n g s f i l e i s a d e q u a t e f o r f i n d i n g s y n t a x e r r o r s .
2023-01-25 18:06:23 +00:00
// I f a n y e n t r y i s n o t p r o p e r t h a n t h e k e y w i l l b e r e t u r n e d a n d t h e t e s t w i l l f a i l .
2023-01-25 18:23:01 +00:00
for languageCode in LanguageCode . allCases {
2023-02-17 19:37:58 +00:00
// s w i f t l i n t : d i s a b l e l i n e _ l e n g t h
XCTAssertNotEqual ( languageCode . translation ( key : " unitTestLeadingEntry " ) , " unitTestLeadingEntry " , " Got untranslated value for unitTestLeadingEntry in \( languageCode ) " )
XCTAssertNotEqual ( languageCode . translation ( key : " unitTestTrailingEntry " ) , " unitTestTrailingEntry " , " Got untranslated value for unitTestTrailingEntry in \( languageCode ) " )
// s w i f t l i n t : e n a b l e l i n e _ l e n g t h
2023-01-25 18:23:01 +00:00
}
2023-01-25 18:06:23 +00:00
}
2023-01-25 18:23:01 +00:00
static var allTests = [
( " testThatLocalTextFindsStrings " , testThatLocalTextFindsStrings )
]
}
private enum LanguageCode : String , CaseIterable {
case english = " en "
case simpleChinese = " zh-Hans "
case spanish = " es "
func translation ( key : String ) -> String {
2023-01-25 18:06:23 +00:00
guard
2023-01-25 18:23:01 +00:00
let bundlePath = Bundle . module . path ( forResource : rawValue , ofType : " lproj " ) ,
2023-01-25 18:06:23 +00:00
let bundle = Bundle ( path : bundlePath )
else { return key }
return NSLocalizedString ( key , bundle : bundle , comment : " " )
}
}