<commit_before># encoding: utf-8

require 'test/helper'

class Nanoc3::Filters::HamlTest < MiniTest::Unit::TestCase

  include Nanoc3::TestHelpers

  def test_filter
    if_have 'haml' do
      # Create filter
      filter = ::Nanoc3::Filters::Haml.new({ :question => 'Is this the Payne residence?' })

      # Run filter (no assigns)
      result = filter.run('%html')
      assert_match(/<html>.*<\/html>/, result)

      # Run filter (assigns without @)
      result = filter.run('%p= question')
      assert_equal("<p>Is this the Payne residence?</p>\n", result)

      # Run filter (assigns with @)
      result = filter.run('%p= @question')
      assert_equal("<p>Is this the Payne residence?</p>\n", result)
    end
  end

  def test_filter_with_params
    if_have 'haml' do
      # Create filter
      filter = ::Nanoc3::Filters::Haml.new({ :foo => 'bar' })

      # Check with HTML5
      result = filter.run('%img', :format => :html5)
      assert_match(/<img>/, result)

      # Check with XHTML
      result = filter.run('%img', :format => :xhtml)
      assert_match(/<img\s*\/>/, result)
    end
  end

  def test_filter_error
    if_have 'haml' do
      # Create filter
      filter = ::Nanoc3::Filters::Haml.new({ :foo => 'bar' })

      # Run filter
      raised = false
      begin
        filter.run('%p= this isn\'t really ruby so it\'ll break, muahaha')
      rescue SyntaxError => e
        e.message =~ /(.+?):\d+: /
        assert_match '?', $1
        raised = true
      end
      assert raised
    end
  end

  def test_filter_with_yield
    if_have 'haml' do
      # Create filter
      filter = ::Nanoc3::Filters::Haml.new({ :content => 'Is this the Payne residence?' })

      # Run filter 
      result = filter.run('%p= yield')
      assert_equal("<p>Is this the Payne residence?</p>\n", result)
    end
  end

end<commit_msg>added ~ yield haml test<commit_after># encoding: utf-8

require 'test/helper'

class Nanoc3::Filters::HamlTest < MiniTest::Unit::TestCase

  include Nanoc3::TestHelpers

  def test_filter
    if_have 'haml' do
      # Create filter
      filter = ::Nanoc3::Filters::Haml.new({ :question => 'Is this the Payne residence?' })

      # Run filter (no assigns)
      result = filter.run('%html')
      assert_match(/<html>.*<\/html>/, result)

      # Run filter (assigns without @)
      result = filter.run('%p= question')
      assert_equal("<p>Is this the Payne residence?</p>\n", result)

      # Run filter (assigns with @)
      result = filter.run('%p= @question')
      assert_equal("<p>Is this the Payne residence?</p>\n", result)
    end
  end

  def test_filter_with_params
    if_have 'haml' do
      # Create filter
      filter = ::Nanoc3::Filters::Haml.new({ :foo => 'bar' })

      # Check with HTML5
      result = filter.run('%img', :format => :html5)
      assert_match(/<img>/, result)

      # Check with XHTML
      result = filter.run('%img', :format => :xhtml)
      assert_match(/<img\s*\/>/, result)
    end
  end

  def test_filter_error
    if_have 'haml' do
      # Create filter
      filter = ::Nanoc3::Filters::Haml.new({ :foo => 'bar' })

      # Run filter
      raised = false
      begin
        filter.run('%p= this isn\'t really ruby so it\'ll break, muahaha')
      rescue SyntaxError => e
        e.message =~ /(.+?):\d+: /
        assert_match '?', $1
        raised = true
      end
      assert raised
    end
  end

  def test_filter_with_yield
    if_have 'haml' do
      # Create filter
      filter = ::Nanoc3::Filters::Haml.new({ :content => 'Is this the Payne residence?' })

      # Run filter
      result = filter.run('%p= yield')
      assert_equal("<p>Is this the Payne residence?</p>\n", result)
    end
  end

  def test_filter_with_proper_indentation
    if_have 'haml' do
      # Create file to include
      File.open('stuff', 'w') do |io|
        io.write("<pre>Max Payne\nMona Sax</pre>")
      end

      # Run filter
      filter = ::Nanoc3::Filters::Haml.new
      result = filter.run("%body\n  ~ File.read('stuff')")
      assert_match(/Max Payne&#x000A;Mona Sax/, result)
    end
  end

end
{'fraction_non_alphanumeric': 0.14744525547445256, 'fraction_numerical': 0.00583941605839416, 'mean_word_length': 2.5196917808219177, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 39, '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': '3797041', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1349, 'n_words': 352}