docks_app 0.0.1
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.
- data/.editorconfig +8 -0
- data/.gitignore +22 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +3 -0
- data/bin/docks +5 -0
- data/config/json/docks_config.json +71 -0
- data/config/ruby/docks_config.rb +127 -0
- data/config/yaml/docks_config.yml +70 -0
- data/docks.gemspec +38 -0
- data/lib/docks/build.rb +300 -0
- data/lib/docks/cache.rb +143 -0
- data/lib/docks/command_line.rb +65 -0
- data/lib/docks/configuration.rb +217 -0
- data/lib/docks/containers/base_container.rb +103 -0
- data/lib/docks/containers/class_container.rb +39 -0
- data/lib/docks/containers/component_container.rb +92 -0
- data/lib/docks/containers/demo_container.rb +105 -0
- data/lib/docks/containers/factory_container.rb +12 -0
- data/lib/docks/containers/function_container.rb +46 -0
- data/lib/docks/containers/mixin_container.rb +19 -0
- data/lib/docks/containers/pattern_container.rb +168 -0
- data/lib/docks/containers/pattern_library_container.rb +77 -0
- data/lib/docks/containers/state_container.rb +9 -0
- data/lib/docks/containers/symbol_container.rb +77 -0
- data/lib/docks/containers/variable_container.rb +47 -0
- data/lib/docks/containers/variant_container.rb +9 -0
- data/lib/docks/containers/variation_container.rb +38 -0
- data/lib/docks/containers.rb +25 -0
- data/lib/docks/descriptor.rb +60 -0
- data/lib/docks/errors.rb +5 -0
- data/lib/docks/group.rb +66 -0
- data/lib/docks/helpers/github_helper.rb +29 -0
- data/lib/docks/helpers/path_helper.rb +94 -0
- data/lib/docks/helpers/render_helper.rb +87 -0
- data/lib/docks/helpers.rb +19 -0
- data/lib/docks/languages/base_language.rb +17 -0
- data/lib/docks/languages/coffeescript_language.rb +30 -0
- data/lib/docks/languages/common_types/markup_language.rb +71 -0
- data/lib/docks/languages/css_language.rb +13 -0
- data/lib/docks/languages/erb_language.rb +21 -0
- data/lib/docks/languages/haml_language.rb +21 -0
- data/lib/docks/languages/html_language.rb +10 -0
- data/lib/docks/languages/javascript_language.rb +42 -0
- data/lib/docks/languages/json_language.rb +18 -0
- data/lib/docks/languages/less_language.rb +33 -0
- data/lib/docks/languages/markdown_language.rb +10 -0
- data/lib/docks/languages/sass_language.rb +36 -0
- data/lib/docks/languages/slim_language.rb +21 -0
- data/lib/docks/languages/stylus_language.rb +26 -0
- data/lib/docks/languages/yaml_language.rb +18 -0
- data/lib/docks/languages.rb +103 -0
- data/lib/docks/markdown.rb +18 -0
- data/lib/docks/messenger.rb +69 -0
- data/lib/docks/naming_conventions/base_naming_convention.rb +9 -0
- data/lib/docks/naming_conventions/bem_naming_convention.rb +45 -0
- data/lib/docks/naming_conventions/suit_naming_convention.rb +45 -0
- data/lib/docks/naming_conventions.rb +21 -0
- data/lib/docks/ostruct.rb +17 -0
- data/lib/docks/parser.rb +86 -0
- data/lib/docks/parsers/base_parser.rb +128 -0
- data/lib/docks/parsers/coffeescript_parser.rb +30 -0
- data/lib/docks/parsers/css_parser.rb +27 -0
- data/lib/docks/parsers/javascript_parser.rb +30 -0
- data/lib/docks/parsers/less_parser.rb +22 -0
- data/lib/docks/parsers/sass_parser.rb +31 -0
- data/lib/docks/parsers/stylus_parser.rb +28 -0
- data/lib/docks/process.rb +60 -0
- data/lib/docks/processors.rb +416 -0
- data/lib/docks/renderers/base_renderer.rb +64 -0
- data/lib/docks/renderers/common_features/capturable.rb +69 -0
- data/lib/docks/renderers/common_features/helperable.rb +23 -0
- data/lib/docks/renderers/erb_renderer.rb +68 -0
- data/lib/docks/renderers/haml_renderer.rb +37 -0
- data/lib/docks/renderers/slim_renderer.rb +33 -0
- data/lib/docks/symbol_sources/base_symbol_source.rb +12 -0
- data/lib/docks/symbol_sources/jquery_symbol_source.rb +17 -0
- data/lib/docks/symbol_sources/mdn_symbol_source.rb +35 -0
- data/lib/docks/symbol_sources/sass_symbol_source.rb +27 -0
- data/lib/docks/symbol_sources.rb +28 -0
- data/lib/docks/tags/access_tag.rb +27 -0
- data/lib/docks/tags/activate_with_tag.rb +17 -0
- data/lib/docks/tags/active_tag.rb +14 -0
- data/lib/docks/tags/alias_tag.rb +17 -0
- data/lib/docks/tags/author_tag.rb +19 -0
- data/lib/docks/tags/base_tag.rb +52 -0
- data/lib/docks/tags/beta_tag.rb +26 -0
- data/lib/docks/tags/class_tag.rb +16 -0
- data/lib/docks/tags/compatibility_tag.rb +19 -0
- data/lib/docks/tags/demo_type_tag.rb +14 -0
- data/lib/docks/tags/deprecated_tag.rb +26 -0
- data/lib/docks/tags/description_tag.rb +99 -0
- data/lib/docks/tags/example_tag.rb +20 -0
- data/lib/docks/tags/factory_tag.rb +16 -0
- data/lib/docks/tags/for_tag.rb +23 -0
- data/lib/docks/tags/group_tag.rb +10 -0
- data/lib/docks/tags/helper_tag.rb +13 -0
- data/lib/docks/tags/include_with_tag.rb +57 -0
- data/lib/docks/tags/javascript_action_tag.rb +10 -0
- data/lib/docks/tags/link_tag.rb +18 -0
- data/lib/docks/tags/markup_tag.rb +106 -0
- data/lib/docks/tags/member_tag.rb +37 -0
- data/lib/docks/tags/method_tag.rb +18 -0
- data/lib/docks/tags/name_tag.rb +10 -0
- data/lib/docks/tags/object_tag.rb +15 -0
- data/lib/docks/tags/param_tag.rb +94 -0
- data/lib/docks/tags/pattern_tag.rb +21 -0
- data/lib/docks/tags/preclude_tag.rb +17 -0
- data/lib/docks/tags/private_tag.rb +15 -0
- data/lib/docks/tags/property_tag.rb +18 -0
- data/lib/docks/tags/public_tag.rb +15 -0
- data/lib/docks/tags/require_tag.rb +47 -0
- data/lib/docks/tags/returns_tag.rb +31 -0
- data/lib/docks/tags/set_by_tag.rb +18 -0
- data/lib/docks/tags/signature_tag.rb +35 -0
- data/lib/docks/tags/since_tag.rb +26 -0
- data/lib/docks/tags/source_tag.rb +12 -0
- data/lib/docks/tags/state_tag.rb +21 -0
- data/lib/docks/tags/static_tag.rb +14 -0
- data/lib/docks/tags/subcomponent_tag.rb +68 -0
- data/lib/docks/tags/subtitle_tag.rb +11 -0
- data/lib/docks/tags/symbol_type_tag.rb +10 -0
- data/lib/docks/tags/throws_tag.rb +30 -0
- data/lib/docks/tags/title_tag.rb +10 -0
- data/lib/docks/tags/type_tag.rb +10 -0
- data/lib/docks/tags/value_tag.rb +10 -0
- data/lib/docks/tags/variant_tag.rb +21 -0
- data/lib/docks/tags/variation_tag.rb +136 -0
- data/lib/docks/tags.rb +103 -0
- data/lib/docks/templates.rb +122 -0
- data/lib/docks/themes.rb +19 -0
- data/lib/docks/types.rb +26 -0
- data/lib/docks/version.rb +3 -0
- data/lib/docks.rb +37 -0
- data/spec/fixtures/build/scripts/bar/bar_2.js +1 -0
- data/spec/fixtures/build/scripts/bar.js +1 -0
- data/spec/fixtures/build/styles/foo/foo-2.css +1 -0
- data/spec/fixtures/build/styles/foo.css +1 -0
- data/spec/fixtures/build/templates/baz/baz_2.erb +1 -0
- data/spec/fixtures/build/templates/baz.erb +1 -0
- data/spec/fixtures/grouper/components/button/button.coffee +0 -0
- data/spec/fixtures/grouper/components/button/button.haml +0 -0
- data/spec/fixtures/grouper/components/button/button.scss +0 -0
- data/spec/fixtures/grouper/components/checkbox/_checkbox.haml +0 -0
- data/spec/fixtures/grouper/components/checkbox/_checkbox.scss +0 -0
- data/spec/fixtures/grouper/components/checkbox/checkbox.coffee +0 -0
- data/spec/fixtures/grouper/components/form/form.coffee +0 -0
- data/spec/fixtures/grouper/components/form/form.m +0 -0
- data/spec/fixtures/grouper/components/form/form.scss +0 -0
- data/spec/fixtures/grouper/components/next-expanding-textarea/_next-expanding-textarea.scss +0 -0
- data/spec/fixtures/grouper/components/next-expanding-textarea/_next_expanding_textarea.coffee +0 -0
- data/spec/fixtures/grouper/components/next-expanding-textarea/next-expanding-textarea.haml +0 -0
- data/spec/fixtures/grouper/components/next-tab/next-tab.coffee +0 -0
- data/spec/fixtures/grouper/components/next-tab/next-tab.haml +0 -0
- data/spec/fixtures/grouper/components/next-tab/next-tab.scss +0 -0
- data/spec/fixtures/grouper/components/segmented control/segmented control.coffee +0 -0
- data/spec/fixtures/grouper/components/segmented control/segmented control.haml +0 -0
- data/spec/fixtures/grouper/components/segmented control/segmented control.min.html +0 -0
- data/spec/fixtures/grouper/components/segmented control/segmented control.scss +0 -0
- data/spec/fixtures/grouper/markup/list-view.haml +0 -0
- data/spec/fixtures/grouper/markup/resizable/resizable.haml +0 -0
- data/spec/fixtures/grouper/markup/toggle.haml +0 -0
- data/spec/fixtures/grouper/scripts/resizable/resizable.coffee +0 -0
- data/spec/fixtures/grouper/scripts/toggle.coffee +0 -0
- data/spec/fixtures/grouper/style/_list-view.scss +0 -0
- data/spec/fixtures/grouper/style/_toggle.scss +0 -0
- data/spec/fixtures/languages/stub.json +3 -0
- data/spec/fixtures/languages/stub.yml +2 -0
- data/spec/fixtures/parsers/coffeescript_parser_fixture_basic.coffee +20 -0
- data/spec/fixtures/parsers/coffeescript_parser_fixture_complex.coffee +80 -0
- data/spec/fixtures/parsers/css_parser_fixture_basic.css +44 -0
- data/spec/fixtures/parsers/css_parser_fixture_complex.css +120 -0
- data/spec/fixtures/parsers/javascript_parser_fixture_basic.js +27 -0
- data/spec/fixtures/parsers/javascript_parser_fixture_complex.js +85 -0
- data/spec/fixtures/parsers/sass_parser_fixture_basic.scss +39 -0
- data/spec/fixtures/parsers/sass_parser_fixture_complex.scss +149 -0
- data/spec/fixtures/parsers/stylus_parser_fixture_basic.styl +34 -0
- data/spec/fixtures/parsers/stylus_parser_fixture_complex.styl +113 -0
- data/spec/fixtures/processors/join_with_smart_line_breaks/code_blocks.txt +10 -0
- data/spec/fixtures/processors/join_with_smart_line_breaks/headings.txt +15 -0
- data/spec/fixtures/processors/join_with_smart_line_breaks/lists.txt +21 -0
- data/spec/fixtures/processors/join_with_smart_line_breaks/lists_with_nesting.txt +13 -0
- data/spec/fixtures/processors/join_with_smart_line_breaks/multiple_paragraphs.txt +11 -0
- data/spec/fixtures/renderers/helpers.rb +37 -0
- data/spec/fixtures/renderers/html_output.html +7 -0
- data/spec/fixtures/renderers/templates/layouts/application.html.erb +0 -0
- data/spec/fixtures/renderers/templates/layouts/more/subdirectory.html.erb +0 -0
- data/spec/fixtures/renderers/templates/partials/_leading_underscore.html.erb +1 -0
- data/spec/fixtures/renderers/templates/partials/more/_subdirectory.html.erb +1 -0
- data/spec/fixtures/renderers/templates/partials/partial.html.erb +0 -0
- data/spec/fixtures/renderers/templates/partials/template.html.erb +1 -0
- data/spec/fixtures/renderers/templates/template.html.erb +1 -0
- data/spec/fixtures/tags/description/button.md +24 -0
- data/spec/fixtures/tags/description/class.md +27 -0
- data/spec/fixtures/tags/description/component.md +23 -0
- data/spec/fixtures/tags/description/function.md +30 -0
- data/spec/lib/build_spec.rb +467 -0
- data/spec/lib/cache_spec.rb +175 -0
- data/spec/lib/command_line_spec.rb +77 -0
- data/spec/lib/configuration_spec.rb +180 -0
- data/spec/lib/containers/base_container_spec.rb +214 -0
- data/spec/lib/containers/class_container_spec.rb +209 -0
- data/spec/lib/containers/component_container_spec.rb +158 -0
- data/spec/lib/containers/demo_container_spec.rb +113 -0
- data/spec/lib/containers/function_container_spec.rb +116 -0
- data/spec/lib/containers/mixin_container_spec.rb +4 -0
- data/spec/lib/containers/pattern_container_spec.rb +291 -0
- data/spec/lib/containers/pattern_library_container_spec.rb +130 -0
- data/spec/lib/containers/symbol_container_spec.rb +216 -0
- data/spec/lib/containers/variable_container_spec.rb +116 -0
- data/spec/lib/containers/variation_container_spec.rb +52 -0
- data/spec/lib/containers_spec.rb +22 -0
- data/spec/lib/descriptor_spec.rb +73 -0
- data/spec/lib/group_spec.rb +151 -0
- data/spec/lib/helpers/path_helper_spec.rb +202 -0
- data/spec/lib/helpers/render_helper_spec.rb +159 -0
- data/spec/lib/helpers_spec.rb +35 -0
- data/spec/lib/languages/base_language_spec.rb +32 -0
- data/spec/lib/languages/coffeescript_language_spec.rb +52 -0
- data/spec/lib/languages/css_language_spec.rb +13 -0
- data/spec/lib/languages/erb_language_spec.rb +33 -0
- data/spec/lib/languages/haml_language_spec.rb +32 -0
- data/spec/lib/languages/javascript_language_spec.rb +54 -0
- data/spec/lib/languages/json_language_spec.rb +24 -0
- data/spec/lib/languages/less_language_spec.rb +39 -0
- data/spec/lib/languages/markup_language_spec.rb +95 -0
- data/spec/lib/languages/sass_language_spec.rb +53 -0
- data/spec/lib/languages/slim_language_spec.rb +32 -0
- data/spec/lib/languages/stylus_language_spec.rb +34 -0
- data/spec/lib/languages/yaml_language_spec.rb +24 -0
- data/spec/lib/languages_spec.rb +127 -0
- data/spec/lib/markdown_spec.rb +63 -0
- data/spec/lib/messenger_spec.rb +1 -0
- data/spec/lib/naming_conventions/bem_naming_convention_spec.rb +112 -0
- data/spec/lib/naming_conventions/suit_naming_convention_spec.rb +107 -0
- data/spec/lib/naming_conventions_spec.rb +28 -0
- data/spec/lib/ostruct_spec.rb +15 -0
- data/spec/lib/parser_spec.rb +93 -0
- data/spec/lib/parsers/base_parser_spec.rb +128 -0
- data/spec/lib/parsers/coffeescript_parser_spec.rb +184 -0
- data/spec/lib/parsers/css_parser_spec.rb +136 -0
- data/spec/lib/parsers/javascript_parser_spec.rb +216 -0
- data/spec/lib/parsers/less_parser_spec.rb +111 -0
- data/spec/lib/parsers/sass_parser_spec.rb +233 -0
- data/spec/lib/parsers/stylus_parser_spec.rb +212 -0
- data/spec/lib/process_spec.rb +96 -0
- data/spec/lib/processors_spec.rb +555 -0
- data/spec/lib/renderers/base_renderer_spec.rb +122 -0
- data/spec/lib/renderers/common_features/helperable_spec.rb +30 -0
- data/spec/lib/renderers/erb_renderer_spec.rb +119 -0
- data/spec/lib/renderers/haml_renderer_spec.rb +103 -0
- data/spec/lib/renderers/slim_renderer_spec.rb +103 -0
- data/spec/lib/symbol_sources/jquery_symbol_source_spec.rb +25 -0
- data/spec/lib/symbol_sources/mdn_symbol_source_spec.rb +40 -0
- data/spec/lib/symbol_sources/sass_symbol_source_spec.rb +39 -0
- data/spec/lib/symbol_sources_spec.rb +19 -0
- data/spec/lib/tags/access_tag_spec.rb +32 -0
- data/spec/lib/tags/activate_with_tag_spec.rb +31 -0
- data/spec/lib/tags/active_tag_spec.rb +24 -0
- data/spec/lib/tags/alias_tag_spec.rb +31 -0
- data/spec/lib/tags/author_tag_spec.rb +172 -0
- data/spec/lib/tags/base_tag_spec.rb +21 -0
- data/spec/lib/tags/beta_tag_spec.rb +52 -0
- data/spec/lib/tags/class_tag_spec.rb +29 -0
- data/spec/lib/tags/compatibility_tag_spec.rb +159 -0
- data/spec/lib/tags/demo_type_tag_spec.rb +24 -0
- data/spec/lib/tags/deprecated_tag_spec.rb +50 -0
- data/spec/lib/tags/description_tag_spec.rb +242 -0
- data/spec/lib/tags/example_tag_spec.rb +37 -0
- data/spec/lib/tags/factory_tag_spec.rb +29 -0
- data/spec/lib/tags/for_tag_spec.rb +45 -0
- data/spec/lib/tags/group_tag_spec.rb +20 -0
- data/spec/lib/tags/helper_tag_spec.rb +22 -0
- data/spec/lib/tags/include_with_tag_spec.rb +74 -0
- data/spec/lib/tags/javascript_action_tag_spec.rb +20 -0
- data/spec/lib/tags/link_tag_spec.rb +49 -0
- data/spec/lib/tags/markup_tag_spec.rb +255 -0
- data/spec/lib/tags/member_tag_spec.rb +167 -0
- data/spec/lib/tags/method_tag_spec.rb +27 -0
- data/spec/lib/tags/name_tag_spec.rb +20 -0
- data/spec/lib/tags/object_tag_spec.rb +24 -0
- data/spec/lib/tags/param_tag_spec.rb +261 -0
- data/spec/lib/tags/pattern_tag_spec.rb +49 -0
- data/spec/lib/tags/preclude_tag_spec.rb +31 -0
- data/spec/lib/tags/private_tag_spec.rb +31 -0
- data/spec/lib/tags/property_tag_spec.rb +27 -0
- data/spec/lib/tags/public_tag_spec.rb +29 -0
- data/spec/lib/tags/require_tag_spec.rb +133 -0
- data/spec/lib/tags/returns_tag_spec.rb +85 -0
- data/spec/lib/tags/set_by_tag_spec.rb +92 -0
- data/spec/lib/tags/signature_tag_spec.rb +125 -0
- data/spec/lib/tags/since_tag_spec.rb +48 -0
- data/spec/lib/tags/state_tag_spec.rb +199 -0
- data/spec/lib/tags/static_tag_spec.rb +27 -0
- data/spec/lib/tags/subcomponent_tag_spec.rb +78 -0
- data/spec/lib/tags/subtitle_tag_spec.rb +13 -0
- data/spec/lib/tags/symbol_type_tag_spec.rb +20 -0
- data/spec/lib/tags/throws_tag_spec.rb +49 -0
- data/spec/lib/tags/title_tag_spec.rb +20 -0
- data/spec/lib/tags/type_tag_spec.rb +20 -0
- data/spec/lib/tags/value_tag_spec.rb +20 -0
- data/spec/lib/tags/variant_tag_spec.rb +13 -0
- data/spec/lib/tags/variation_tag_spec.rb +154 -0
- data/spec/lib/tags_spec.rb +264 -0
- data/spec/lib/templates_spec.rb +185 -0
- data/spec/lib/themes_spec.rb +32 -0
- data/spec/spec_helper.rb +34 -0
- data/tasks/rspec.rake +7 -0
- data/tasks/rubocop.rake +8 -0
- metadata +740 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::NamingConventions::BEM do
|
|
4
|
+
subject { described_class.instance }
|
|
5
|
+
|
|
6
|
+
describe "#base_component" do
|
|
7
|
+
it "removes variation details" do
|
|
8
|
+
expect(subject.base_component("foo--bar")).to eq "foo"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "removes subcomponent details" do
|
|
12
|
+
expect(subject.base_component("foo__bar")).to eq "foo"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "removes variation and state details" do
|
|
16
|
+
expect(subject.base_component("foo--bar__baz--qux")).to eq "foo"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "#base_component?" do
|
|
21
|
+
it "identifies a base component name correctly" do
|
|
22
|
+
expect(subject.base_component?("foo")).to be true
|
|
23
|
+
expect(subject.base_component?("foo--bar")).to be false
|
|
24
|
+
expect(subject.base_component?("foo__bar")).to be false
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "#component" do
|
|
29
|
+
it "removes variation details" do
|
|
30
|
+
expect(subject.component("foo--bar")).to eq "foo"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "preserves subcomponents" do
|
|
34
|
+
expect(subject.component("foo__bar")).to eq "foo__bar"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "preserves the lowest subcomponent and strips all levels of variation" do
|
|
38
|
+
expect(subject.component("foo--bar__baz--qux__foo--bar")).to eq "foo__baz__foo"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe "#parent_component" do
|
|
43
|
+
it "goes one level up" do
|
|
44
|
+
expect(subject.parent_component("foo")).to eq "foo"
|
|
45
|
+
expect(subject.parent_component("foo__bar")).to eq "foo"
|
|
46
|
+
expect(subject.parent_component("foo__bar__baz")).to eq "foo__bar"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "strips away variations" do
|
|
50
|
+
expect(subject.parent_component("foo--bar")).to eq "foo"
|
|
51
|
+
expect(subject.parent_component("foo__bar--baz")).to eq "foo"
|
|
52
|
+
expect(subject.parent_component("foo--fuzz__bar--baz__quz")).to eq "foo__bar"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "state?" do
|
|
57
|
+
it "identifies disconnected states" do
|
|
58
|
+
expect(subject.state?("is-active")).to be true
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "identifies states connected to component names" do
|
|
62
|
+
expect(subject.state?("foo--is-active")).to be true
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "doesn't identify states when the component has is- in the name" do
|
|
66
|
+
expect(subject.state?("foois-bar")).to be false
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe "variant?" do
|
|
71
|
+
it "identifies variants" do
|
|
72
|
+
expect(subject.variant?("foo--bar")).to be true
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "doesn't identify a component" do
|
|
76
|
+
expect(subject.variant?("foo")).to be false
|
|
77
|
+
expect(subject.variant?("foo__bar")).to be false
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "doesn't identify variants when it is actually a connected state" do
|
|
81
|
+
expect(subject.variant?("foo--is-bar")).to be false
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe "#disconnected_state?" do
|
|
86
|
+
it "checks whether a state is not connected to the base class name" do
|
|
87
|
+
expect(subject.disconnected_state?("is-active")).to be true
|
|
88
|
+
expect(subject.disconnected_state?("component")).to be false
|
|
89
|
+
expect(subject.disconnected_state?("component--is-active")).to be false
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
describe "#clean_variation_name" do
|
|
94
|
+
it "doesn't prepend the base class name for disconnected states" do
|
|
95
|
+
expect(subject.clean_variation_name("is-active", "foo")).to eq "is-active"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "prepends the base class name and -- for non-disconnected-states" do
|
|
99
|
+
expect(subject.clean_variation_name("bar", "foo")).to eq "foo--bar"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "prepends the base class name for variations starting with --" do
|
|
103
|
+
expect(subject.clean_variation_name("--bar", "foo")).to eq "foo--bar"
|
|
104
|
+
expect(subject.clean_variation_name("--is-active", "foo")).to eq "foo--is-active"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "does nothing for fully-formed variations" do
|
|
108
|
+
expect(subject.clean_variation_name("foo--bar", "foo")).to eq "foo--bar"
|
|
109
|
+
expect(subject.clean_variation_name("foo--is-active", "foo")).to eq "foo--is-active"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::NamingConventions::SUIT do
|
|
4
|
+
subject { described_class.instance }
|
|
5
|
+
|
|
6
|
+
describe "#base_component" do
|
|
7
|
+
it "removes variation details" do
|
|
8
|
+
expect(subject.base_component("Foo--baz")).to eq "Foo"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "removes subcomponent details" do
|
|
12
|
+
expect(subject.base_component("Foo-baz")).to eq "Foo"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "removes variation and state details" do
|
|
16
|
+
expect(subject.base_component("Foo--bar")).to eq "Foo"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "#base_component?" do
|
|
21
|
+
it "identifies a base component name correctly" do
|
|
22
|
+
expect(subject.base_component?("Foo")).to be true
|
|
23
|
+
expect(subject.base_component?("Foo--bar")).to be false
|
|
24
|
+
expect(subject.base_component?("Foo-bar")).to be false
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "#component" do
|
|
29
|
+
it "removes variation details" do
|
|
30
|
+
expect(subject.component("Foo--bar")).to eq "Foo"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "preserves subcomponents" do
|
|
34
|
+
expect(subject.component("Foo-bar")).to eq "Foo-bar"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "#parent_component" do
|
|
39
|
+
it "goes one level up" do
|
|
40
|
+
expect(subject.parent_component("Foo")).to eq "Foo"
|
|
41
|
+
expect(subject.parent_component("Foo-bar")).to eq "Foo"
|
|
42
|
+
expect(subject.parent_component("Foo-bar-baz")).to eq "Foo-bar"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "strips away variations" do
|
|
46
|
+
expect(subject.parent_component("Foo--bar")).to eq "Foo"
|
|
47
|
+
expect(subject.parent_component("Foo-bar--baz")).to eq "Foo"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "state?" do
|
|
52
|
+
it "identifies disconnected states" do
|
|
53
|
+
expect(subject.state?("is-active")).to be true
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "identifies states connected to component names" do
|
|
57
|
+
expect(subject.state?("Foo--is-active")).to be true
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "doesn't identify states when the component has is- in the name" do
|
|
61
|
+
expect(subject.state?("Foois-bar")).to be false
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
describe "variant?" do
|
|
66
|
+
it "identifies variants" do
|
|
67
|
+
expect(subject.variant?("Foo--bar")).to be true
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "doesn't identify a component" do
|
|
71
|
+
expect(subject.variant?("Foo")).to be false
|
|
72
|
+
expect(subject.variant?("Foo-bar")).to be false
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "doesn't identify variants when it is actually a connected state" do
|
|
76
|
+
expect(subject.variant?("Foo--is-bar")).to be false
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe "#disconnected_state?" do
|
|
81
|
+
it "checks whether a state is not connected to the base class name" do
|
|
82
|
+
expect(subject.disconnected_state?("is-active")).to be true
|
|
83
|
+
expect(subject.disconnected_state?("Component")).to be false
|
|
84
|
+
expect(subject.disconnected_state?("Component--is-active")).to be false
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe "#clean_variation_name" do
|
|
89
|
+
it "doesn't prepend the base class name for disconnected states" do
|
|
90
|
+
expect(subject.clean_variation_name("is-active", "Foo")).to eq "is-active"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "prepends the base class name and -- for non-disconnected-states" do
|
|
94
|
+
expect(subject.clean_variation_name("bar", "Foo")).to eq "Foo--bar"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "prepends the base class name for variations starting with --" do
|
|
98
|
+
expect(subject.clean_variation_name("--bar", "Foo")).to eq "Foo--bar"
|
|
99
|
+
expect(subject.clean_variation_name("--is-active", "Foo")).to eq "Foo--is-active"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "does nothing for fully-formed variations" do
|
|
103
|
+
expect(subject.clean_variation_name("Foo--bar", "Foo")).to eq "Foo--bar"
|
|
104
|
+
expect(subject.clean_variation_name("Foo--is-active", "Foo")).to eq "Foo--is-active"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::NamingConventions do
|
|
4
|
+
subject { described_class }
|
|
5
|
+
let(:convention) { described_class::BEM }
|
|
6
|
+
|
|
7
|
+
describe ".for" do
|
|
8
|
+
it "gets the convention from a string" do
|
|
9
|
+
expect(described_class.for("BEM")).to be_a convention
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "gets the convention from a symbol" do
|
|
13
|
+
expect(described_class.for(:BEM)).to be_a convention
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "gets the convention from a class" do
|
|
17
|
+
expect(described_class.for(convention)).to be_a convention
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "gets the convention from an instance" do
|
|
21
|
+
expect(described_class.for(convention.instance)).to be_a convention
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "doesn't throw an error when it fails" do
|
|
25
|
+
expect { described_class.for(:FOO) }.not_to raise_error
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::OpenStruct do
|
|
4
|
+
let(:backing) do
|
|
5
|
+
{ foo: "bar" }
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
subject { described_class.new(backing) }
|
|
9
|
+
|
|
10
|
+
describe "as_json" do
|
|
11
|
+
it "directly returns its table as JSON" do
|
|
12
|
+
expect(subject.to_json).to eq backing.to_json
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::Parser do
|
|
4
|
+
subject { Docks::Parser }
|
|
5
|
+
|
|
6
|
+
around do |example|
|
|
7
|
+
Docks::Tags.register_bundled_tags
|
|
8
|
+
Docks::Languages.register_bundled_languages
|
|
9
|
+
example.run
|
|
10
|
+
subject.send(:clean)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe ".parse" do
|
|
14
|
+
let(:style_file) { File.expand_path("../../fixtures/parsers/sass_parser_fixture_basic.scss", __FILE__) }
|
|
15
|
+
let(:script_file) { File.expand_path("../../fixtures/parsers/coffeescript_parser_fixture_basic.coffee", __FILE__) }
|
|
16
|
+
let(:style_parser) { Docks::Parsers::Sass.instance }
|
|
17
|
+
let(:script_parser) { Docks::Parsers::CoffeeScript.instance }
|
|
18
|
+
|
|
19
|
+
it "returns a pattern" do
|
|
20
|
+
expect(subject.parse(style_file)).to be_a Docks::Containers::Pattern
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "parses the contents of each file" do
|
|
24
|
+
expect(style_parser).to receive(:parse).with(style_file).and_call_original
|
|
25
|
+
expect(script_parser).to receive(:parse).with(script_file).and_call_original
|
|
26
|
+
subject.parse([style_file, script_file])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "processes all parsed symbols and the final pattern" do
|
|
30
|
+
symbols = style_parser.parse(style_file) + script_parser.parse(script_file)
|
|
31
|
+
symbols.each { |symbol| expect(Docks::Process).to receive(:process).with(symbol) { |arg| arg } }
|
|
32
|
+
expect(Docks::Process).to receive(:process).with(an_instance_of(Docks::Containers::Pattern))
|
|
33
|
+
subject.parse([style_file, script_file])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "includes the parse result of a file in the appropriate group" do
|
|
37
|
+
expect(Docks::Process).to receive(:process).at_least(:once) { |arg| arg }
|
|
38
|
+
expect_any_instance_of(Docks::Containers::Pattern).to receive(:add).with(:style, style_parser.parse(style_file))
|
|
39
|
+
expect_any_instance_of(Docks::Containers::Pattern).to receive(:add).with(:script, script_parser.parse(script_file))
|
|
40
|
+
subject.parse([style_file, script_file])
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "uses a matching registered parser" do
|
|
44
|
+
class ExampleParser < Docks::Parsers::Base; end
|
|
45
|
+
subject.register(ExampleParser, for: /fixture/)
|
|
46
|
+
expect(ExampleParser.instance).to receive(:parse).with(style_file).and_return([])
|
|
47
|
+
subject.parse([style_file])
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "uses the last registered parser" do
|
|
51
|
+
class ExampleParser < Docks::Parsers::Base; end
|
|
52
|
+
class OtherParser < Docks::Parsers::Base; end
|
|
53
|
+
|
|
54
|
+
subject.register(ExampleParser, for: /fixture/)
|
|
55
|
+
subject.register(OtherParser, for: /parser/)
|
|
56
|
+
expect(OtherParser.instance).to receive(:parse).with(style_file).and_return([])
|
|
57
|
+
subject.parse([style_file])
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "doesn't use a parser that doesn't match the file" do
|
|
61
|
+
class ExampleParser < Docks::Parsers::Base; end
|
|
62
|
+
subject.register(ExampleParser, for: /script/)
|
|
63
|
+
expect(ExampleParser.instance).to_not receive(:parse)
|
|
64
|
+
subject.parse([style_file])
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "doesn't try to parse a file that doesn't exist" do
|
|
68
|
+
expect(File).to_not receive(:read).with("foo.bar")
|
|
69
|
+
subject.parse("foo.bar")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "doesn't try to parse a file that has no parser" do
|
|
73
|
+
File.open("foo.md", "w") { |file| file.write("foo bar") }
|
|
74
|
+
expect(subject).to_not receive(:parse_file).with("foo.md")
|
|
75
|
+
subject.parse("foo.md")
|
|
76
|
+
FileUtils.rm("foo.md")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "doesn't try to parse a file that doesn't have a supported extension" do
|
|
80
|
+
File.open("foo.bar", "w") { |file| file.write("foo bar") }
|
|
81
|
+
expect(File).to_not receive(:read).with("foo.bar")
|
|
82
|
+
subject.parse("foo.bar")
|
|
83
|
+
FileUtils.rm("foo.bar")
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "sets the most recently modified file's time to be the pattern's modified attribute" do
|
|
87
|
+
FileUtils.touch(script_file)
|
|
88
|
+
expected_modified = File.mtime(script_file)
|
|
89
|
+
pattern = subject.parse([style_file, script_file])
|
|
90
|
+
expect(pattern.modified).to eq expected_modified
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::Parsers::Base do
|
|
4
|
+
subject { Docks::Parsers::Base.instance }
|
|
5
|
+
|
|
6
|
+
before :each do
|
|
7
|
+
Docks::Tags.register_bundled_tags
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe "#parse" do
|
|
11
|
+
let(:example_parser) { Docks::Parsers::Sass.instance }
|
|
12
|
+
let(:example_files) do
|
|
13
|
+
[
|
|
14
|
+
File.expand_path("../../../fixtures/parsers/sass_parser_fixture_complex.scss", __FILE__),
|
|
15
|
+
File.expand_path("../../../fixtures/parsers/sass_parser_fixture_basic.scss", __FILE__)
|
|
16
|
+
]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "adds a source attribute to the symbol with source file" do
|
|
20
|
+
example_files.each do |file|
|
|
21
|
+
example_parser.parse(file).each do |symbol|
|
|
22
|
+
expect(symbol.source.file).to eq file
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "adds the language code of the file" do
|
|
28
|
+
example_files.each do |file|
|
|
29
|
+
example_parser.parse(file).each do |symbol|
|
|
30
|
+
expect(symbol.source.language_code).to eq Docks::Languages.extension_for_file(file)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "#pattern_block_extractor" do
|
|
37
|
+
it "doesn't break within the block when a sequence of characters matches the possible closing symbol" do
|
|
38
|
+
match = " //*\n // @pattern Foo\n\n // Don't **break** me here!\n\n\n//*\nBreak here".match(Docks::Parsers::Sass.instance.pattern_block_extractor)
|
|
39
|
+
expect(match[0]).to include "**break**"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "#parse_comment_block" do
|
|
44
|
+
it "adds a description when it is leading without a tag name" do
|
|
45
|
+
description = "This is\na description"
|
|
46
|
+
symbol = subject.parse_comment_block(description)
|
|
47
|
+
expect(symbol.description.join("\n")).to eq description
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "adds a normal tag to an array of results" do
|
|
51
|
+
title = "Next Tab"
|
|
52
|
+
symbol = subject.parse_comment_block(" @title #{title}")
|
|
53
|
+
expect(symbol.title).to eq title
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "adds a multiple-per-block tag to an array of arrays" do
|
|
57
|
+
param = "{String} name"
|
|
58
|
+
symbol = subject.parse_comment_block(" @param #{param}")
|
|
59
|
+
expect(symbol.param).to eq [[param]]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "adds a result even when there is no text content following the tag" do
|
|
63
|
+
symbol = subject.parse_comment_block(" @class")
|
|
64
|
+
expect(symbol[:class]).to eq ""
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "appends a second line of a normal tag to the same result array" do
|
|
68
|
+
line_one = "html"
|
|
69
|
+
line_two = " <p>Hello</p>"
|
|
70
|
+
symbol = subject.parse_comment_block(" @example #{line_one}\n#{line_two}")
|
|
71
|
+
example_result = symbol.example.first
|
|
72
|
+
expect(example_result.length).to eq 2
|
|
73
|
+
expect(example_result[0]).to eq line_one
|
|
74
|
+
expect(example_result[1]).to eq line_two
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "adds details for multiple tags" do
|
|
78
|
+
title = "Title"
|
|
79
|
+
subtitle = "Subtitle"
|
|
80
|
+
symbol = subject.parse_comment_block(" @title #{title}\n @subtitle #{subtitle}")
|
|
81
|
+
expect(symbol.title).to eq title
|
|
82
|
+
expect(symbol.subtitle).to eq subtitle
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "adds a new array to multiple_allowed tags when other tags are between the first and second ones" do
|
|
86
|
+
param_one = "{String} name - The\nname"
|
|
87
|
+
param_two = "{Number} count - The\ncount"
|
|
88
|
+
title = "Title"
|
|
89
|
+
subtitle = "Subtitle"
|
|
90
|
+
|
|
91
|
+
symbol = subject.parse_comment_block("@param #{param_one}\n@title #{title}\n@subtitle #{subtitle}\n@param #{param_two}")
|
|
92
|
+
expect(symbol.title).to eq title
|
|
93
|
+
expect(symbol.subtitle).to eq subtitle
|
|
94
|
+
expect(symbol.param).to include(param_one.split("\n"))
|
|
95
|
+
expect(symbol.param).to include(param_two.split("\n"))
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "keeps only the last instance of a one_per_file tag" do
|
|
99
|
+
pattern_one = "Buttons"
|
|
100
|
+
pattern_two = "No, wait, Forms!"
|
|
101
|
+
|
|
102
|
+
symbol = subject.parse_comment_block("@pattern #{pattern_one}\n@pattern #{pattern_two}")
|
|
103
|
+
expect(symbol.pattern).not_to eq pattern_one
|
|
104
|
+
expect(symbol.pattern).to eq pattern_two
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "does not include lines following non-multiline comments even if the following lines include no tag" do
|
|
108
|
+
pattern = "Button"
|
|
109
|
+
following_line = "Here is some more content"
|
|
110
|
+
|
|
111
|
+
symbol = subject.parse_comment_block("@pattern #{pattern}\n#{following_line}")
|
|
112
|
+
expect(symbol.pattern).to eq pattern
|
|
113
|
+
expect(symbol.description).to include(following_line)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "only removes one space after the tag name" do
|
|
117
|
+
pattern = "Button"
|
|
118
|
+
symbol = subject.parse_comment_block("@pattern #{pattern}")
|
|
119
|
+
expect(symbol.pattern).to eq " #{pattern}"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "preserves newlines in multiline tags" do
|
|
123
|
+
description = "This is\na description"
|
|
124
|
+
symbol = subject.parse_comment_block(description)
|
|
125
|
+
expect(symbol.description.join("\n")).to eq description
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Docks::Parsers::CoffeeScript do
|
|
4
|
+
subject { Docks::Parsers::CoffeeScript.instance }
|
|
5
|
+
|
|
6
|
+
before :each do
|
|
7
|
+
Docks::Tags.register_bundled_tags
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
let(:basic_fixture) { File.join(File.dirname(__FILE__), "..", "..", "fixtures", "parsers", "coffeescript_parser_fixture_basic.coffee") }
|
|
11
|
+
let(:complex_fixture) { File.join(File.dirname(__FILE__), "..", "..", "fixtures", "parsers", "coffeescript_parser_fixture_complex.coffee") }
|
|
12
|
+
|
|
13
|
+
describe "#parse" do
|
|
14
|
+
let(:basic_parsed_symbols) { subject.parse(basic_fixture) }
|
|
15
|
+
let(:complex_parsed_symbols) { subject.parse(complex_fixture) }
|
|
16
|
+
|
|
17
|
+
it "captures the correct number of documentation blocks" do
|
|
18
|
+
expect(basic_parsed_symbols.length).to eq 2
|
|
19
|
+
expect(complex_parsed_symbols.length).to eq 6
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "captures the pattern comment block when one exists" do
|
|
23
|
+
expect(basic_parsed_symbols.first[:pattern]).to be nil
|
|
24
|
+
expect(complex_parsed_symbols.first[:pattern]).to_not be nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "captures the pattern comment block when it is written using the page synonym" do
|
|
28
|
+
complex_parsed_symbols = subject.parse(File.read(complex_fixture).sub("@pattern", "@page"))
|
|
29
|
+
expect(complex_parsed_symbols.first[:page]).to_not be nil
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "adds line number for the first line following all other comment blocks" do
|
|
33
|
+
expected_line_numbers = [10, 20]
|
|
34
|
+
basic_parsed_symbols.each_with_index do |symbol, index|
|
|
35
|
+
expect(symbol.source.line_number).to be expected_line_numbers[index]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
expected_line_numbers = [3, 17, 38, 44, 52, 77]
|
|
39
|
+
complex_parsed_symbols.each_with_index do |symbol, index|
|
|
40
|
+
expect(symbol.source.line_number).to be expected_line_numbers[index]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe "#symbol_block_extractor" do
|
|
46
|
+
it "provides the first non-comment line as the second capture group" do
|
|
47
|
+
[
|
|
48
|
+
"_foo = 'bar'",
|
|
49
|
+
"$node = $(this)",
|
|
50
|
+
"bar = 'baz'"
|
|
51
|
+
].each do |non_comment|
|
|
52
|
+
match = " #*\n # Description\n\n #{non_comment}".match(subject.symbol_block_extractor)
|
|
53
|
+
expect(match[:first_line]).to eq non_comment
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe "#comment_line_pattern" do
|
|
59
|
+
let(:basic_comment) { "This is a comment" }
|
|
60
|
+
let(:complex_comment) { "# This comment has ##some extra comment-like symbols/characters #" }
|
|
61
|
+
|
|
62
|
+
it "strips line comments" do
|
|
63
|
+
expect("# #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "strips line comments with leading whitespace" do
|
|
67
|
+
expect(" # #{basic_comment}".gsub(subject.comment_line_pattern, "")).to eq basic_comment
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "strips line complex comments" do
|
|
71
|
+
expect("# #{complex_comment}".gsub(subject.comment_line_pattern, "")).to eq complex_comment
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "leaves empty lines intact" do
|
|
75
|
+
content = "# Foo\n#\n# 1. Bar\n\n# 2. Baz"
|
|
76
|
+
expect(content.gsub(subject.comment_line_pattern, "")).to eq "Foo\n\n1. Bar\n\n2. Baz"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe "#symbol_details_from_first_line" do
|
|
81
|
+
it "identifies a class" do
|
|
82
|
+
target_name = "Tab"
|
|
83
|
+
name, type = subject.symbol_details_from_first_line(" class #{target_name} ").values
|
|
84
|
+
expect(type).to eq Docks::Types::Symbol::CLASS
|
|
85
|
+
expect(name).to eq target_name
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe "functions" do
|
|
89
|
+
it "identifies a function with the single arrow" do
|
|
90
|
+
target_name = "activateTab"
|
|
91
|
+
name, type = subject.symbol_details_from_first_line("#{target_name} = ($tab) -> $tab.activate()").values
|
|
92
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
|
93
|
+
expect(name).to eq target_name
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "identifies a function with the fat arrow" do
|
|
97
|
+
target_name = "activateTab"
|
|
98
|
+
name, type = subject.symbol_details_from_first_line("#{target_name} = => $tab.activate()").values
|
|
99
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
|
100
|
+
expect(name).to eq target_name
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "identifies a function declared in a class definition" do
|
|
104
|
+
target_name = "activateTab"
|
|
105
|
+
name, type = subject.symbol_details_from_first_line(" #{target_name} : ($tab) -> $tab.activate()").values
|
|
106
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
|
107
|
+
expect(name).to eq target_name
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "identifies a function declared using dot notation" do
|
|
111
|
+
target_name = "activateTab"
|
|
112
|
+
|
|
113
|
+
name, type = subject.symbol_details_from_first_line(" foo.#{target_name} = ($tab) -> $tab.activate()").values
|
|
114
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
|
115
|
+
expect(name).to eq target_name
|
|
116
|
+
|
|
117
|
+
name, type = subject.symbol_details_from_first_line(" foo.bar.#{target_name} = ($tab) -> $tab.activate()").values
|
|
118
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
|
119
|
+
expect(name).to eq target_name
|
|
120
|
+
|
|
121
|
+
name, type = subject.symbol_details_from_first_line(" foo['bar'].#{target_name} = ($tab) -> $tab.activate()").values
|
|
122
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
|
123
|
+
expect(name).to eq target_name
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "identifies a function declared using bracket notation" do
|
|
127
|
+
target_name = "activateTab"
|
|
128
|
+
|
|
129
|
+
name, type = subject.symbol_details_from_first_line(" foo['#{target_name}'] = ($tab) -> $tab.activate()").values
|
|
130
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
|
131
|
+
expect(name).to eq target_name
|
|
132
|
+
|
|
133
|
+
name, type = subject.symbol_details_from_first_line(" foo[\"#{target_name}\"] = ($tab) -> $tab.activate()").values
|
|
134
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
|
135
|
+
expect(name).to eq target_name
|
|
136
|
+
|
|
137
|
+
name, type = subject.symbol_details_from_first_line(" foo['bar']['#{target_name}'] = ($tab) -> $tab.activate()").values
|
|
138
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
|
139
|
+
expect(name).to eq target_name
|
|
140
|
+
|
|
141
|
+
name, type = subject.symbol_details_from_first_line(" foo.bar['#{target_name}'] = ($tab) -> $tab.activate()").values
|
|
142
|
+
expect(type).to eq Docks::Types::Symbol::FUNCTION
|
|
143
|
+
expect(name).to eq target_name
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
describe "variables" do
|
|
148
|
+
it "identifies a variable" do
|
|
149
|
+
target_name = "newTab"
|
|
150
|
+
name, type = subject.symbol_details_from_first_line(" #{target_name} = @newTab()").values
|
|
151
|
+
expect(type).to eq Docks::Types::Symbol::VARIABLE
|
|
152
|
+
expect(name).to eq target_name
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it "identifies a variable declared in a class definition" do
|
|
156
|
+
target_name = "val"
|
|
157
|
+
name, type = subject.symbol_details_from_first_line(" #{target_name} : (2 * 3) / 4").values
|
|
158
|
+
expect(type).to eq Docks::Types::Symbol::VARIABLE
|
|
159
|
+
expect(name).to eq target_name
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "identifies a variable that is declared without assignment" do
|
|
163
|
+
target_name = "val"
|
|
164
|
+
name, type = subject.symbol_details_from_first_line(target_name).values
|
|
165
|
+
expect(type).to eq Docks::Types::Symbol::VARIABLE
|
|
166
|
+
expect(name).to eq target_name
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "identifies the first variable in a comma-separated list without assignment" do
|
|
170
|
+
target_name = "val"
|
|
171
|
+
name, type = subject.symbol_details_from_first_line(" #{target_name}, foo, bar , baz").values
|
|
172
|
+
expect(type).to eq Docks::Types::Symbol::VARIABLE
|
|
173
|
+
expect(name).to eq target_name
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it "identifies the first variable in a comma-separated list with assignment" do
|
|
177
|
+
target_name = "val"
|
|
178
|
+
name, type = subject.symbol_details_from_first_line(" #{target_name}, foo, bar , baz = 'qux'").values
|
|
179
|
+
expect(type).to eq Docks::Types::Symbol::VARIABLE
|
|
180
|
+
expect(name).to eq target_name
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|