Sha256: 02548d6d66c2e0edf71661c527523529d00328c23defc7a14bf54839b33af4f4
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
#!/usr/bin/env ruby require 'test/unit' require 'mahoro' class MahoroTestCase < Test::Unit::TestCase def setup @m = Mahoro.new end def test_file @m.flags = Mahoro::NONE assert_equal('ASCII C program 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_equal('ASCII C program 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_equal('ASCII C program 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 end # arch-tag: test
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mahoro-0.3 | test.rb |