File: codepoint_test_helper.rb

package info (click to toggle)
ruby-stringex 2.8.5-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,232 kB
  • sloc: ruby: 3,745; makefile: 5
file content (32 lines) | stat: -rw-r--r-- 992 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# encoding: UTF-8

# 100% shorthand
module CodepointTestHelper
  def assert_equal_encoded(expected, encode_mes)
    # Killing a duck because Ruby 1.9 doesn't mix Enumerable into String
    encode_mes = [encode_mes] if encode_mes.is_a?(String)
    encode_mes.each do |encode_me|
      encoded = encode(encode_me)
      actual = encoded.to_ascii
      if expected == actual
        # Let's not retest it
        assert true
      else
        message = "<#{expected.inspect}> expected but was\n<#{actual.inspect}>\n"
        message << "  defined in #{Stringex::Unidecoder.in_yaml_file(encoded)}"
        reporting_class = defined?(Test::Unit::AssertionFailedError) ?
           Test::Unit::AssertionFailedError : ActiveSupport::TestCase::Assertion
        raise reporting_class.new(message)
      end
    end
  end

private
  def encode(codepoint)
    Stringex::Unidecoder.encode(codepoint)
  end

  def which_yaml(codepoint)
    Stringex::Unidecoder.in_yaml_file(encode(codepoint))
  end
end