Sha256: 2941ddb96c503de801c0f70ea35aa98743d032d2e73cee77cc79e347802aa064

Contents?: true

Size: 1.34 KB

Versions: 18

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

describe 'GH-1171', site: true, stdio: true do
  before do
    File.write('nanoc.yaml', <<~EOS)
      data_sources:
        -
          type: filesystem
          encoding: utf-8
EOS
  end

  context 'UTF-8 code in ASCII env' do
    before do
      File.write('content/hi.md', '<%= ::EMOJI_🔥 %>', encoding: 'utf-8')
      File.write('lib/asdf.rb', 'EMOJI_🔥 = "hot"', encoding: 'utf-8')

      File.write('Rules', <<~EOS)
        compile '/**/*' do
          filter :erb
          write '/last.html'
        end
EOS
    end

    around do |ex|
      orig_encoding = Encoding.default_external
      Encoding.default_external = 'ASCII'
      ex.run
      Encoding.default_external = orig_encoding
    end

    it 'does not crash' do
      Nanoc::CLI.run(%w[compile])
      expect(File.read('output/last.html')).to eql('hot')
    end
  end

  context 'ISO 8859-1 code UTF-8 env' do
    before do
      File.write('content/hi.md', '<%= ::BRØKEN %>')
      File.write('lib/asdf.rb', "# encoding: iso-8859-1\n\nBRØKEN = 1", encoding: 'ISO-8859-1')

      File.write('Rules', <<~EOS)
        compile '/**/*' do
          filter :erb
          write '/last.html'
        end
EOS
    end

    it 'detects manually specified encodings' do
      Nanoc::CLI.run(%w[compile])
      expect(File.read('output/last.html')).to eql('1')
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
nanoc-4.8.12 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.11 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.10 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.9 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.8 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.7 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.6 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.5 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.4 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.3 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.2 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.1 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.8.0 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.7.14 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.7.13 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.7.12 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.7.11 spec/nanoc/regressions/gh_1171_spec.rb
nanoc-4.7.10 spec/nanoc/regressions/gh_1171_spec.rb