-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
637191b
commit b5695ae
Showing
4 changed files
with
160 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
require "../../../../spec_helper" | ||
require "../../../../support/tempfile" | ||
|
||
describe Crystal::Doc::ProjectInfo do | ||
it ".new_with_defaults" do | ||
with_tempfile("docs-defaults") do |tempdir| | ||
Dir.mkdir tempdir | ||
Dir.cd(tempdir) do | ||
# Empty dir | ||
Crystal::Doc::ProjectInfo.new_with_defaults(nil, nil) { |name, version| "missing:#{name}:#{version}" }.should eq "missing::" | ||
Crystal::Doc::ProjectInfo.new_with_defaults("foo", "1.0") { |name, version| "missing:#{name}:#{version}" }.should eq Crystal::Doc::ProjectInfo.new("foo", "1.0") | ||
|
||
# shard.yml | ||
File.write("shard.yml", "name: foo\nversion: 1.0") | ||
Crystal::Doc::ProjectInfo.new_with_defaults(nil, nil) { |name, version| "missing:#{name}:#{version}" }.should eq Crystal::Doc::ProjectInfo.new("foo", "1.0") | ||
Crystal::Doc::ProjectInfo.new_with_defaults("bar", "2.0") { |name, version| "missing:#{name}:#{version}" }.should eq Crystal::Doc::ProjectInfo.new("bar", "2.0") | ||
Crystal::Doc::ProjectInfo.new_with_defaults(nil, "2.0") { |name, version| "missing:#{name}:#{version}" }.should eq Crystal::Doc::ProjectInfo.new("foo", "2.0") | ||
|
||
# git tagged version | ||
`git init` | ||
`git add shard.yml` | ||
`git commit -m 'Initial commit' --no-gpg-sign` | ||
`git tag v3.0` | ||
Crystal::Doc::ProjectInfo.new_with_defaults(nil, nil) { |name, version| "missing:#{name}:#{version}" }.should eq Crystal::Doc::ProjectInfo.new("foo", "3.0") | ||
Crystal::Doc::ProjectInfo.new_with_defaults("bar", "2.0") { |name, version| "missing:#{name}:#{version}" }.should eq Crystal::Doc::ProjectInfo.new("bar", "2.0") | ||
|
||
# git dirty dir | ||
File.write("foo.txt", "bar") | ||
Crystal::Doc::ProjectInfo.new_with_defaults(nil, nil) { |name, version| "missing:#{name}:#{version}" }.should eq Crystal::Doc::ProjectInfo.new("foo", "1.0") | ||
Crystal::Doc::ProjectInfo.new_with_defaults(nil, "1.1") { |name, version| "missing:#{name}:#{version}" }.should eq Crystal::Doc::ProjectInfo.new("foo", "1.1") | ||
Crystal::Doc::ProjectInfo.new_with_defaults("bar", "2.0") { |name, version| "missing:#{name}:#{version}" }.should eq Crystal::Doc::ProjectInfo.new("bar", "2.0") | ||
File.delete("foo.txt") | ||
|
||
# No shard.yml, but git version | ||
`git rm shard.yml` | ||
`git commit -m 'Remove shard.yml' --no-gpg-sign` | ||
`git tag v4.0` | ||
Crystal::Doc::ProjectInfo.new_with_defaults(nil, nil) { |name, version| "missing:#{name}:#{version}" }.should eq "missing::4.0" | ||
Crystal::Doc::ProjectInfo.new_with_defaults("foo", nil) { |name, version| "missing:#{name}:#{version}" }.should eq Crystal::Doc::ProjectInfo.new("foo", "4.0") | ||
Crystal::Doc::ProjectInfo.new_with_defaults("bar", "2.0") { |name, version| "missing:#{name}:#{version}" }.should eq Crystal::Doc::ProjectInfo.new("bar", "2.0") | ||
end | ||
end | ||
end | ||
|
||
it ".find_git_version" do | ||
with_tempfile("docs-git-version") do |tempdir| | ||
Dir.mkdir tempdir | ||
Dir.cd(tempdir) do | ||
# Non-git directory | ||
Crystal::Doc::ProjectInfo.find_git_version.should be_nil | ||
|
||
`git init` | ||
Crystal::Doc::ProjectInfo.find_git_version.should be_nil | ||
|
||
File.write("file.txt", "foo") | ||
`git add file.txt` | ||
`git commit -m 'Initial commit' --no-gpg-sign` | ||
Crystal::Doc::ProjectInfo.find_git_version.should be_nil | ||
|
||
`git tag v0.1.0` | ||
Crystal::Doc::ProjectInfo.find_git_version.should eq "0.1.0" | ||
|
||
File.write("file.txt", "bar") | ||
Crystal::Doc::ProjectInfo.find_git_version.should be_nil | ||
|
||
`git add file.txt` | ||
Crystal::Doc::ProjectInfo.find_git_version.should be_nil | ||
|
||
`git reset --hard v0.1.0` | ||
Crystal::Doc::ProjectInfo.find_git_version.should eq "0.1.0" | ||
|
||
`git tag v0.2.0` | ||
Crystal::Doc::ProjectInfo.find_git_version.should be_nil | ||
end | ||
end | ||
end | ||
|
||
it ".read_shard_properties" do | ||
with_tempfile("docs-shard.yml") do |tempdir| | ||
Dir.mkdir tempdir | ||
Dir.cd(tempdir) do | ||
Crystal::Doc::ProjectInfo.read_shard_properties.should eq({nil, nil}) | ||
|
||
File.write("shard.yml", "foo: bar\n") | ||
Crystal::Doc::ProjectInfo.read_shard_properties.should eq({nil, nil}) | ||
|
||
File.write("shard.yml", "name: \nversion: ") | ||
Crystal::Doc::ProjectInfo.read_shard_properties.should eq({nil, nil}) | ||
|
||
File.write("shard.yml", " name: bar\n version: 1.0") | ||
Crystal::Doc::ProjectInfo.read_shard_properties.should eq({nil, nil}) | ||
|
||
File.write("shard.yml", "name: bar\n") | ||
Crystal::Doc::ProjectInfo.read_shard_properties.should eq({"bar", nil}) | ||
|
||
File.write("shard.yml", "name: bar\nversion: 1.0") | ||
Crystal::Doc::ProjectInfo.read_shard_properties.should eq({"bar", "1.0"}) | ||
|
||
File.write("shard.yml", "name: bar\nversion: 1.0\nname: foo\nversion: foo") | ||
Crystal::Doc::ProjectInfo.read_shard_properties.should eq({"bar", "1.0"}) | ||
|
||
File.write("shard.yml", "name: bar \nversion: 1.0 ") | ||
Crystal::Doc::ProjectInfo.read_shard_properties.should eq({"bar", "1.0"}) | ||
|
||
File.write("shard.yml", "name: 'bar'\nversion: '1.0'") | ||
Crystal::Doc::ProjectInfo.read_shard_properties.should eq({"bar", "1.0"}) | ||
|
||
File.write("shard.yml", "name: bar # comment\nversion: 1.0 # comment") | ||
Crystal::Doc::ProjectInfo.read_shard_properties.should eq({"bar", "1.0"}) | ||
|
||
File.write("shard.yml", "name: # comment\nversion: # comment") | ||
Crystal::Doc::ProjectInfo.read_shard_properties.should eq({nil, nil}) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters