Skip to content

Commit

Permalink
Add tests for ansi_print
Browse files Browse the repository at this point in the history
  • Loading branch information
Mon-Ouie committed Sep 14, 2014
1 parent 19ccf50 commit 05fb186
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/coolline_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
require File.expand_path("helpers.rb", File.dirname(__FILE__))

context "a user uses colors for live code highlighting" do
Expand Down Expand Up @@ -28,3 +29,30 @@
asserts(:readline).equals "p 82"
asserts(:readline).nil
end

context "printing part of a string" do
setup {
$stdout = StringIO.new
extend Coolline::ANSI
}

context "with ASCII characters" do
hookup { ansi_print("Hello World", 2, 9) }
asserts { $stdout.string }.equals "llo Wor"
end

context "with non-ASCII characters" do
hookup { ansi_print("Hellô Wörld", 3, 7) }
asserts { $stdout.string }.equals "lô W"
end

context "with full-width characters" do
hookup { ansi_print("日本e本語語本語本語", 3, 9) }
asserts { $stdout.string }.equals "e本語"
end

context "with ANSI codes interleaved" do
hookup { ansi_print("\e[3mH\e[42mello W\e[41morld\e[0m", 2, 9) }
asserts { $stdout.string }.equals "\e[3m\e[42mllo W\e[41mor\e[0m"
end
end

0 comments on commit 05fb186

Please sign in to comment.