social_snippet 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +2 -0
- data/.travis.yml +22 -3
- data/Gemfile +25 -2
- data/Guardfile +9 -0
- data/README.md +6 -1
- data/Rakefile +51 -1
- data/appveyor.yml +36 -0
- data/bin/ssnip +10 -0
- data/bin/sspm +10 -0
- data/lib/social_snippet.rb +15 -4
- data/lib/social_snippet/api.rb +238 -0
- data/lib/social_snippet/command_line.rb +4 -0
- data/lib/social_snippet/command_line/command.rb +158 -0
- data/lib/social_snippet/command_line/ssnip.rb +2 -0
- data/lib/social_snippet/command_line/ssnip/main_command.rb +26 -0
- data/lib/social_snippet/command_line/sspm.rb +3 -0
- data/lib/social_snippet/command_line/sspm/main_command.rb +63 -0
- data/lib/social_snippet/command_line/sspm/sub_commands.rb +16 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/complete_command.rb +28 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/info_command.rb +28 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/install_command.rb +103 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/publish_command.rb +51 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/search_command.rb +32 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/update_command.rb +37 -0
- data/lib/social_snippet/config.rb +92 -0
- data/lib/social_snippet/context.rb +89 -0
- data/lib/social_snippet/core.rb +40 -0
- data/lib/social_snippet/inserter.rb +64 -0
- data/lib/social_snippet/logger.rb +9 -0
- data/lib/social_snippet/registry.rb +3 -0
- data/lib/social_snippet/registry/registry_client.rb +15 -0
- data/lib/social_snippet/registry/registry_resources.rb +3 -0
- data/lib/social_snippet/registry/registry_resources/base.rb +80 -0
- data/lib/social_snippet/registry/registry_resources/repositories.rb +23 -0
- data/lib/social_snippet/repository.rb +6 -0
- data/lib/social_snippet/repository/drivers.rb +3 -0
- data/lib/social_snippet/repository/drivers/base_repository.rb +192 -0
- data/lib/social_snippet/repository/drivers/git_repository.rb +76 -0
- data/lib/social_snippet/repository/repository_errors.rb +5 -0
- data/lib/social_snippet/repository/repository_factory.rb +59 -0
- data/lib/social_snippet/repository/repository_installer.rb +86 -0
- data/lib/social_snippet/repository/repository_manager.rb +177 -0
- data/lib/social_snippet/resolvers.rb +4 -0
- data/lib/social_snippet/resolvers/base_resolver.rb +103 -0
- data/lib/social_snippet/resolvers/dep_resolver.rb +61 -0
- data/lib/social_snippet/resolvers/insert_resolver.rb +100 -0
- data/lib/social_snippet/snippet.rb +14 -0
- data/lib/social_snippet/tag.rb +198 -0
- data/lib/social_snippet/tag_parser.rb +61 -0
- data/lib/social_snippet/version.rb +26 -1
- data/social_snippet.gemspec +18 -3
- data/spec/helpers/codeclimate_helper.rb +4 -0
- data/spec/helpers/fakefs_helper.rb +15 -0
- data/spec/helpers/webmock_helper.rb +16 -0
- data/spec/lib/api_spec.rb +106 -0
- data/spec/lib/command_line/sspm_install_spec.rb +224 -0
- data/spec/lib/command_line/sspm_search_spec.rb +167 -0
- data/spec/lib/command_line/sspm_spec.rb +81 -0
- data/spec/lib/config_spec.rb +56 -0
- data/spec/lib/context_spec.rb +48 -0
- data/spec/lib/core_spec.rb +126 -0
- data/spec/lib/inserter_spec.rb +177 -0
- data/spec/lib/registry_client_spec.rb +173 -0
- data/spec/lib/repository/base_repository_spec.rb +104 -0
- data/spec/lib/repository/git_repository_spec.rb +83 -0
- data/spec/lib/repository/repository_factory_spec.rb +31 -0
- data/spec/lib/repository/repository_installer_spec.rb +63 -0
- data/spec/lib/repository/repository_manager_spec.rb +201 -0
- data/spec/lib/tag_parser_spec.rb +173 -0
- data/spec/lib/tag_spec.rb +93 -0
- data/spec/spec_helper.rb +106 -0
- data/test/base_repository_test.rb +375 -0
- data/test/command_test.rb +39 -0
- data/test/context_test.rb +31 -0
- data/test/core_test.rb +2091 -0
- data/test/git_repository_test.rb +114 -0
- data/test/install_command_test.rb +28 -0
- data/test/repository_manager_test.rb +109 -0
- data/test/tag_parser_test.rb +47 -0
- data/test/tag_test.rb +217 -0
- data/test/version_test.rb +56 -0
- metadata +271 -14
@@ -0,0 +1,114 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module ::SocialSnippet::Repository
|
4
|
+
|
5
|
+
describe Drivers::GitRepository do
|
6
|
+
|
7
|
+
class FakeClass; end
|
8
|
+
|
9
|
+
def create_fake_instance
|
10
|
+
FakeClass.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_branch(name)
|
14
|
+
branch = create_fake_instance
|
15
|
+
allow(branch).to receive(:name).and_return "refs/remotes/origin/#{name}"
|
16
|
+
branch
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_tag(name)
|
20
|
+
branch = create_fake_instance
|
21
|
+
allow(branch).to receive(:name).and_return "refs/tags/#{name}"
|
22
|
+
branch
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
class FakeDriver < Drivers::GitRepository; end
|
27
|
+
allow(Rugged::Repository).to receive(:new) do
|
28
|
+
rugged_repo = create_fake_instance
|
29
|
+
|
30
|
+
allow(rugged_repo).to receive(:references).and_return [
|
31
|
+
create_branch("master"),
|
32
|
+
create_branch("develop"),
|
33
|
+
create_tag("0.0.1"),
|
34
|
+
create_tag("0.0.2"),
|
35
|
+
]
|
36
|
+
rugged_repo
|
37
|
+
end
|
38
|
+
@repo = FakeDriver.new("/path/to/repo")
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#refs" do
|
42
|
+
it { expect(@repo.refs.length).to eq 4 }
|
43
|
+
it { expect(@repo.refs).to include "master" }
|
44
|
+
it { expect(@repo.refs).to include "develop" }
|
45
|
+
it { expect(@repo.refs).to include "0.0.1" }
|
46
|
+
it { expect(@repo.refs).to include "0.0.2" }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#remote_refs" do
|
50
|
+
it { expect(@repo.remote_refs.length).to eq 2 }
|
51
|
+
it { expect(@repo.remote_refs).to include "master" }
|
52
|
+
it { expect(@repo.remote_refs).to include "develop" }
|
53
|
+
it { expect(@repo.remote_refs).to_not include "0.0.1" }
|
54
|
+
it { expect(@repo.remote_refs).to_not include "0.0.2" }
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe Drivers::GitRepository, :without_fakefs => true do
|
60
|
+
|
61
|
+
before do
|
62
|
+
disable_fakefs
|
63
|
+
make_fake_home
|
64
|
+
end
|
65
|
+
|
66
|
+
before do
|
67
|
+
@curdir = Dir.pwd
|
68
|
+
@tmpdir = Dir.mktmpdir
|
69
|
+
Dir.chdir @tmpdir
|
70
|
+
end
|
71
|
+
|
72
|
+
after do
|
73
|
+
Dir.chdir @curdir
|
74
|
+
FileUtils.rm_r @tmpdir
|
75
|
+
end
|
76
|
+
|
77
|
+
context "clone example-repo" do
|
78
|
+
before do
|
79
|
+
@cloned_repo = RepositoryFactory.clone "git://github.com/social-snippet/example-repo"
|
80
|
+
end
|
81
|
+
|
82
|
+
context "checkout 1.0.0" do
|
83
|
+
before do
|
84
|
+
@cloned_repo.checkout "1.0.0"
|
85
|
+
end
|
86
|
+
|
87
|
+
context "load snippet json" do
|
88
|
+
before do
|
89
|
+
@cloned_repo.load_snippet_json
|
90
|
+
end
|
91
|
+
|
92
|
+
context "create cache" do
|
93
|
+
|
94
|
+
before do
|
95
|
+
@cloned_repo.create_cache("./cache")
|
96
|
+
end
|
97
|
+
|
98
|
+
it do
|
99
|
+
expect(@cloned_repo.commit_id).to eq "efa58ecae07cf3d063ae75fa97fce164c56d205a"
|
100
|
+
end
|
101
|
+
|
102
|
+
it do
|
103
|
+
expect(File.exists?("#{@cloned_repo.cache_path}")).to be_truthy
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end # clone example-repo
|
111
|
+
|
112
|
+
end # Drivers::GitRepository
|
113
|
+
|
114
|
+
end # ::SocialSnippet::Repository
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module ::SocialSnippet::CommandLine
|
4
|
+
|
5
|
+
describe SSpm::SubCommands::InstallCommand do
|
6
|
+
|
7
|
+
describe "has_ref?()" do
|
8
|
+
|
9
|
+
let(:update_command) { SSpm::SubCommands::InstallCommand.new [] }
|
10
|
+
|
11
|
+
describe "with ref" do
|
12
|
+
it { expect(update_command.send :has_ref?, "hello#1.2.3").to be_truthy }
|
13
|
+
it { expect(update_command.send :has_ref?, "example_repo#master").to be_truthy }
|
14
|
+
it { expect(update_command.send :has_ref?, "example-repo#develop").to be_truthy }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "without ref" do
|
18
|
+
it { expect(update_command.send :has_ref?, "hello").to be_falsey }
|
19
|
+
it { expect(update_command.send :has_ref?, "example_repo").to be_falsey }
|
20
|
+
it { expect(update_command.send :has_ref?, "example-repo").to be_falsey }
|
21
|
+
end
|
22
|
+
|
23
|
+
end # has_ref?
|
24
|
+
|
25
|
+
end # SSpm::SubCommands::UpdateCommand
|
26
|
+
|
27
|
+
end # ::SocialSnippet::CommandLine
|
28
|
+
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ::SocialSnippet::Repository::RepositoryManager do
|
4
|
+
|
5
|
+
let(:logger) do
|
6
|
+
logger = ::SocialSnippet::Logger.new(STDOUT)
|
7
|
+
logger.level = ::SocialSnippet::Logger::Severity::INFO
|
8
|
+
logger
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:config) do
|
12
|
+
::SocialSnippet::Config.new(social_snippet)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:social_snippet) do
|
16
|
+
class Fake; end
|
17
|
+
fake = Fake.new
|
18
|
+
fake
|
19
|
+
end
|
20
|
+
|
21
|
+
before do
|
22
|
+
allow(social_snippet).to receive(:config).and_return config
|
23
|
+
allow(social_snippet).to receive(:logger).and_return logger
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:repo_manager) do
|
27
|
+
::SocialSnippet::Repository::RepositoryManager.new(social_snippet)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "complete (repo)", :current => true do
|
31
|
+
|
32
|
+
before do
|
33
|
+
install_path = "/path/to/install/path"
|
34
|
+
FileUtils.mkdir_p "#{install_path}"
|
35
|
+
FileUtils.mkdir_p "#{install_path}/my-repo"
|
36
|
+
FileUtils.mkdir_p "#{install_path}/new-repo"
|
37
|
+
FileUtils.mkdir_p "#{install_path}/my-math-repo"
|
38
|
+
FileUtils.mkdir_p "#{install_path}/myrepo"
|
39
|
+
allow(repo_manager.installer).to receive(:path).and_return install_path
|
40
|
+
end # prepare files
|
41
|
+
|
42
|
+
context "key = my-" do
|
43
|
+
it { expect(repo_manager.complete "@snip <my-").to include "my-repo" }
|
44
|
+
it { expect(repo_manager.complete "@snip <my-").to_not include "new-repo" }
|
45
|
+
it { expect(repo_manager.complete "@snip <my-").to include "my-math-repo" }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "key = new-" do
|
49
|
+
it { expect(repo_manager.complete "@snip <new-").to_not include "my-repo" }
|
50
|
+
it { expect(repo_manager.complete "@snip <new-").to include "new-repo" }
|
51
|
+
it { expect(repo_manager.complete "@snip <new-").to_not include "my-math-repo" }
|
52
|
+
end
|
53
|
+
|
54
|
+
end # complete (repo)
|
55
|
+
|
56
|
+
describe "is_completing_file_path?", :current => true do
|
57
|
+
|
58
|
+
context "valid cases" do
|
59
|
+
it { expect(repo_manager.is_completing_file_path? "// @snip <repo:").to be_truthy }
|
60
|
+
it { expect(repo_manager.is_completing_file_path? "# @snippet <repo:path").to be_truthy }
|
61
|
+
it { expect(repo_manager.is_completing_file_path? "# @snippet<my-repo:path/to").to be_truthy }
|
62
|
+
it { expect(repo_manager.is_completing_file_path? "@snip<my_repo:path/to/file.cpp").to be_truthy }
|
63
|
+
it { expect(repo_manager.is_completing_file_path? "@snip <repo:path/to").to be_truthy }
|
64
|
+
it { expect(repo_manager.is_completing_file_path? "@snippet <repo:path/to/").to be_truthy }
|
65
|
+
it { expect(repo_manager.is_completing_file_path? "@snippet <my-repo:path/to/file").to be_truthy }
|
66
|
+
it { expect(repo_manager.is_completing_file_path? "//@snip<my_repo:path/to/fi").to be_truthy }
|
67
|
+
end # valid cases
|
68
|
+
|
69
|
+
context "invalid cases" do
|
70
|
+
it { expect(repo_manager.is_completing_file_path? "@snip <repo").to be_falsey }
|
71
|
+
it { expect(repo_manager.is_completing_file_path? "@snippet <repo#").to be_falsey }
|
72
|
+
it { expect(repo_manager.is_completing_file_path? "@snippet <my-repo").to be_falsey }
|
73
|
+
it { expect(repo_manager.is_completing_file_path? "// @snip<my_repo").to be_falsey }
|
74
|
+
it { expect(repo_manager.is_completing_file_path? "// @snip <repo:>").to be_falsey }
|
75
|
+
it { expect(repo_manager.is_completing_file_path? "# @snippet <repo:path>").to be_falsey }
|
76
|
+
it { expect(repo_manager.is_completing_file_path? "# @snippet<my-repo:path/to>").to be_falsey }
|
77
|
+
it { expect(repo_manager.is_completing_file_path? "@snip<my_repo:path/to/file.cpp>").to be_falsey }
|
78
|
+
it { expect(repo_manager.is_completing_file_path? "@snip <repo:path/to>").to be_falsey }
|
79
|
+
it { expect(repo_manager.is_completing_file_path? "@snippet <repo:path/to/>").to be_falsey }
|
80
|
+
it { expect(repo_manager.is_completing_file_path? "@snippet <my-repo:path/to/file>").to be_falsey }
|
81
|
+
it { expect(repo_manager.is_completing_file_path? "//@snip<my_repo:path/to/fi>").to be_falsey }
|
82
|
+
end
|
83
|
+
|
84
|
+
end # is_completing_repo_name?
|
85
|
+
|
86
|
+
describe "is_completing_repo_name?", :current => true do
|
87
|
+
|
88
|
+
context "valid cases" do
|
89
|
+
it { expect(repo_manager.is_completing_repo_name? "@snip <repo").to be_truthy }
|
90
|
+
it { expect(repo_manager.is_completing_repo_name? "@snippet <repo").to be_truthy }
|
91
|
+
it { expect(repo_manager.is_completing_repo_name? "@snippet <my-repo").to be_truthy }
|
92
|
+
it { expect(repo_manager.is_completing_repo_name? "@snip<my_repo").to be_truthy }
|
93
|
+
end # valid cases
|
94
|
+
|
95
|
+
context "invalid cases" do
|
96
|
+
it { expect(repo_manager.is_completing_repo_name? "@snip <repo:").to be_falsey }
|
97
|
+
it { expect(repo_manager.is_completing_repo_name? "@snippet <repo#").to be_falsey }
|
98
|
+
it { expect(repo_manager.is_completing_repo_name? "@snippet <my-repo:").to be_falsey }
|
99
|
+
it { expect(repo_manager.is_completing_repo_name? "@snip<my_repo:").to be_falsey }
|
100
|
+
it { expect(repo_manager.is_completing_repo_name? "@snip <repo>").to be_falsey }
|
101
|
+
it { expect(repo_manager.is_completing_repo_name? "@snippet <repo>").to be_falsey }
|
102
|
+
it { expect(repo_manager.is_completing_repo_name? "@snippet <my-repo>").to be_falsey }
|
103
|
+
it { expect(repo_manager.is_completing_repo_name? "@snip<my_repo>").to be_falsey }
|
104
|
+
end
|
105
|
+
|
106
|
+
end # is_completing_repo_name?
|
107
|
+
|
108
|
+
end # ::SocialSnippet::Repository::RepositoryManager
|
109
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe SocialSnippet::TagParser do
|
4
|
+
|
5
|
+
describe "#find_snip_tags" do
|
6
|
+
|
7
|
+
context "there are two @snip" do
|
8
|
+
|
9
|
+
let(:input) do
|
10
|
+
[
|
11
|
+
"// @snip <path/to/file1.c>",
|
12
|
+
"// @snip <path/to/file2.c>",
|
13
|
+
"// @snippet <path/to/file3.c>",
|
14
|
+
].join("\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
context "result" do
|
18
|
+
let(:result) { SocialSnippet::TagParser.find_snip_tags(input) }
|
19
|
+
it { expect(result.length).to eq 2 }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end # find_snip_tags
|
25
|
+
|
26
|
+
describe "#find_snippet_tags" do
|
27
|
+
|
28
|
+
context "there is a @snippet" do
|
29
|
+
|
30
|
+
let(:input) do
|
31
|
+
[
|
32
|
+
"// @snip <path/to/file1.c>",
|
33
|
+
"// @snip <path/to/file2.c>",
|
34
|
+
"// @snippet <path/to/file3.c>",
|
35
|
+
].join("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
context "result" do
|
39
|
+
let(:result) { SocialSnippet::TagParser.find_snippet_tags(input) }
|
40
|
+
it { expect(result.length).to eq 1 }
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end # find_snippet_tags
|
46
|
+
|
47
|
+
end # SocialSnippet::TagParser
|
data/test/tag_test.rb
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module SocialSnippet
|
4
|
+
|
5
|
+
describe Tag do
|
6
|
+
|
7
|
+
describe "#get_spaces" do
|
8
|
+
|
9
|
+
context "valid cases" do
|
10
|
+
it { expect(Tag.get_spaces("// @snip <path/to/file.cpp>")).to eq " " }
|
11
|
+
it { expect(Tag.get_spaces("# @snip <path/to/file.rb>")).to eq " " }
|
12
|
+
it { expect(Tag.get_spaces("/* @snip <path/to/file.c> */")).to eq " " }
|
13
|
+
it { expect(Tag.get_spaces("@snip <path/to/file.c>")).to eq " " }
|
14
|
+
|
15
|
+
it { expect(Tag.get_spaces("// @snip<path/to/file.cpp>test1")).to eq "" }
|
16
|
+
it { expect(Tag.get_spaces("# @snip<path/to/file.rb>test2")).to eq "" }
|
17
|
+
it { expect(Tag.get_spaces("/* @snip<path/to/file.c>test3*/")).to eq "" }
|
18
|
+
it { expect(Tag.get_spaces("@snip<path/to/file.c>test4")).to eq "" }
|
19
|
+
end # valid caess
|
20
|
+
|
21
|
+
context "invalid cases" do
|
22
|
+
it { expect(Tag.get_spaces("// @snip <path/to/file.cpp")).to eq "" }
|
23
|
+
it { expect(Tag.get_spaces("# @snp <path/to/file.rb>")).to eq "" }
|
24
|
+
it { expect(Tag.get_spaces("/* @snip path/to/file.c> */")).to eq "" }
|
25
|
+
end # invalid cases
|
26
|
+
|
27
|
+
end # get_spaces
|
28
|
+
|
29
|
+
describe "#get_suffix" do
|
30
|
+
|
31
|
+
context "valid cases" do
|
32
|
+
it { expect(Tag.get_suffix("// @snip <path/to/file.cpp>")).to eq "" }
|
33
|
+
it { expect(Tag.get_suffix("# @snip <path/to/file.rb>")).to eq "" }
|
34
|
+
it { expect(Tag.get_suffix("/* @snip <path/to/file.c> */")).to eq " */" }
|
35
|
+
it { expect(Tag.get_suffix("@snip <path/to/file.c>")).to eq "" }
|
36
|
+
|
37
|
+
it { expect(Tag.get_suffix("// @snip <path/to/file.cpp>test1")).to eq "test1" }
|
38
|
+
it { expect(Tag.get_suffix("# @snip <path/to/file.rb>test2")).to eq "test2" }
|
39
|
+
it { expect(Tag.get_suffix("/* @snip <path/to/file.c>test3*/")).to eq "test3*/" }
|
40
|
+
it { expect(Tag.get_suffix("@snip <path/to/file.c>test4")).to eq "test4" }
|
41
|
+
end # valid caess
|
42
|
+
|
43
|
+
context "invalid cases" do
|
44
|
+
it { expect(Tag.get_suffix("// @snip <path/to/file.cpp")).to eq "" }
|
45
|
+
it { expect(Tag.get_suffix("# @snp <path/to/file.rb>")).to eq "" }
|
46
|
+
it { expect(Tag.get_suffix("/* @snip path/to/file.c> */")).to eq "" }
|
47
|
+
end # invalid cases
|
48
|
+
|
49
|
+
end # get_suffix
|
50
|
+
|
51
|
+
describe "#get_prefix" do
|
52
|
+
|
53
|
+
context "valid cases" do
|
54
|
+
it { expect(Tag.get_prefix("// @snip <path/to/file.cpp>")).to eq "// " }
|
55
|
+
it { expect(Tag.get_prefix("# @snip <path/to/file.rb>")).to eq "# " }
|
56
|
+
it { expect(Tag.get_prefix("/* @snip <path/to/file.c> */")).to eq "/* " }
|
57
|
+
it { expect(Tag.get_prefix("@snip <path/to/file.c>")).to eq "" }
|
58
|
+
end # valid caess
|
59
|
+
|
60
|
+
context "invalid cases" do
|
61
|
+
it { expect(Tag.get_prefix("// @snip <path/to/file.cpp")).to eq "" }
|
62
|
+
it { expect(Tag.get_prefix("# @snp <path/to/file.rb>")).to eq "" }
|
63
|
+
it { expect(Tag.get_prefix("/* @snip path/to/file.c> */")).to eq "" }
|
64
|
+
end # invalid cases
|
65
|
+
|
66
|
+
end # get_prefix
|
67
|
+
|
68
|
+
describe "#get_path" do
|
69
|
+
|
70
|
+
context "valid cases" do
|
71
|
+
|
72
|
+
context "without repo" do
|
73
|
+
it { expect(Tag.get_path("// @snip <path/to/file.cpp>")).to eq "path/to/file.cpp" }
|
74
|
+
it { expect(Tag.get_path("# @snip <path/to/file.rb>")).to eq "path/to/file.rb" }
|
75
|
+
it { expect(Tag.get_path("/* @snip <path/to/file.c> */")).to eq "path/to/file.c" }
|
76
|
+
end # without repo
|
77
|
+
|
78
|
+
context "with repo" do
|
79
|
+
it { expect(Tag.get_path("// @snip <repo:path/to/file.cpp>")).to eq "path/to/file.cpp" }
|
80
|
+
it { expect(Tag.get_path("# @snip <repo:path/to/file.rb>")).to eq "path/to/file.rb" }
|
81
|
+
it { expect(Tag.get_path("/* @snip <repo:path/to/file.rb> */")).to eq "path/to/file.rb" }
|
82
|
+
it { expect(Tag.get_path("// @snip <my-repo:path/to/file.cpp>")).to eq "path/to/file.cpp" }
|
83
|
+
it { expect(Tag.get_path("# @snip <my-repo:path/to/file.rb>")).to eq "path/to/file.rb" }
|
84
|
+
it { expect(Tag.get_path("/* @snip <my-repo:path/to/file.c> */")).to eq "path/to/file.c" }
|
85
|
+
end # with repo
|
86
|
+
|
87
|
+
end # valid cases
|
88
|
+
|
89
|
+
context "invalid cases" do
|
90
|
+
|
91
|
+
context "without repo" do
|
92
|
+
it { expect(Tag.get_path("// snip <path/to/file.cpp>")).to eq "" }
|
93
|
+
it { expect(Tag.get_path("# @sni <path/to/file.rb>")).to eq "" }
|
94
|
+
it { expect(Tag.get_path("/* @snipp <path/to/file.c> */")).to eq "" }
|
95
|
+
end # without repo
|
96
|
+
|
97
|
+
context "with repo" do
|
98
|
+
it { expect(Tag.get_path("// @snip repo:path/to/file.cpp")).to eq "" }
|
99
|
+
it { expect(Tag.get_path("# @snip <repo:path/to/file.rb")).to eq "" }
|
100
|
+
it { expect(Tag.get_path("/* @snip repo:path/to/file.rb> */")).to eq "" }
|
101
|
+
it { expect(Tag.get_path("//snip <my-repo:path/to/file.cpp>")).to eq "" }
|
102
|
+
it { expect(Tag.get_path("# @snip2 <my-repo:path/to/file.rb>")).to eq "" }
|
103
|
+
it { expect(Tag.get_path("/* @s <my-repo:path/to/file.c> */")).to eq "" }
|
104
|
+
end # with repo
|
105
|
+
|
106
|
+
end # invalid cases
|
107
|
+
|
108
|
+
end # get_path
|
109
|
+
|
110
|
+
describe "#get_repo" do
|
111
|
+
|
112
|
+
context "without repo" do
|
113
|
+
it { expect(Tag.get_repo("// @snip <path/to/file.cpp>")).to eq "" }
|
114
|
+
it { expect(Tag.get_repo("# @snip <path/to/file.rb>")).to eq "" }
|
115
|
+
it { expect(Tag.get_repo("/* @snip <path/to/file.rb> */")).to eq "" }
|
116
|
+
end # without repo
|
117
|
+
|
118
|
+
context "with repo" do
|
119
|
+
it { expect(Tag.get_repo("// @snip <repo:path/to/file.cpp>")).to eq "repo" }
|
120
|
+
it { expect(Tag.get_repo("# @snip <repo:path/to/file.rb>")).to eq "repo" }
|
121
|
+
it { expect(Tag.get_repo("/* @snip <repo:path/to/file.rb> */")).to eq "repo" }
|
122
|
+
it { expect(Tag.get_repo("// @snip <my-repo:path/to/file.cpp>")).to eq "my-repo" }
|
123
|
+
it { expect(Tag.get_repo("# @snip <my-repo:path/to/file.rb>")).to eq "my-repo" }
|
124
|
+
it { expect(Tag.get_repo("/* @snip <my-repo:path/to/file.rb> */")).to eq "my-repo" }
|
125
|
+
end # with repo
|
126
|
+
|
127
|
+
end # get_repo
|
128
|
+
|
129
|
+
describe "#is_snip_tag_line" do
|
130
|
+
|
131
|
+
context "valid cases" do
|
132
|
+
|
133
|
+
context "relative path without `./`" do
|
134
|
+
it { expect(Tag.is_snip_tag_line("// @snip <path/to/file.cpp>")).to be_truthy }
|
135
|
+
it { expect(Tag.is_snip_tag_line("/* @snip <path/to/file.c> */")).to be_truthy }
|
136
|
+
it { expect(Tag.is_snip_tag_line("# @snip <path/to/file.py>")).to be_truthy }
|
137
|
+
end
|
138
|
+
|
139
|
+
context "relative path start with `./`" do
|
140
|
+
it { expect(Tag.is_snip_tag_line("// @snip <./path/to/file.cpp>")).to be_truthy }
|
141
|
+
it { expect(Tag.is_snip_tag_line("/* @snip <./path/to/file.c> */")).to be_truthy }
|
142
|
+
it { expect(Tag.is_snip_tag_line("# @snip <./path/to/file.py>")).to be_truthy }
|
143
|
+
end
|
144
|
+
|
145
|
+
context "with repo without `/`" do
|
146
|
+
it { expect(Tag.is_snip_tag_line("// @snip <repo:path/to/file.cpp>")).to be_truthy }
|
147
|
+
it { expect(Tag.is_snip_tag_line("/* @snip <repo:path/to/file.c> */")).to be_truthy }
|
148
|
+
it { expect(Tag.is_snip_tag_line("# @snip <repo:path/to/file.py>")).to be_truthy }
|
149
|
+
end
|
150
|
+
|
151
|
+
context "with repo and start with `/`" do
|
152
|
+
it { expect(Tag.is_snip_tag_line("// @snip <repo:/path/to/file.cpp>")).to be_truthy }
|
153
|
+
it { expect(Tag.is_snip_tag_line("/* @snip <repo:/path/to/file.c> */")).to be_truthy }
|
154
|
+
it { expect(Tag.is_snip_tag_line("# @snip <repo:/path/to/file.py>")).to be_truthy }
|
155
|
+
end
|
156
|
+
|
157
|
+
# TODO: add `@snip <{repo}#{version}:{path}>`
|
158
|
+
|
159
|
+
end # valid cases
|
160
|
+
|
161
|
+
context "invalid cases" do
|
162
|
+
it { expect(Tag.is_snip_tag_line("// @snip2 <path/to/file.cpp>")).to be_falsey }
|
163
|
+
it { expect(Tag.is_snip_tag_line("// @sni <path/to/file.cpp>")).to be_falsey }
|
164
|
+
it { expect(Tag.is_snip_tag_line("// @snip <path/to/file.cpp")).to be_falsey }
|
165
|
+
it { expect(Tag.is_snip_tag_line("// @snip path/to/file.cpp>")).to be_falsey }
|
166
|
+
it { expect(Tag.is_snip_tag_line("/* @ snip <path/to/file.c> */")).to be_falsey }
|
167
|
+
it { expect(Tag.is_snip_tag_line("# @snp <path/to/file.py>")).to be_falsey }
|
168
|
+
end # invalid cases
|
169
|
+
|
170
|
+
end # is_snip_tag_line
|
171
|
+
|
172
|
+
describe "#is_snippet_tag_line" do
|
173
|
+
|
174
|
+
context "valid cases" do
|
175
|
+
|
176
|
+
context "relative path without `./`" do
|
177
|
+
it { expect(Tag.is_snippet_tag_line("// @snippet <path/to/file.cpp>")).to be_truthy }
|
178
|
+
it { expect(Tag.is_snippet_tag_line("/* @snippet <path/to/file.c> */")).to be_truthy }
|
179
|
+
it { expect(Tag.is_snippet_tag_line("# @snippet <path/to/file.py>")).to be_truthy }
|
180
|
+
end
|
181
|
+
|
182
|
+
context "relative path start with `./`" do
|
183
|
+
it { expect(Tag.is_snippet_tag_line("// @snippet <./path/to/file.cpp>")).to be_truthy }
|
184
|
+
it { expect(Tag.is_snippet_tag_line("/* @snippet <./path/to/file.c> */")).to be_truthy }
|
185
|
+
it { expect(Tag.is_snippet_tag_line("# @snippet <./path/to/file.py>")).to be_truthy }
|
186
|
+
end
|
187
|
+
|
188
|
+
context "with repo" do
|
189
|
+
it { expect(Tag.is_snippet_tag_line("// @snippet <repo:path/to/file.cpp>")).to be_truthy }
|
190
|
+
it { expect(Tag.is_snippet_tag_line("/* @snippet <repo:path/to/file.c> */")).to be_truthy }
|
191
|
+
it { expect(Tag.is_snippet_tag_line("# @snippet <repo:path/to/file.py>")).to be_truthy }
|
192
|
+
end
|
193
|
+
|
194
|
+
context "with repo start with `/`" do
|
195
|
+
it { expect(Tag.is_snippet_tag_line("// @snippet <repo:/path/to/file.cpp>")).to be_truthy }
|
196
|
+
it { expect(Tag.is_snippet_tag_line("/* @snippet <repo:/path/to/file.c> */")).to be_truthy }
|
197
|
+
it { expect(Tag.is_snippet_tag_line("# @snippet <repo:/path/to/file.py>")).to be_truthy }
|
198
|
+
end
|
199
|
+
|
200
|
+
# TODO: add `@snippet <{repo}#{version}:{path}>`
|
201
|
+
|
202
|
+
end # valid cases
|
203
|
+
|
204
|
+
context "invalid cases" do
|
205
|
+
it { expect(Tag.is_snippet_tag_line("// @snippet2 <path/to/file.cpp>")).to be_falsey }
|
206
|
+
it { expect(Tag.is_snippet_tag_line("// @snippe <path/to/file.cpp>")).to be_falsey }
|
207
|
+
it { expect(Tag.is_snippet_tag_line("// @snippet <path/to/file.cpp")).to be_falsey }
|
208
|
+
it { expect(Tag.is_snippet_tag_line("// @snippet path/to/file.cpp>")).to be_falsey }
|
209
|
+
it { expect(Tag.is_snippet_tag_line("/* @ snippet <path/to/file.c> */")).to be_falsey }
|
210
|
+
it { expect(Tag.is_snippet_tag_line("# @snppet <path/to/file.py>")).to be_falsey }
|
211
|
+
end
|
212
|
+
|
213
|
+
end # is_snippet_tag_line
|
214
|
+
|
215
|
+
end # Tag
|
216
|
+
|
217
|
+
end # SocialSnippet
|