Sha256: 9f54e0cd85e9d4e907b1c9e036b7a8d827cf57593dbd9ba78986c3f54601e878

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require "test_helper"

# Pull the EmojiHelper example from the docs
readme = File.expand_path("../README.md", __dir__)
docs = File.open(readme, "r:UTF-8", &:read)
eval docs.match(%r{^module.+?^end}m)[0]

String.class_eval do
  def html_safe
    self
  end

  def present?
    !empty?
  end
end

class DocumentationTest < TestCase
  module Helper
    extend EmojiHelper

    def self.h(str)
      str.gsub("<", "&lt;").gsub(">", "&gt;")
    end

    def self.image_path(img)
      "/images/#{img}?123"
    end
  end

  test "replaces emoji syntax with images" do
    assert_equal "It's raining " \
        '<img alt="cat" src="/images/emoji/1f431.svg?123" style="vertical-align:middle" width="20" height="20" />s and ' \
        '<img alt="dog" src="/images/emoji/1f436.svg?123" style="vertical-align:middle" width="20" height="20" />s!',
                 Helper.emojify("It's raining :cat:s and :dog:s!")
  end

  test "doesn't replace unknown emoji" do
    content = ":jupiter: is in :space:"
    assert_equal content, Helper.emojify(content)
  end

  test "escapes other HTML" do
    assert_equal "You have been &lt;script&gt;alert('pwned!')&lt;/script&gt;",
                 Helper.emojify("You have been <script>alert('pwned!')</script>")
  end

  test "returns nil for blank content" do
    assert_nil Helper.emojify("")
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
negarmoji-0.1.10 test/documentation_test.rb
negarmoji-0.1.9 test/documentation_test.rb
negarmoji-0.1.8 test/documentation_test.rb
negarmoji-0.1.6 test/documentation_test.rb
negarmoji-0.1.5 test/documentation_test.rb
negarmoji-0.1.4 test/documentation_test.rb
negarmoji-0.1.3 test/documentation_test.rb