summaryrefslogtreecommitdiff
path: root/spec/tooling/lib/tooling/test_map_packer_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/tooling/lib/tooling/test_map_packer_spec.rb')
-rw-r--r--spec/tooling/lib/tooling/test_map_packer_spec.rb77
1 files changed, 77 insertions, 0 deletions
diff --git a/spec/tooling/lib/tooling/test_map_packer_spec.rb b/spec/tooling/lib/tooling/test_map_packer_spec.rb
new file mode 100644
index 00000000000..233134d2524
--- /dev/null
+++ b/spec/tooling/lib/tooling/test_map_packer_spec.rb
@@ -0,0 +1,77 @@
+# frozen_string_literal: true
+
+require_relative '../../../../tooling/lib/tooling/test_map_packer'
+
+RSpec.describe Tooling::TestMapPacker do
+ subject { described_class.new }
+
+ let(:map) do
+ {
+ 'file1.rb' => [
+ './a/b/c/test_1.rb',
+ './a/b/test_2.rb',
+ './a/b/test_3.rb',
+ './a/test_4.rb',
+ './test_5.rb'
+ ],
+ 'file2.rb' => [
+ './a/b/c/test_1.rb',
+ './a/test_4.rb',
+ './test_5.rb'
+ ]
+ }
+ end
+
+ let(:compact_map) do
+ {
+ 'file1.rb' => {
+ '.' => {
+ 'a' => {
+ 'b' => {
+ 'c' => {
+ 'test_1.rb' => 1
+ },
+ 'test_2.rb' => 1,
+ 'test_3.rb' => 1
+ },
+ 'test_4.rb' => 1
+ },
+ 'test_5.rb' => 1
+ }
+ },
+ 'file2.rb' => {
+ '.' => {
+ 'a' => {
+ 'b' => {
+ 'c' => {
+ 'test_1.rb' => 1
+ }
+ },
+ 'test_4.rb' => 1
+ },
+ 'test_5.rb' => 1
+ }
+ }
+ }
+ end
+
+ describe '#pack' do
+ it 'compacts list of test files into a prefix tree' do
+ expect(subject.pack(map)).to eq(compact_map)
+ end
+
+ it 'does nothing to empty hash' do
+ expect(subject.pack({})).to eq({})
+ end
+ end
+
+ describe '#unpack' do
+ it 'unpack prefix tree into list of test files' do
+ expect(subject.unpack(compact_map)).to eq(map)
+ end
+
+ it 'does nothing to empty hash' do
+ expect(subject.unpack({})).to eq({})
+ end
+ end
+end