<commit_before>require 'hanami/view'
require 'hanami/controller'
require 'hanami/helpers/html_helper'
require 'hanami/helpers/escape_helper'
require 'dry/struct'

module Types
  include Dry::Types.module
end

Store = Struct.new(:code, :label) do
  def to_ary
    [label, code]
  end
end

class Signup < Dry::Struct
  attribute :password, Types::String.optional
end

class HtmlView
  include Hanami::Helpers::HtmlHelper

  def empty_div
    html.div
  end

  def div_with_string_content
    html.div('hello world')
  end

  def div_with_block_content_as_string
    html.div { 'hola' }
  end

  def div_with_block_content_with_tag_helper
    html.div(html.p('inner'))
  end

  def div_with_block_content_with_nested_calls
    html.div do
      span 'hello'
    end
  end

  def div_with_block_content_and_multiple_nested_calls
    html.form(action: '/users', method: 'POST') do
      div do
        label 'First name', for: 'user-first-name'
        input type: 'text', id: 'user-first-name', name: 'user[first_name]', value: 'L'
      end

      input type: 'submit', value: 'Save changes'
    end
  end

  def concatenation_of_multiple_fragments
    hello  = html { div 'Hello' }
    hanami = html { div 'Hanami' }

    hello + hanami
  end

  def concatenation_of_multiple_divs
    html.div('Hello') + html.div('Hanami')
  end

  def concatenation_of_fragment_and_div
    html { div 'Hello' } + html.div('Hanami')
  end

  def fragment_with_block_content
    html do
      div 'Hello'
      div 'Hanami'
    end
  end

  def div_with_attr
    html.div(id: 'container')
  end

  # RUBY_VERSION >= '2.2'
  # def div_with_data_attr
  #   html.div('data-where': 'up')
  # end
  def div_with_data_attr
    html.div('data-where': 'up')
  end

  def div_with_attrs
    html.div(id: 'content', class: 'filled')
  end

  def div_with_string_content_and_attrs
    html.div('ciao', id: 'greeting', class: 'blink')
  end

  def div_with_block_content_as_string_and_attrs
    html.div(id: 'sidebar', class: 'blue') { 'bonjour' }
  end

  def custom_tag
    html.tag(:custom, 'Foo', id: 'next')
  end

  def custom_empty_tag
    html.empty_tag(:xr, id: 'next')
  end

  def evil_string_content
    html.div("<script>alert('xss')</script>")
  end

  def evil_block_content
    html.div { "<script>alert('xss')</script>" }
  end

  def evil_tag_helper
    html.div(html.p("<script>alert('xss')</script>"))
  end

  def evil_nested_block_content
    html.div do
      p "<script>alert('xss')</script>"
    end
  end
end

class NumbersView
  include Hanami::Helpers::NumberFormattingHelper

  def single_digit
    format_number 1
  end

  def thousand_digits
    format_number 1_000
  end

  def million_digits
    format_number 1_000_000
  end

  def zero_point_one
    format_number 0.1
  end

  def precision_default_format
    format_number 3.141592
  end

  def precision_format
    format_number 3.141592, precision: 4
  end

  def precision_higher_than_numbers_precision
    format_number 3.14, precision: 4
  end

  def zero_precision
    format_number 3.14, precision: 0
  end

  def mixed_digits
    format_number 5002.007, precision: 3
  end

  def euro_format
    format_number 1234.12, delimiter: '.', separator: ','
  end

  def pass_nil
    format_number nil
  end

  def pass_class_name
    format_number Object
  end

  def pass_string
    format_number 'string'
  end

  def pass_non_numeric_integer
    format_number '1'
  end

  def pass_non_numeric_float
    format_number '1.0'
  end

  def big_decimal
    format_number BigDecimal.new('0.0001'), precision: 4
  end

  def complex
    format_number Complex(1)
  end

  def rational
    format_number Rational(1)
  end

  def string
    format_number Rational(1)
  end

  def infinity
    format_number Float::INFINITY
  end

  def nan
    format_number 0.0 / 0
  end
end

class EscapeView
  include Hanami::Helpers::EscapeHelper

  def good_string
    escape_html 'this is a good string'
  end

  def evil_string
    escape_html "<script>alert('xss')</script>"
  end

  def good_attributes_string
    "<a title='#{escape_html_attribute('foo')}'>link</a>"
  end

  def evil_attributes_string
    "<a title='#{escape_html_attribute('<script>alert(\'xss\')</script>')}'>link</a>"
  end

  def good_url_string
    escape_url 'http://hanamirb.org'
  end

  def evil_url_string
    escape_url "javascript:alert('xss')"
  end

  def raw_string
    raw "<div>I'm a raw string</div>"
  end

  def html_string_alias
    h 'this is a good string'
  end

  def html_attribute_string_alias
    "<a title='#{ha('foo')}'>link</a>"
  end

  def url_string_alias
    hu 'http://hanamirb.org'
  end
end

class Book < Dry::Struct
  constructor_type :weak
<commit_msg>Make fixture to work with dry-struct ~> 0.4<commit_after>require 'hanami/view'
require 'hanami/controller'
require 'hanami/helpers/html_helper'
require 'hanami/helpers/escape_helper'
require 'dry/struct'

