xolti 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ # tc_config.rb
2
+ # Copyright (C) Rémi Even 2016
3
+ #
4
+ # This file is part of Xolti.
5
+ #
6
+ # Xolti is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Xolti is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Xolti. If not, see <http://www.gnu.org/licenses/>.
18
+ require "test/unit"
19
+
20
+ require_relative "../lib/config"
21
+
22
+ class TestConfig < Test::Unit::TestCase
23
+
24
+ def test_default_comment
25
+ sut = XoltiConfig.new({
26
+ "project_info" => {
27
+ "project_name" => "Xolti",
28
+ "author" => "Rémi Even"
29
+ },
30
+ "template" => "Header",
31
+ "comment" => {
32
+ "tex" => "% "
33
+ }
34
+ })
35
+ assert_equal(sut.get_comment("someUnknownExtension"), ["/*", " * ", " */"])
36
+ assert_equal(sut.get_comment("rb"), "# ")
37
+ assert_equal(sut.get_comment("tex"), "% ")
38
+ assert_equal(sut.get_comment(".tex"), "% ")
39
+ end
40
+ end
@@ -0,0 +1,54 @@
1
+ # tc_header_validator.rb
2
+ # Copyright (C) Rémi Even 2016
3
+ #
4
+ # This file is part of Xolti.
5
+ #
6
+ # Xolti is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Xolti is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Xolti. If not, see <http://www.gnu.org/licenses/>.
18
+ require "test/unit"
19
+
20
+ require_relative "../lib/header_validator"
21
+
22
+ class TestHeaderValidator < Test::Unit::TestCase
23
+
24
+ def test_diff
25
+ actual_file_name = "awesme.txt"
26
+ actual_year = "2017"
27
+ actual_author = "Remi E"
28
+ actual_project_name = "Xolti"
29
+ detected = {
30
+ start: 2,
31
+ matches: [
32
+ "# #{actual_file_name}".match(/^(# )(?<file_name>.*)$/),
33
+ "# ".match(/^(# )$/),
34
+ "# (C) #{actual_year} #{actual_author}".match(/^(# \(C\) )(?<year>[[:digit:]]{4})( )(?<author>.*)$/),
35
+ "# Project #{actual_project_name}".match(/^(# Project )(?<project_name>.*)/)
36
+ ]
37
+ }
38
+ expected_file_name = "awesome.txt"
39
+ expected_year = "2016"
40
+ expected_author = "Rémi Even"
41
+ expected_project_name = actual_project_name
42
+ info = {
43
+ file_name: expected_file_name,
44
+ year: expected_year,
45
+ author: expected_author,
46
+ project_name: expected_project_name
47
+ }
48
+ diff = HeaderValidator.diff(detected, info)
49
+ assert_equal(diff.length, 3)
50
+ assert_equal(diff[0], {line: 3, expected: expected_file_name, actual: actual_file_name})
51
+ assert_equal(diff[1], {line: 5, expected: expected_year, actual: actual_year})
52
+ assert_equal(diff[2], {line: 5, expected: expected_author, actual: actual_author})
53
+ end
54
+ end
@@ -0,0 +1,58 @@
1
+ # tc_template_utils.rb
2
+ # Copyright (C) Rémi Even 2016
3
+ #
4
+ # This file is part of Xolti.
5
+ #
6
+ # Xolti is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Xolti is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Xolti. If not, see <http://www.gnu.org/licenses/>.
18
+ require "test/unit"
19
+
20
+ require_relative "../lib/template_utils"
21
+
22
+ class TestTemplateUtils < Test::Unit::TestCase
23
+
24
+ def test_find_template_tokens_indexes
25
+ assert_equal([], TemplateUtils.find_template_tokens_indexes(""))
26
+ assert_equal([], TemplateUtils.find_template_tokens_indexes("ee"))
27
+ assert_equal([2, 5], TemplateUtils.find_template_tokens_indexes("ee%{r}"))
28
+ assert_equal([2, 5, 7, 12], TemplateUtils.find_template_tokens_indexes("ee%{r} %{abc}fe"))
29
+ end
30
+
31
+ def test_split_template_tokens_from_line
32
+ assert_equal(["ee"], TemplateUtils.split_template_tokens_from_line("ee"))
33
+ assert_equal(["ee", "%{coucou}"], TemplateUtils.split_template_tokens_from_line("ee%{coucou}"))
34
+ assert_equal(["%{coucou}"], TemplateUtils.split_template_tokens_from_line("%{coucou}"))
35
+ assert_equal(["ee", "%{coucou}", "ee"], TemplateUtils.split_template_tokens_from_line("ee%{coucou}ee"))
36
+ assert_equal(["ee", "%{coucou}", "ee", "%{coucou}"], TemplateUtils.split_template_tokens_from_line("ee%{coucou}ee%{coucou}"))
37
+ assert_equal(["ee", "%{coucou}", "%{coucou}"], TemplateUtils.split_template_tokens_from_line("ee%{coucou}%{coucou}"))
38
+ end
39
+
40
+ def test_create_detection_regexp_for_line
41
+ assert_match(TemplateUtils.create_detection_regexp_for_line("e"), "e")
42
+ assert_match(TemplateUtils.create_detection_regexp_for_line("."), ".")
43
+ assert_no_match(TemplateUtils.create_detection_regexp_for_line("."), "a")
44
+ assert_match(TemplateUtils.create_detection_regexp_for_line("%{r}"), "azer")
45
+ assert_match(TemplateUtils.create_detection_regexp_for_line(""), "")
46
+ assert_match(TemplateUtils.create_detection_regexp_for_line("a%{r}r"), "azer")
47
+ assert_no_match(TemplateUtils.create_detection_regexp_for_line("z%{r}f"), "azer")
48
+ end
49
+
50
+ def test_extract_tag_type
51
+ assert_equal(TemplateUtils.extract_tag_type("%{coucou}"), "coucou")
52
+ end
53
+
54
+ def test_tag?
55
+ assert(TemplateUtils.tag?("%{coucou}"))
56
+ refute(TemplateUtils.tag?("blabla"))
57
+ end
58
+ end
@@ -17,5 +17,7 @@
17
17
  # along with Xolti. If not, see <http://www.gnu.org/licenses/>.
18
18
  require "test/unit"
19
19
 
20
- require_relative "tc_header_detection"
20
+ require_relative "tc_template_utils"
21
21
  require_relative "tc_comment"
22
+ require_relative "tc_config"
23
+ require_relative "tc_header_validator"
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "xolti"
3
- spec.version = "0.0.0"
3
+ spec.version = "0.1.0"
4
4
  spec.summary = "A gem to manage license headers"
5
- spec.description = "A gem to manage license headers"
5
+ spec.description = "A gem to manage license headers, providing a simple CLI."
6
6
  spec.authors = ["Rémi Even"]
7
7
  spec.homepage = "https://github.com/RemiEven/xolti"
8
8
  spec.license = "GPL-3.0"
data/xolti.yml CHANGED
@@ -2,22 +2,4 @@
2
2
  project_info:
3
3
  project_name: Xolti
4
4
  author: "Rémi Even"
5
- comment: "# "
6
- template: |
7
- %{file_name}
8
- Copyright (C) %{author} %{year}
9
-
10
- This file is part of %{project_name}.
11
-
12
- %{project_name} is free software: you can redistribute it and/or modify
13
- it under the terms of the GNU General Public License as published by
14
- the Free Software Foundation, either version 3 of the License, or
15
- (at your option) any later version.
16
-
17
- %{project_name} is distributed in the hope that it will be useful,
18
- but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- GNU General Public License for more details.
21
-
22
- You should have received a copy of the GNU General Public License
23
- along with %{project_name}. If not, see <http://www.gnu.org/licenses/>.
5
+ license: GPL3.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xolti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Even
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-15 00:00:00.000000000 Z
11
+ date: 2016-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -30,7 +30,7 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.19.1
33
- description: A gem to manage license headers
33
+ description: A gem to manage license headers, providing a simple CLI.
34
34
  email:
35
35
  executables:
36
36
  - xolti
@@ -40,17 +40,28 @@ files:
40
40
  - ".travis.yml"
41
41
  - ".xoltignore"
42
42
  - Gemfile
43
+ - LICENSE
43
44
  - Rakefile
44
45
  - exe/xolti
45
46
  - lib/comment.rb
46
47
  - lib/config.rb
47
48
  - lib/core.rb
49
+ - lib/default_comment_tokens.rb
48
50
  - lib/file_finder.rb
49
- - lib/header_detection.rb
51
+ - lib/file_modification.rb
52
+ - lib/header_detector.rb
53
+ - lib/header_generator.rb
54
+ - lib/header_validator.rb
55
+ - lib/resources.rb
56
+ - lib/template_utils.rb
50
57
  - lib/xolti.rb
51
58
  - readme.md
59
+ - resources/headers/GPL3.0
60
+ - resources/licenses/GPL3.0
52
61
  - test/tc_comment.rb
53
- - test/tc_header_detection.rb
62
+ - test/tc_config.rb
63
+ - test/tc_header_validator.rb
64
+ - test/tc_template_utils.rb
54
65
  - test/ts_xolti.rb
55
66
  - xolti.gemspec
56
67
  - xolti.yml
@@ -1,58 +0,0 @@
1
- # tc_header_detection.rb
2
- # Copyright (C) Rémi Even 2016
3
- #
4
- # This file is part of Xolti.
5
- #
6
- # Xolti is free software: you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation, either version 3 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # Xolti is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with Xolti. If not, see <http://www.gnu.org/licenses/>.
18
- require "test/unit"
19
-
20
- require_relative "../lib/header_detection"
21
-
22
- class TestHeaderDetection < Test::Unit::TestCase
23
-
24
- def test_find_template_tokens_indexes
25
- assert_equal([], HeaderDetection.find_template_tokens_indexes(""))
26
- assert_equal([], HeaderDetection.find_template_tokens_indexes("ee"))
27
- assert_equal([2, 5], HeaderDetection.find_template_tokens_indexes("ee%{r}"))
28
- assert_equal([2, 5, 7, 12], HeaderDetection.find_template_tokens_indexes("ee%{r} %{abc}fe"))
29
- end
30
-
31
- def test_split_template_tokens_from_line
32
- assert_equal(["ee"], HeaderDetection.split_template_tokens_from_line("ee"))
33
- assert_equal(["ee", "%{coucou}"], HeaderDetection.split_template_tokens_from_line("ee%{coucou}"))
34
- assert_equal(["%{coucou}"], HeaderDetection.split_template_tokens_from_line("%{coucou}"))
35
- assert_equal(["ee", "%{coucou}", "ee"], HeaderDetection.split_template_tokens_from_line("ee%{coucou}ee"))
36
- assert_equal(["ee", "%{coucou}", "ee", "%{coucou}"], HeaderDetection.split_template_tokens_from_line("ee%{coucou}ee%{coucou}"))
37
- assert_equal(["ee", "%{coucou}", "%{coucou}"], HeaderDetection.split_template_tokens_from_line("ee%{coucou}%{coucou}"))
38
- end
39
-
40
- def test_create_detection_regexp_for_line
41
- assert_match(HeaderDetection.create_detection_regexp_for_line("e"), "e")
42
- assert_match(HeaderDetection.create_detection_regexp_for_line("."), ".")
43
- assert_no_match(HeaderDetection.create_detection_regexp_for_line("."), "a")
44
- assert_match(HeaderDetection.create_detection_regexp_for_line("%{r}"), "azer")
45
- assert_match(HeaderDetection.create_detection_regexp_for_line(""), "")
46
- assert_match(HeaderDetection.create_detection_regexp_for_line("a%{r}r"), "azer")
47
- assert_no_match(HeaderDetection.create_detection_regexp_for_line("z%{r}f"), "azer")
48
- end
49
-
50
- def test_extract_tag_type
51
- assert_equal(HeaderDetection.extract_tag_type("%{coucou}"), "coucou")
52
- end
53
-
54
- def test_tag?
55
- assert(HeaderDetection.tag?("%{coucou}"))
56
- refute(HeaderDetection.tag?("blabla"))
57
- end
58
- end