Skip to content

Commit ef31a1d

Browse files
authored
Merge pull request #438 from nodeg/fix_poly
2 parents fd75a9b + 583e51b commit ef31a1d

5 files changed

Lines changed: 50 additions & 33 deletions

File tree

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
To develop tetra, you will need:
66

77
* to install Bundler and Ruby development headers. On SUSE distros, use
8-
`sudo zypper install ruby3.1-rubygem-bundler ruby-devel`;
8+
`sudo zypper install ruby3.4-rubygem-bundler ruby3.4-devel`;
99
* to get development dependencies: `bundle install`;
1010

1111
To install a development version of tetra use:
@@ -14,8 +14,8 @@ To install a development version of tetra use:
1414
sudo rake install
1515
```
1616

17-
To run tests, simply run `rake`. Please note that tests are divided into fine (more similar to unit tests) and coarse
18-
(more similar to integration tests).
17+
To run tests, simply run `rake` or `bundle exec rake`. Please note that tests are divided into fine
18+
(more similar to unit tests) and coarse (more similar to integration tests).
1919

2020
## Coding style
2121

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ rake install
3636

3737
Test can be found in the `spec/` folder and are divided into fine (more similar to unit tests) and coarse
3838
(more similar to integration tests).
39-
To run tests manually, simply execute `rake`.
39+
To run tests manually, simply execute `rake` or `bundle exec rake`.
4040
With every Pull Request against master and consecutive pushes to that PR, several [GitHub Actions tests](https://github.com/uyuni-project/tetra/tree/master/.github/workflows)
4141
will run automatically.
4242

lib/tetra/packages/package.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ def outputs
4949
end
5050

5151
def cleanup_description(raw, max_length)
52+
# Normalize spaces and strip and truncate to max_length
53+
raw = raw.gsub(/[\s]+/, " ").strip
54+
raw = raw.slice(0..max_length - 1)
55+
56+
# Remove the last word if it was cut off (preceded by a space)
57+
raw = raw.sub(/\s\w+\z/, "")
58+
59+
# Safely remove trailing dots linear in O(N)
60+
raw = raw[0...-1] while raw.end_with?(".")
61+
5262
raw
53-
.gsub(/[\s]+/, " ")
54-
.strip
55-
.slice(0..max_length - 1)
56-
.sub(/\s\w+$/, "")
57-
.sub(/\.+$/, "")
5863
end
5964

6065
def to_spec

lib/tetra/version_matcher.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class VersionMatcher
1010
# by a ., -, _, ~ or space
1111
# returns a [name, version] pair
1212
def split_version(full_name)
13-
matches = full_name.match(/(.*?)(?:[\.\-\_ ~,]?([0-9].*))?$/)
13+
matches = full_name.match(/\A(.*?)(?:[\.\-\_ ~,]?([0-9].*))\z/)
1414
if !matches.nil? && matches.length > 1
1515
[matches[1], matches[2]]
1616
else
17-
[full_string, nil]
17+
[full_name, nil]
1818
end
1919
end
2020

spec/lib/fine/version_matcher_spec.rb

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,74 @@
33
require "spec_helper"
44

55
describe Tetra::VersionMatcher do
6-
let(:version_matcher) { Tetra::VersionMatcher.new }
6+
let(:v_matcher) { Tetra::VersionMatcher.new }
77

88
describe "#split_version" do
99
it "splits full names into names and version numbers" do
10-
expect(version_matcher.split_version("moio-3.2beta1")).to eq(["moio", "3.2beta1"])
11-
expect(version_matcher.split_version("3.2beta1")).to eq(["", "3.2beta1"])
12-
expect(version_matcher.split_version("v3.2beta1")).to eq(["v", "3.2beta1"])
10+
expect(v_matcher.split_version("moio-3.2beta1")).to eq(["moio", "3.2beta1"])
11+
expect(v_matcher.split_version("3.2beta1")).to eq(["", "3.2beta1"])
12+
expect(v_matcher.split_version("v3.2beta1")).to eq(["v", "3.2beta1"])
13+
end
14+
15+
it "returns the full name and nil version when no version is found" do
16+
# This triggers the 'else' block where the variable name bug was
17+
expect(v_matcher.split_version("simple-package-name")).to eq(["simple-package-name", nil])
18+
expect(v_matcher.split_version("mypackage")).to eq(["mypackage", nil])
19+
end
20+
21+
it "handles version strings with different separators" do
22+
expect(v_matcher.split_version("package_name-1.0")).to eq(["package_name", "1.0"])
23+
expect(v_matcher.split_version("package.name.1.0")).to eq(["package.name", "1.0"])
24+
expect(v_matcher.split_version("package name 1.0")).to eq(["package name", "1.0"])
1325
end
1426
end
1527

1628
describe "#chunk_distance" do
1729
it "computes chunk distances" do
18-
expect(version_matcher.chunk_distance(nil, "1")).to eq(1)
19-
expect(version_matcher.chunk_distance("alpha", nil)).to eq(5)
30+
expect(v_matcher.chunk_distance(nil, "1")).to eq(1)
31+
expect(v_matcher.chunk_distance("alpha", nil)).to eq(5)
2032

21-
expect(version_matcher.chunk_distance("1", "1")).to eq(0)
22-
expect(version_matcher.chunk_distance("1", "9")).to eq(8)
23-
expect(version_matcher.chunk_distance("1", "999")).to eq(99)
33+
expect(v_matcher.chunk_distance("1", "1")).to eq(0)
34+
expect(v_matcher.chunk_distance("1", "9")).to eq(8)
35+
expect(v_matcher.chunk_distance("1", "999")).to eq(99)
2436

25-
expect(version_matcher.chunk_distance("snap", "SNAP")).to eq(0)
26-
expect(version_matcher.chunk_distance("snap", "snippete")).to eq(5)
27-
expect(version_matcher.chunk_distance("snap", "l" * 999)).to eq(99)
37+
expect(v_matcher.chunk_distance("snap", "SNAP")).to eq(0)
38+
expect(v_matcher.chunk_distance("snap", "snippete")).to eq(5)
39+
expect(v_matcher.chunk_distance("snap", "l" * 999)).to eq(99)
2840

29-
expect(version_matcher.chunk_distance("1", "SNAP")).to eq(4)
41+
expect(v_matcher.chunk_distance("1", "SNAP")).to eq(4)
3042

31-
expect(version_matcher.chunk_distance("0", "10")).to eq(10)
32-
expect(version_matcher.chunk_distance("0", "9")).to eq(9)
43+
expect(v_matcher.chunk_distance("0", "10")).to eq(10)
44+
expect(v_matcher.chunk_distance("0", "9")).to eq(9)
3345
end
3446
end
3547

3648
describe "#best_match" do
3749
it "finds the best match" do
3850
my_version = "1.0"
3951
available_versions = ["1.0", "1", "2.0", "1.0.1", "4.5.6.7.8"]
40-
expect(version_matcher.best_match(my_version, available_versions)).to eq("1.0")
52+
expect(v_matcher.best_match(my_version, available_versions)).to eq("1.0")
4153

4254
available_versions = ["3.0", "2.0", "1.0.1"]
43-
expect(version_matcher.best_match(my_version, available_versions)).to eq("1.0.1")
55+
expect(v_matcher.best_match(my_version, available_versions)).to eq("1.0.1")
4456

4557
available_versions = ["1.snap", "2.0", "4.0.1"]
46-
expect(version_matcher.best_match(my_version, available_versions)).to eq("1.snap")
58+
expect(v_matcher.best_match(my_version, available_versions)).to eq("1.snap")
4759

4860
available_versions = ["1.10", "1.9", "2.0", "3.0.1"]
49-
expect(version_matcher.best_match(my_version, available_versions)).to eq("1.9")
61+
expect(v_matcher.best_match(my_version, available_versions)).to eq("1.9")
5062

5163
my_version = "1.snap"
5264
available_versions = ["1.snap", "1"]
53-
expect(version_matcher.best_match(my_version, available_versions)).to eq("1.snap")
65+
expect(v_matcher.best_match(my_version, available_versions)).to eq("1.snap")
5466

5567
my_version = "1.very-very_very_longish"
5668
available_versions = ["1.snap", "1"]
57-
expect(version_matcher.best_match(my_version, available_versions)).to eq("1.snap")
69+
expect(v_matcher.best_match(my_version, available_versions)).to eq("1.snap")
5870

5971
my_version = "1.snap"
6072
available_versions = []
61-
expect(version_matcher.best_match(my_version, available_versions)).to be_nil
73+
expect(v_matcher.best_match(my_version, available_versions)).to be_nil
6274
end
6375
end
6476
end

0 commit comments

Comments
 (0)