fixtures/attribute_generators.rb

Lines

100%

17 of 17 covered

Branches

—

0 of 0 covered

Methods

—

0 of 0 covered

1# frozen_string_literal: true
2
3# Quickdraw generators for attribute hashes, with words that reach the
4# escaping, reference and unsafe-name checks.
52module AttributeGenerators
62 G = Quickdraw::Generators
7
8 TEXT_WORDS = (
92 %w[javascript: JavaScript java script : : ∷ : : &#X3A j j &#0000106 �] +
10 %w[&tab; &Tab; &newline; &NewLine; &#9; &#x0a; &amp; &quot; & # ; " ' < > / = _ - j J] +
11 " \t\n\r\0\fİKſ".chars
12 ).freeze
13
14 NAME_WORDS = (
152 %w[on ON click href Href src xlink xlink:href formaction srcdoc sandbox http-equiv http equiv] +
16 %w[id ID data aria style class title _ - : " ' = < > /] +
17 " \t\0İK".chars
18 ).freeze
19
202 TEXT = G.one_of(G.string(:ascii, dictionary: TEXT_WORDS), G.string(dictionary: TEXT_WORDS))
212 NAME = G.string(:ascii, length: 0..10, dictionary: NAME_WORDS)
222 KEY = G.one_of(NAME.map(&:to_sym), NAME, :_)
23
242 SCALAR = G.one_of(
25 TEXT,
26 NAME.map(&:to_sym),
27 G.integer,
28 G.float,
29 true,
30 false,
31 nil,
3281 TEXT.map { |text| Phlex::SGML::SafeValue.new(text) },
33 )
34
352 TOKENS = G.array(G.one_of(SCALAR, G.array(SCALAR, length: 0..3)), length: 0..4)
36
372 NESTED = G.hash_of(KEY, G.one_of(SCALAR, TOKENS, G.hash_of(KEY, SCALAR, length: 0..3)), length: 0..3)
38
39113 VALUE = G.one_of(SCALAR, TOKENS, TOKENS.map { |tokens| Set.new(tokens) }, NESTED)
40
412 ATTRIBUTES = G.hash_of(KEY, VALUE, length: 0..4)
42
43 # Text that isn't valid UTF-8 or isn't ASCII-compatible, which some string
44 # operations refuse.
452 ENCODED_TEXT = G.one_of(
468 TEXT.map { |text| text.encode(Encoding::UTF_16LE) },
478 TEXT.map { |text| (text.b << "\xFF".b).force_encoding(Encoding::UTF_8) },
488 TEXT.map { |text| text.b << "\xFF".b },
49 )
50end