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 50 51 52 53 54 55
|
require "rgfa.rb"
require "test/unit"
class TestRGFAFieldParser < Test::Unit::TestCase
def test_parse_gfa_opfield
o = "AA:i:1"
assert_equal([:AA,:i,"1"], o.parse_gfa_optfield)
assert_raise(RGFA::FieldParser::FormatError) do
"1A:A:A".parse_gfa_optfield
end
assert_raise(RGFA::FieldParser::FormatError) do
"_A:A:A".parse_gfa_optfield
end
assert_raise(RGFA::FieldParser::FormatError) do
"A:A:A".parse_gfa_optfield
end
assert_raise(RGFA::FieldParser::FormatError) do
"AAA:A:A".parse_gfa_optfield
end
assert_raise(RGFA::FieldParser::FormatError) {"AA:C:1".parse_gfa_optfield}
assert_raise(RGFA::FieldParser::FormatError) {"AA:AA:1".parse_gfa_optfield}
assert_raise(RGFA::FieldParser::FormatError) {"AA:a:1".parse_gfa_optfield}
end
def test_parse_gfa_field_A
assert_equal("1", "1".parse_gfa_field(datatype: :A))
end
def test_parse_gfa_field_i
assert_equal(12, "12".parse_gfa_field(datatype: :i))
end
def test_parse_gfa_field_f
assert_equal(1.2, "1.2".parse_gfa_field(datatype: :f))
end
def test_parse_gfa_field_Z
assert_equal("1.2", "1.2".parse_gfa_field(datatype: :Z))
end
def test_parse_gfa_field_H
assert_equal([26], "1A".parse_gfa_field(datatype: :H))
end
def test_parse_gfa_field_B
assert_equal([12,12,12], "c,12,12,12".parse_gfa_field(datatype: :B))
assert_equal([1.2,1.2,1.2], "f,1.2,1.2,1.2".parse_gfa_field(datatype: :B))
end
def test_parse_gfa_field_J
assert_equal({"1" => 2}, "{\"1\":2}".parse_gfa_field(datatype: :J))
end
end
|