File: case_bbcode.rb

package info (click to toggle)
ruby-ansi 1.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 404 kB
  • sloc: ruby: 1,880; makefile: 5
file content (49 lines) | stat: -rw-r--r-- 1,515 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'test_helper'
require 'ansi/bbcode'

testcase ANSI::BBCode do

  class_method :bbcode_to_ansi do
    test do
      str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
      out = "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
      out.assert == ANSI::BBCode.bbcode_to_ansi(str)
    end
  end

  class_method :bbcode_to_html do
    test do
      str = "this is [COLOR=red]red[/COLOR], this is [B]bold[/B]"
      out = "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n"
      out.assert == ANSI::BBCode.bbcode_to_html(str)
    end
  end

  class_method :ansi_to_bbcode do
    test "example from RSpec" do
      str = "\e[32m.\e[0m\e[32m.\e[0m"
      expected = "[COLOR=green].[/COLOR][COLOR=green].[/COLOR]\n"
      out = ANSI::BBCode.ansi_to_bbcode(str)
      out.assert == expected
    end

    test "just the reset code" do
      out = ANSI::BBCode.ansi_to_bbcode("\e[0m")
      out.assert == "\n"
    end
  end

  class_method :ansi_to_html do
    test do
      str = "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n" +
            "this is a line without any ansi code\n" +
            "this is \e[0;31mred\e[0m, this is \e[1mbold\e[0m\n"
      out = "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n" +
            "this is a line without any ansi code<br />\n" +
            "this is <font color=\"red\">red</font>, this is <strong>bold</strong><br />\n"
      out.assert == ANSI::BBCode.ansi_to_html(str)
    end
  end

end