@@ -5019,22 +5019,28 @@ public class ProgramBuilder {
50195019 // so we instead register a generator that allows the fuzzer a greater chance of generating
50205020 // one when needed.
50215021 //
5022- // These can be registered on the JavaScriptEnvironment with addProducingGenerator()
5022+ // These can be registered on the JavaScriptEnvironment with addProducingGenerator().
5023+ // argument `predefined`: Provide values that should be used for the given properties of the
5024+ // options bag (if present) instead of finding or generating random values for them. The
5025+ // property might still be filtered out.
50235026 @discardableResult
5024- func createOptionsBag( _ bag: OptionsBag ) -> Variable {
5027+ func createOptionsBag( _ bag: OptionsBag , predefined : [ String : Variable ] = [ : ] ) -> Variable {
50255028 // We run .filter() to pick a subset of fields, but we generally want to set as many as possible
50265029 // and let the mutator prune things
5027- let dict : [ String : Variable ] = bag. properties. filter { _ in probability ( 0.8 ) } . mapValues {
5028- if $0. isEnumeration {
5029- return loadEnum ( $0)
5030+ let dict = [ String : Variable] ( uniqueKeysWithValues: bag. properties. filter { _ in probability ( 0.8 ) } . map {
5031+ let ( propertyName, type) = $0
5032+ if let predefinedVar = predefined [ propertyName] {
5033+ return ( propertyName, predefinedVar)
5034+ } else if type. isEnumeration {
5035+ return ( propertyName, loadEnum ( type) )
50305036 // relativeTo doesn't have an ObjectGroup so we cannot just register a producingGenerator for it
5031- } else if $0 . Is ( OptionsBag . jsTemporalRelativeTo) {
5032- return findOrGenerateType ( chooseUniform ( from: [ . jsTemporalZonedDateTime, . jsTemporalPlainDateTime,
5033- . jsTemporalPlainDate, . string] ) )
5037+ } else if type . Is ( OptionsBag . jsTemporalRelativeTo) {
5038+ return ( propertyName , findOrGenerateType ( chooseUniform ( from: [ . jsTemporalZonedDateTime, . jsTemporalPlainDateTime,
5039+ . jsTemporalPlainDate, . string] ) ) )
50345040 } else {
5035- return findOrGenerateType ( $0 )
5041+ return ( propertyName , findOrGenerateType ( type ) )
50365042 }
5037- }
5043+ } )
50385044 return createObject ( with: dict)
50395045 }
50405046
@@ -5403,6 +5409,29 @@ public class ProgramBuilder {
54035409 fileprivate static let allScripts = [ " Adlm " , " Afak " , " Aghb " , " Ahom " , " Arab " , " Aran " , " Armi " , " Armn " , " Avst " , " Bali " , " Bamu " , " Bass " , " Batk " , " Beng " , " Berf " , " Bhks " , " Blis " , " Bopo " , " Brah " , " Brai " , " Bugi " , " Buhd " , " Cakm " , " Cans " , " Cari " , " Cham " , " Cher " , " Chis " , " Chrs " , " Cirt " , " Copt " , " Cpmn " , " Cprt " , " Cyrl " , " Cyrs " , " Deva " , " Diak " , " Dogr " , " Dsrt " , " Dupl " , " Egyd " , " Egyh " , " Egyp " , " Elba " , " Elym " , " Ethi " , " Gara " , " Geok " , " Geor " , " Glag " , " Gong " , " Gonm " , " Goth " , " Gran " , " Grek " , " Gujr " , " Gukh " , " Guru " , " Hanb " , " Hang " , " Hani " , " Hano " , " Hans " , " Hant " , " Hatr " , " Hebr " , " Hira " , " Hluw " , " Hmng " , " Hmnp " , " Hntl " , " Hrkt " , " Hung " , " Inds " , " Ital " , " Jamo " , " Java " , " Jpan " , " Jurc " , " Kali " , " Kana " , " Kawi " , " Khar " , " Khmr " , " Khoj " , " Kitl " , " Kits " , " Knda " , " Kore " , " Kpel " , " Krai " , " Kthi " , " Lana " , " Laoo " , " Latf " , " Latg " , " Latn " , " Leke " , " Lepc " , " Limb " , " Lina " , " Linb " , " Lisu " , " Loma " , " Lyci " , " Lydi " , " Mahj " , " Maka " , " Mand " , " Mani " , " Marc " , " Maya " , " Medf " , " Mend " , " Merc " , " Mero " , " Mlym " , " Modi " , " Mong " , " Moon " , " Mroo " , " Mtei " , " Mult " , " Mymr " , " Nagm " , " Nand " , " Narb " , " Nbat " , " Newa " , " Nkdb " , " Nkgb " , " Nkoo " , " Nshu " , " Ogam " , " Olck " , " Onao " , " Orkh " , " Orya " , " Osge " , " Osma " , " Ougr " , " Palm " , " Pauc " , " Pcun " , " Pelm " , " Perm " , " Phag " , " Phli " , " Phlp " , " Phlv " , " Phnx " , " Piqd " , " Plrd " , " Prti " , " Psin " , " Qaaa-Qabx " , " Ranj " , " Rjng " , " Rohg " , " Roro " , " Runr " , " Samr " , " Sara " , " Sarb " , " Saur " , " Seal " , " Sgnw " , " Shaw " , " Shrd " , " Shui " , " Sidd " , " Sidt " , " Sind " , " Sinh " , " Sogd " , " Sogo " , " Sora " , " Soyo " , " Sund " , " Sunu " , " Sylo " , " Syrc " , " Syre " , " Syrj " , " Syrn " , " Tagb " , " Takr " , " Tale " , " Talu " , " Taml " , " Tang " , " Tavt " , " Tayo " , " Telu " , " Teng " , " Tfng " , " Tglg " , " Thaa " , " Thai " , " Tibt " , " Tirh " , " Tnsa " , " Todr " , " Tols " , " Toto " , " Tutg " , " Ugar " , " Vaii " , " Visp " , " Vith " , " Wara " , " Wcho " , " Wole " , " Xpeo " , " Xsux " , " Yezi " , " Yiii " , " Zanb " , " Zinh " , " Zmth " , " Zsye " , " Zsym " , " Zxxx " , " Zyyy " , " Zzzz " ]
54045410 fileprivate static let allAlpha = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
54055411 fileprivate static let allAlphaNum = allAlpha + " 0123456789 "
5412+ fileprivate static let allRegionsTwoDigit = [
5413+ " AD " , " AE " , " AF " , " AG " , " AI " , " AL " , " AM " , " AO " , " AQ " , " AR " , " AS " , " AT " ,
5414+ " AU " , " AW " , " AX " , " AZ " , " BA " , " BB " , " BD " , " BE " , " BF " , " BG " , " BH " , " BI " ,
5415+ " BJ " , " BL " , " BM " , " BN " , " BO " , " BQ " , " BR " , " BS " , " BT " , " BV " , " BW " , " BY " ,
5416+ " BZ " , " CA " , " CC " , " CD " , " CF " , " CG " , " CH " , " CI " , " CK " , " CL " , " CM " , " CN " ,
5417+ " CO " , " CR " , " CU " , " CV " , " CW " , " CX " , " CY " , " CZ " , " DE " , " DJ " , " DK " , " DM " ,
5418+ " DO " , " DZ " , " EC " , " EE " , " EG " , " EH " , " ER " , " ES " , " ET " , " FI " , " FJ " , " FK " ,
5419+ " FM " , " FO " , " FR " , " GA " , " GB " , " GD " , " GE " , " GF " , " GG " , " GH " , " GI " , " GL " ,
5420+ " GM " , " GN " , " GP " , " GQ " , " GR " , " GS " , " GT " , " GU " , " GW " , " GY " , " HK " , " HM " ,
5421+ " HN " , " HR " , " HT " , " HU " , " ID " , " IE " , " IL " , " IM " , " IN " , " IO " , " IQ " , " IR " ,
5422+ " IS " , " IT " , " JE " , " JM " , " JO " , " JP " , " KE " , " KG " , " KH " , " KI " , " KM " , " KN " ,
5423+ " KP " , " KR " , " KW " , " KY " , " KZ " , " LA " , " LB " , " LC " , " LI " , " LK " , " LR " , " LS " ,
5424+ " LT " , " LU " , " LV " , " LY " , " MA " , " MC " , " MD " , " ME " , " MF " , " MG " , " MH " , " MK " ,
5425+ " ML " , " MM " , " MN " , " MO " , " MP " , " MQ " , " MR " , " MS " , " MT " , " MU " , " MV " , " MW " ,
5426+ " MX " , " MY " , " MZ " , " NA " , " NC " , " NE " , " NF " , " NG " , " NI " , " NL " , " NO " , " NP " ,
5427+ " NR " , " NU " , " NZ " , " OM " , " PA " , " PE " , " PF " , " PG " , " PH " , " PK " , " PL " , " PM " ,
5428+ " PN " , " PR " , " PS " , " PT " , " PW " , " PY " , " QA " , " RE " , " RO " , " RS " , " RU " , " RW " ,
5429+ " SA " , " SB " , " SC " , " SD " , " SE " , " SG " , " SH " , " SI " , " SJ " , " SK " , " SL " , " SM " ,
5430+ " SN " , " SO " , " SR " , " SS " , " ST " , " SV " , " SX " , " SY " , " SZ " , " TC " , " TD " , " TF " ,
5431+ " TG " , " TH " , " TJ " , " TK " , " TL " , " TM " , " TN " , " TO " , " TR " , " TT " , " TV " , " TW " ,
5432+ " TZ " , " UA " , " UG " , " UM " , " US " , " UY " , " UZ " , " VA " , " VC " , " VE " , " VG " , " VI " ,
5433+ " VN " , " VU " , " WF " , " WS " , " YE " , " YT " , " ZA " , " ZM " , " ZW " ,
5434+ ]
54065435
54075436 @discardableResult
54085437 static func constructIntlUnit( ) -> String {
@@ -5429,7 +5458,7 @@ public class ProgramBuilder {
54295458 static func constructIntlRegionString( ) -> String {
54305459 // either two letters or three digits
54315460 if probability ( 0.5 ) {
5432- return String ( ( 0 ..< 2 ) . map { _ in allAlpha . randomElement ( ) ! } )
5461+ return allRegionsTwoDigit . randomElement ( ) !
54335462 } else {
54345463 return String ( format: " %03d " , Int . random ( in: 0 ... 999 ) )
54355464 }
@@ -5495,6 +5524,11 @@ public class ProgramBuilder {
54955524 return constructIntlType ( type: " Collator " , optionsBag: . jsIntlCollatorSettings)
54965525 }
54975526
5527+ @discardableResult
5528+ func constructIntlDisplayNames( ) -> Variable {
5529+ return constructIntlType ( type: " DisplayNames " , optionsBag: . jsIntlDisplayNamesSettings)
5530+ }
5531+
54985532 @discardableResult
54995533 func constructIntlListFormat( ) -> Variable {
55005534 return constructIntlType ( type: " ListFormat " , optionsBag: . jsIntlListFormatSettings)
0 commit comments