+ def test_files_with_colons_in_names
+ manifest = Keep::Manifest.new(COLON_FILENAME_MANIFEST)
+ assert_equal([[".", "file:test.txt", 9]], manifest.files)
+ end
+
+ def test_files_with_escape_sequence_in_filename
+ manifest = Keep::Manifest.new(ESCAPED_FILENAME_MANIFEST)
+ assert_equal([[".", "a a.txt", 9]], manifest.files)
+ end
+
+ def test_files_spanning_multiple_blocks
+ manifest = Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST)
+ assert_equal([[".", "repfile", 5],
+ [".", "uniqfile", 4],
+ [".", "uniqfile2", 7],
+ ["./s1", "repfile", 3],
+ ["./s1", "uniqfile", 3]],
+ manifest.files.sort)
+ end
+
+ def test_minimum_file_count_simple
+ manifest = Keep::Manifest.new(SIMPLEST_MANIFEST)
+ assert(manifest.minimum_file_count?(1), "real minimum file count false")
+ refute(manifest.minimum_file_count?(2), "fake minimum file count true")
+ end
+
+ def test_minimum_file_count_multiblock
+ manifest = Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST)
+ assert(manifest.minimum_file_count?(2), "low minimum file count false")
+ assert(manifest.minimum_file_count?(5), "real minimum file count false")
+ refute(manifest.minimum_file_count?(6), "fake minimum file count true")
+ end
+
+ def test_exact_file_count_simple
+ manifest = Keep::Manifest.new(SIMPLEST_MANIFEST)
+ assert(manifest.exact_file_count?(1), "exact file count false")
+ refute(manifest.exact_file_count?(0), "-1 file count true")
+ refute(manifest.exact_file_count?(2), "+1 file count true")
+ end
+
+ def test_exact_file_count_multiblock
+ manifest = Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST)
+ assert(manifest.exact_file_count?(5), "exact file count false")
+ refute(manifest.exact_file_count?(4), "-1 file count true")
+ refute(manifest.exact_file_count?(6), "+1 file count true")
+ end
+
+ def test_files_size_multiblock
+ assert_equal(22, Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST).files_size)
+ end
+
+ def test_files_size_with_skipped_overlapping_data
+ manifest = Keep::Manifest.new(". #{random_block(9)} 3:3:f1 5:3:f2\n")
+ assert_equal(6, manifest.files_size)
+ end
+
+ def test_has_file
+ manifest = Keep::Manifest.new(MULTIBLOCK_FILE_MANIFEST)
+ assert(manifest.has_file?("./repfile"), "one-arg repfile not found")
+ assert(manifest.has_file?(".", "repfile"), "two-arg repfile not found")
+ assert(manifest.has_file?("./s1/repfile"), "one-arg s1/repfile not found")
+ assert(manifest.has_file?("./s1", "repfile"), "two-arg s1/repfile not found")
+ refute(manifest.has_file?("./s1/uniqfile2"), "one-arg missing file found")
+ refute(manifest.has_file?("./s1", "uniqfile2"), "two-arg missing file found")
+ refute(manifest.has_file?("./s2/repfile"), "one-arg missing stream found")
+ refute(manifest.has_file?("./s2", "repfile"), "two-arg missing stream found")
+ end
+
+ def test_has_file_with_spaces
+ manifest = Keep::Manifest.new(ESCAPED_FILENAME_MANIFEST)
+ assert(manifest.has_file?("./a a.txt"), "one-arg path not found")
+ assert(manifest.has_file?(".", "a a.txt"), "two-arg path not found")
+ refute(manifest.has_file?("a\\040\\141"), "one-arg unescaped found")
+ refute(manifest.has_file?(".", "a\\040\\141"), "two-arg unescaped found")
+ end
+
+ def test_parse_all_fixtures
+ fixtures('collections').each do |name, collection|
+ parse_collection_manifest name, collection
+ end
+ end
+
+ def test_raise_on_bogus_fixture
+ assert_raises ArgumentError do
+ parse_collection_manifest('bogus collection',
+ {'manifest_text' => ". zzz 0:\n"})
+ end
+ end
+
+ def parse_collection_manifest name, collection
+ manifest = Keep::Manifest.new(collection['manifest_text'])
+ manifest.each_file_spec do |stream_name, start_pos, file_size, file_name|
+ assert_kind_of String, stream_name
+ assert_kind_of Integer, start_pos
+ assert_kind_of Integer, file_size
+ assert_kind_of String, file_name
+ assert !stream_name.empty?, "empty stream_name in #{name} fixture"
+ assert !file_name.empty?, "empty file_name in #{name} fixture"
+ end