diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-04-05 22:08:41 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-04-05 22:40:51 +0000 |
commit | c5fab448d4260594a876a2d29339156e45bfd379 (patch) | |
tree | c3cfa6069cddf2535ad1fe92cdf3a0f611e13351 /test.rb | |
parent | 7f87cbc2e5289f328c3278a991519068d8747374 (diff) | |
download | mahoro-c5fab448d4260594a876a2d29339156e45bfd379.tar.gz |
tree reorganization + various maint fixes v0.4
Using an ext/ directory is easier to grok for RubyGems
Diffstat (limited to 'test.rb')
-rwxr-xr-x | test.rb | 104 |
1 files changed, 0 insertions, 104 deletions
diff --git a/test.rb b/test.rb deleted file mode 100755 index 5c2c23d..0000000 --- a/test.rb +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env ruby - -require 'test/unit' -require 'mahoro' -require 'mahoro/thread_safe' -require 'pathname' - -class MahoroTestCase < Test::Unit::TestCase - - def setup - @m = Mahoro.new - end - - # Different versions of libmagic may generate different values. - # So far, we have seen: - # - ASCII C program text - # - C source, ASCII text - def assert_c_text(buf) - assert_match(/\bC\b/, buf, "contains the letter C") - assert_match(/\s/, buf, "contains spaces") - assert_match(/(?:source|text)/, buf, "is source or text") - end - - def test_pathname - @m.flags = Mahoro::NONE - pn = Pathname.new('mahoro.c') - assert_c_text(@m.file(pn)) - end - - def test_file - @m.flags = Mahoro::NONE - assert_c_text(@m.file('mahoro.c')) - end - - def test_mime_file - @m.flags = Mahoro::MIME - assert({ - 'text/x-c; charset=us-ascii' => true, - 'text/x-c charset=us-ascii' => true - }.include?(@m.file('mahoro.c'))) - end - - def test_null_byte_in_path - assert_raises(ArgumentError) { @m.file("mahoro.c\0foo") } - end - - def test_buffer - @m.flags = Mahoro::NONE - assert_c_text(@m.buffer(File.read('mahoro.c'))) - end - - def test_buffer_string_convert - tmp = File.read('mahoro.c') - buf = Struct.new(:to_str).new(tmp) - assert_c_text(@m.buffer(buf)) - end - - def test_buffer_invalid - @m.flags = Mahoro::NONE - assert_raises(TypeError) { @m.buffer @m } - end - - def test_mime_buffer - @m.flags = Mahoro::MIME - assert({ - 'text/x-c; charset=us-ascii' => true, - 'text/x-c charset=us-ascii' => true - }.include?(@m.buffer(File.read('mahoro.c')))) - end - - def test_valid - assert(@m.valid?, 'Default database was not valid.') - end - - def test_valid_with_null - assert_raises(ArgumentError) { @m.valid? "mahoro.c\0" } - end - - def test_compile - File.open(__FILE__) do |fp| - fp.flock File::LOCK_EX - assert Mahoro.compile("magic.sample") - assert_nothing_raised do - File.unlink("magic.sample.mgc") - end - end - end - - def test_compile_bad - assert_raises(ArgumentError) do - Mahoro.compile "magic.sample\0" - end - end - - def test_thread_safe - before = @m.method(:file) - @m.extend(Mahoro::ThreadSafe) - @m.flags = Mahoro::NONE - assert_c_text(@m.file('mahoro.c')) - assert_not_equal(before.object_id, @m.method(:file).object_id) - end -end - -# arch-tag: test |