def get_svg_animatable_attribute(elem): has_regular = elem in svg_animatable_regular_attributes has_presentation = elem in svg_animatable_presentation_attributes if (not has_presentation) or (has_regular and Random.bool()): return Random.choice(svg_animatable_regular_attributes[elem]) else: return Random.choice(svg_animatable_presentation_attributes[elem])
def generate(self, _): values = [ Random.choice([ "xMinYMin", "xMidYMin", "xMaxYMin", "xMinYMid", "xMidYMid", "xMaxYMid", "xMinYMax", "xMidYMax", "xMaxYMax" ]) ] if Random.bool(): values.append(Random.choice(["meet", "slice"])) self.value = cat(values)
def line_to(): if Random.bool(): cmd = Random.choice(["L", "l"]) x = Random.integer() y = Random.integer() return "{} {},{}".format(cmd, x, y) else: cmd = Random.choice(["H", "h", "V", "v"]) x = Random.integer() return "{} {}".format(cmd, x)
def color(): c = Random.selector(5) if c == 0: return Random.choice(["currentColor", "transparent"]) elif c == 1: return Random.choice(["red", "blue", "green", "black", "white"]) elif c == 2: return "#{}".format(Random.hex_digits(Random.choice([6, 8]))) elif c == 3: return "rgb({})".format(seq([Random.hex_byte() for _ in range(3)])) else: return "rgba({})".format(seq([Random.hex_byte() for _ in range(4)]))
def media_query(): media_type = Random.choice(["all", "print", "screen"]) if Random.bool(): return media_type media_feature = Random.choice( ["min-width", "max-width", "min-height", "max-height", "orientation"]) if media_feature == "orientation": media_feature_value = Random.choice(["portrait", "landscape"]) else: media_feature_value = "{}px".format(Random.integer()) return "{} and ({}:{})".format(media_type, media_feature, media_feature_value)
def insert_root_element(self, context): if self.full: return None if Random.selector(5) > 0: name = Random.choice(docs.html_general_child_elements) else: name = Random.choice(docs.html_other_child_elements) child = of.create_object(name) self.add_root_element(child) if child is not None: self.init_element(context, child) return child
def single(): values = [ "'{}'".format( Random.choice([ "smcp", "c2sc", "zero", "hist", "liga", "tnum", "frac", "swsh", "ss07", "dlig", "vert", "hwid", "twid", "qwid", "kern", "onum" ])) ] if Random.bool(): if Random.bool(): values.append(Random.choice(["on", "off"])) else: values.append(Random.integer()) return cat(values)
def input_type(): return Random.choice([ "button", "checkbox", "color", "date", "datetime-local", "email", "hidden", "image", "month", "number", "password", "radio", "range", "reset", "search", "submit", "tel", "text", "time", "url", "week", "datetime", "foo" # "file" ])
def list_size(): if Random.bool(): return Random.range(1, 5) else: # Special sizes that may trigger realloc # See ./animations/crash-when-animation-is-running-while-getting-value.html return Random.choice([7, 8, 9, 15, 16, 17, 31, 32, 33, 63, 64, 65])
def animation_easing(): value = Random.choice([ "linear", "ease", "ease-in", "ease-out", "ease-in-out", "cubic-bezier" ]) if value == "cubic-bezier": value += "({})".format(seq([Random.number() for _ in range(4)])) return value
def mutate(self, context) -> bool: c = Random.selector(1 + len(self.args)) if c == 0: return self.this.mutate(context) else: arg = Random.choice(self.args) return arg.mutate(context)
def insert_child(self): children = docs.svg_child_elements.get(self.name) if len(children) == 0: return None child = Random.choice(children) return self.generate_child(child)
def generate(self, _): c = Random.selector(3) if c == 0: self.value = Random.choice(["auto", "auto-start-reverse"]) elif c == 1: self.value = dv.angle() else: self.value = Random.number()
def font_stretch_value(): if Random.bool(): return Random.choice([ "normal", "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", "semi-expanded", "expanded", "extra-expanded", "ultra-expanded" ]) else: return percentage()
def length(relative=False): if (not relative) or Random.bool(): if Random.bool(): return "{}px".format(Random.integer()) else: return "{}em".format(Random.number()) else: return "{}{}".format(Random.integer(), Random.choice(["vw", "vh", "vmin", "vmax"]))
def lang(): return Random.choice([ "ar", "af", "en", "am", "ar-SA", "bg", "bn", "cs", "cy", "da", "de-DE", "el-GR", "en-US", "es-ES", "eu", "fa", "fi", "fr-fR", "gd", "gu", "he", "hi", "hr", "hu", "hy", "id", "is", "it", "iu", "ja-JP", "jw", "ka", "kk", "kn", "ko", "ky", "lt", "mk", "mr", "nl", "no", "or", "pl", "pt-PT", "pt-BR", "ro", "ru", "sa", "sr", "si", "sl", "sq", "sv", "ta", "te", "tg", "th", "tl", "tr", "tt", "uk", "ur-IN", "ur-PK", "uz", "vi", "yi", "zh-CN", "zh-TW", "fr", "fr-CA" ])
def mutate(self, context) -> bool: c = Random.selector(4) if c == 0 or len(self.declarations) == 0: return self.append(context) elif c == 1: del self.declarations[Random.selector(len(self.declarations))] return self.append(context) else: decl = Random.choice(self.declarations) return decl.mutate(context)
def image_url(): return "data:image/gif;base64,{}".format( Random.choice(( "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt" "+uBvAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9wDGhYvCNVA1EIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAjklEQVR42u3QIQEAMAgAsHNNVspTgARY1BZh0ZWP3VcgSJAgQYIECRKEIEGCBAkSJEgQggQJEiRIkCBBCBIkSJAgQYIECUKQIEGCBAkSJAhBggQJEiRIkCAECRIkSJAgQYIEIUiQIEGCBAkShCBBggQJEiRIEIIECRIkSJAgQYIQJEiQIEGCBAlCkCBBdwaeugIthHvZ+AAAAABJRU5ErkJggg==", "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAABGdBTUEAALGPC" "/xhBQAAAAlwSFlzAAAOxAAADsQBlSsOGwAAABh0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjIyt5EXfQAAAU5JREFUeF7t07ENACAMxMDA" "/jsDBTtcY6TUlmx+zcx510MGNuKG" "/QYKgL9CAQqADWB8CygANoDxLaAA2ADGt4ACYAMY3wIKgA1gfAsoADaA8S2gANgAxreAAmADGN8CCoANYHwLKAA2gPEtoADYAMa3gAJgAxjfAgqADWB8CygANoDxLaAA2ADGt4ACYAMY3wIKgA1gfAsoADaA8S2gANgAxreAAmADGN8CCoANYHwLKAA2gPEtoADYAMa3gAJgAxjfAgqADWB8CygANoDxLaAA2ADGt4ACYAMY3wIKgA1gfAsoADaA8S2gANgAxreAAmADGN8CCoANYHwLKAA2gPEtoADYAMa3gAJgAxjfAgqADWB8CygANoDxLaAA2ADGt4ACYAMY3wIKgA1gfAsoADaA8S2gANgAxreAAmADGN8CCoANYHwLKAA2gPEtAAe4i54BvwLfXFAAAAAASUVORK5CYII=" )))
def auto_complete(): if Random.bool(): return Random.choice(["on", "off"]) else: return Random.choice([ "name", "honorific-prefix", "given-name", "additional-name", "family-name", "honorific-suffix", "nickname", "email", "username", "new-password", "current-password", "one-time-code", "organization-title", "organization", "street-address", "address-line1", "address-line2", "address-line3", "address-level1", "address-level2", "address-level3", "address-level4", "country", "country-name", "postal-code", "cc-name", "cc-given-name", "cc-additional-name", "cc-family-name", "cc-number", "cc-exp", "cc-exp-month", "cc-exp-year", "cc-csc", "cc-type", "transaction-currency", "transaction-amount", "language", "bday", "bday-day", "bday-month", "bday-year", "sex", "tel", "tel-country-code", "tel-national", "tel-area-code", "tel-local", "tel-extension", "impp", "url", "photo" ])
def generate_rel2(self, context): self.abs = None self.action = None self.repeat_num = None self.event = None self.elem = context.get_object(docs.elements) if self.elem is None: self.generate_abs() return self.event = Random.choice(docs.svg_animation_begin_events)
def mutate_css_style_rule(self, context): count = len(self.css_style_rules) if count == 0: return False trial = 0 while trial < count: rule = Random.choice(self.css_style_rules) if rule.mutate(context): return True trial += 1 return False
def generate(self, context): scope = None if self.scope is not None: scope = context.in_tree_set.intersection(set(self.scope)) if scope is None or len(scope) == 0: scope = context.in_tree_set elem = Random.choice(list(scope)) if elem is not None: self.value = docs.tag_from_element(elem) else: self.value = None
def arc_curve(): cmd = Random.choice(["A", "a"]) rx = Random.integer() ry = Random.integer() _angle = Random.integer() large_arc_flag = Random.range(0, 1) sweep_flag = Random.range(0, 1) dx = Random.integer() dy = Random.integer() return "{} {} {} {} {} {} {},{}".format(cmd, rx, ry, _angle, large_arc_flag, sweep_flag, dx, dy)
def position(): c = Random.selector(3) if c == 0: values = [Random.choice(["left", "center", "right"])] if Random.bool(): values.append(Random.choice(["top", "center", "bottom"])) return cat(values) elif c == 1: values = [ Random.choice(["left", "center", "right"]), length_percentage() ] if Random.bool(): values.extend([ Random.choice(["top", "center", "bottom"]), length_percentage() ]) return cat(values) else: return cat([length_percentage(), length_percentage()])
def replace_attribute(self, context): if self.element_count == 0: return False elements = self.elements trial = 0 while trial < self.element_count: element = Random.choice(elements) if element.replace_attribute(context): return True trial += 1 return False
def generate_rel1(self, context): self.abs = None self.action = None self.repeat_num = None self.event = None self.elem = context.get_object(docs.svg_animation_elements) if self.elem is None: self.generate_abs() return self.action = Random.choice(["begin", "end", "repeat"]) if self.action == "repeat": self.repeat_num = Random.integer()
def mutate_text(self): if self.element_count == 0: return False elements = self.elements trial = 0 while trial < self.element_count: element = Random.choice(elements) if element.mutate_text(): return True trial += 1 return False
def generate_api(self): # 1. select an alive object (type) obj_names = list(self.context.superset_at_line) weights = [get_api_count(name) for name in obj_names] # 2. select an api that uses the object name as |this| while True: name = Random.choices(obj_names, weights)[0] template = Random.choice(js_apis[name]) if template.satiable(self.context): api = template.instantiate() api.generate(self.context) return api
def append_attribute(self, context): if self.element_count == 0: return False elements = self.elements trial = 0 while trial < self.element_count: element = Random.choice(elements) if get_attribute_count( element.name) > 0 and element.append_attribute(context): return True trial += 1 return False
def mutate(self, context) -> bool: c = Random.selector(4) if c == 0: prop = Random.choice(list(self.props.keys())) value_class = get_css_property_value(prop) value = value_class() value.generate(context) self.props[prop].append(value) return True elif c == 1: prop = Random.choice(list(self.props.keys())) values = self.props[prop] value = Random.choice(values) return value.mutate(context) elif c == 2: self.append_prop(context) return True else: # 3. replace property prop = Random.choice(list(self.props.keys())) del self.props[prop] self.append_prop(context) return True