<commit_before>require 'test_helper'

class SkipParseTest < MiniTest::Spec
  representer! do
    property :title, skip_parse: lambda { |options| options[:user_options][:skip?] and options[:fragment] == "skip me" }
    property :band,
      skip_parse: lambda { |options| options[:user_options][:skip?] and options[:fragment]["name"].nil? }, class: OpenStruct do
        property :name
    end

    collection :airplays,
      skip_parse: lambda { |options| options[:user_options][:skip?] and options[:fragment]["station"].nil? }, class: OpenStruct do
        property :station
    end
  end

  let (:song) { OpenStruct.new.extend(representer) }

  # do parse.
  it do
    song.from_hash({
      "title"    => "Victim Of Fate",
      "band"     => {"name" => "Mute 98"},
      "airplays" => [{"station" => "JJJ"}]
    }, user_options: { skip?: true })

    song.title.must_equal "Victim Of Fate"
    song.band.name.must_equal "Mute 98"
    song.airplays[0].station.must_equal "JJJ"
  end

  # skip parsing.
  let (:airplay) { OpenStruct.new(station: "JJJ") }

  it do
    song.from_hash({
      "title"    => "skip me",
      "band"     => {},
      "airplays" => [{"station" => "JJJ"}, {}],
    }, user_options: { skip?: true })

    song.title.must_equal nil
    song.band.must_equal nil
    song.airplays.must_equal [airplay]
  end
end

class SkipRenderTest < MiniTest::Spec
  representer! do
    property :title
    property :band,
      skip_render: lambda { |options| options[:user_options][:skip?] and options[:input].name == "Rancid" } do
        property :name
    end

    collection :airplays,
      skip_render: lambda { |options| options[:user_options][:skip?] and options[:input].station == "Radio Dreyeckland" } do
        property :station
    end
  end
<commit_msg>add some more complexity to the :skip_parse test.<commit_after>require 'test_helper'

class SkipParseTest < MiniTest::Spec
  representer! do
    property :title, skip_parse: lambda { |options| options[:user_options][:skip?] and options[:fragment] == "skip me" }
    property :band,
      skip_parse: lambda { |options| options[:user_options][:skip?] and options[:fragment]["name"].nil? }, class: OpenStruct do
        property :name
    end

    collection :airplays,
      skip_parse: lambda { |options| options[:user_options][:skip?] and options[:fragment]["station"].nil? }, class: OpenStruct do
        property :station
    end
  end

  let (:song) { OpenStruct.new.extend(representer) }

  # do parse.
  it do
    song.from_hash({
      "title"    => "Victim Of Fate",
      "band"     => {"name" => "Mute 98"},
      "airplays" => [{"station" => "JJJ"}]
    }, user_options: { skip?: true })

    song.title.must_equal "Victim Of Fate"
    song.band.name.must_equal "Mute 98"
    song.airplays[0].station.must_equal "JJJ"
  end

  # skip parsing.
  let (:airplay) { OpenStruct.new(station: "JJJ") }

  it do
    song.from_hash({
      "title"    => "skip me",
      "band"     => {},
      "airplays" => [{}, {"station" => "JJJ"}, {}],
    }, user_options: { skip?: true })

    song.title.must_equal nil
    song.band.must_equal nil
    song.airplays.must_equal [airplay]
  end
end

class SkipRenderTest < MiniTest::Spec
  representer! do
    property :title
    property :band,
      skip_render: lambda { |options| options[:user_options][:skip?] and options[:input].name == "Rancid" } do
        property :name
    end

    collection :airplays,
      skip_render: lambda { |options| options[:user_options][:skip?] and options[:input].station == "Radio Dreyeckland" } do
        property :station
    end
  end

{'fraction_non_alphanumeric': 0.1507495835646863, 'fraction_numerical': 0.00277623542476402, 'mean_word_length': 3.2091121495327104, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '1022720', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1165, 'n_words': 287}