module Types
  include Dry::Types.module
end

Store = Struct.new(:code, :label) do
  def to_ary
    [label, code]
  end
end

class Signup < Dry::Struct
  attribute :password, Types::String.optional
end

class HtmlView
  include Hanami::Helpers::HtmlHelper

  def empty_div
    html.div
  end

  def div_with_string_content
    html.div('hello world')
  end

  def div_with_block_content_as_string
    html.div { 'hola' }
  end

  def div_with_block_content_with_tag_helper
    html.div(html.p('inner'))
  end

  def div_with_block_content_with_nested_calls
    html.div do
      span 'hello'
    end
  end

  def div_with_block_content_and_multiple_nested_calls
    html.form(action: '/users', method: 'POST') do
      div do
        label 'First name', for: 'user-first-name'
        input type: 'text', id: 'user-first-name', name: 'user[first_name]', value: 'L'
      end

      input type: 'submit', value: 'Save changes'
    end
  end

  def concatenation_of_multiple_fragments
    hello  = html { div 'Hello' }
    hanami = html { div 'Hanami' }

    hello + hanami
  end

  def concatenation_of_multiple_divs
    html.div('Hello') + html.div('Hanami')
  end

  def concatenation_of_fragment_and_div
    html { div 'Hello' } + html.div('Hanami')
  end

  def fragment_with_block_content
    html do
      div 'Hello'
      div 'Hanami'
    end
  end

  def div_with_attr
    html.div(id: 'container')
  end

  # RUBY_VERSION >= '2.2'
  # def div_with_data_attr
  #   html.div('data-where': 'up')
  # end
  def div_with_data_attr
    html.div('data-where': 'up')
  end

  def div_with_attrs
    html.div(id: 'content', class: 'filled')
  end

  def div_with_string_content_and_attrs
    html.div('ciao', id: 'greeting', class: 'blink')
  end

  def div_with_block_content_as_string_and_attrs
    html.div(id: 'sidebar', class: 'blue') { 'bonjour' }
  end

  def custom_tag
    html.tag(:custom, 'Foo', id: 'next')
  end

  def custom_empty_tag
    html.empty_tag(:xr, id: 'next')
  end

  def evil_string_content
    html.div("<script>alert('xss')</script>")
  end

  def evil_block_content
    html.div { "<script>alert('xss')</script>" }
  end

  def evil_tag_helper
    html.div(html.p("<script>alert('xss')</script>"))
  end

  def evil_nested_block_content
    html.div do
      p "<script>alert('xss')</script>"
    end
  end
end

class NumbersView
  include Hanami::Helpers::NumberFormattingHelper

  def single_digit
    format_number 1
  end

  def thousand_digits
    format_number 1_000
  end

  def million_digits
    format_number 1_000_000
  end

  def zero_point_one
    format_number 0.1
  end

  def precision_default_format
    format_number 3.141592
  end

  def precision_format
    format_number 3.141592, precision: 4
  end

  def precision_higher_than_numbers_precision
    format_number 3.14, precision: 4
  end

  def zero_precision
    format_number 3.14, precision: 0
  end

  def mixed_digits
    format_number 5002.007, precision: 3
  end

  def euro_format
    format_number 1234.12, delimiter: '.', separator: ','
  end

  def pass_nil
    format_number nil
  end

  def pass_class_name
    format_number Object
  end

  def pass_string
    format_number 'string'
  end

  def pass_non_numeric_integer
    format_number '1'
  end

  def pass_non_numeric_float
    format_number '1.0'
  end

  def big_decimal
    format_number BigDecimal.new('0.0001'), precision: 4
  end

  def complex
    format_number Complex(1)
  end

  def rational
    format_number Rational(1)
  end

  def string
    format_number Rational(1)
  end

  def infinity
    format_number Float::INFINITY
  end

  def nan
    format_number 0.0 / 0
  end
end

class EscapeView
  include Hanami::Helpers::EscapeHelper

  def good_string
    escape_html 'this is a good string'
  end

  def evil_string
    escape_html "<script>alert('xss')</script>"
  end

  def good_attributes_string
    "<a title='#{escape_html_attribute('foo')}'>link</a>"
  end

  def evil_attributes_string
    "<a title='#{escape_html_attribute('<script>alert(\'xss\')</script>')}'>link</a>"
  end

  def good_url_string
    escape_url 'http://hanamirb.org'
  end

  def evil_url_string
    escape_url "javascript:alert('xss')"
  end

  def raw_string
    raw "<div>I'm a raw string</div>"
  end

  def html_string_alias
    h 'this is a good string'
  end

  def html_attribute_string_alias
    "<a title='#{ha('foo')}'>link</a>"
  end

  def url_string_alias
    hu 'http://hanamirb.org'
  end
end

class Book < Dry::Struct
  constructor_type :schema

{'fraction_non_alphanumeric': 0.0979020979020979, 'fraction_numerical': 0.014621741894469168, 'mean_word_length': 3.317932296431839, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3677784', 'n_tokens_mistral': 3532, 'n_tokens_neox': 3320, 'n_words': 802}