diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/__init__.py | 0 | ||||
| -rw-r--r-- | tests/fixtures/comments.txt | 33 | ||||
| -rw-r--r-- | tests/fixtures/css/buttons.css | 38 | ||||
| -rw-r--r-- | tests/fixtures/less/_label.less | 10 | ||||
| -rw-r--r-- | tests/fixtures/less/buttons.less | 51 | ||||
| -rw-r--r-- | tests/fixtures/less/mixins.less | 8 | ||||
| -rw-r--r-- | tests/fixtures/less/nested.less | 17 | ||||
| -rw-r--r-- | tests/fixtures/sass/buttons.sass | 40 | ||||
| -rw-r--r-- | tests/fixtures/sass/nested.sass | 10 | ||||
| -rw-r--r-- | tests/fixtures/scss/buttons.scss | 47 | ||||
| -rw-r--r-- | tests/fixtures/scss/nested.scss | 12 | ||||
| -rw-r--r-- | tests/test_comment.py | 65 | ||||
| -rw-r--r-- | tests/test_modifier.py | 15 | ||||
| -rw-r--r-- | tests/test_parser.py | 48 | ||||
| -rw-r--r-- | tests/test_section.py | 36 |
15 files changed, 430 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/__init__.py diff --git a/tests/fixtures/comments.txt b/tests/fixtures/comments.txt new file mode 100644 index 0000000..37dcdf6 --- /dev/null +++ b/tests/fixtures/comments.txt @@ -0,0 +1,33 @@ +This file is used for generic comment parsing across CSS, SCSS, SASS & LESS. + +There's single-line comment styles: + +// This comment block has comment identifiers on every line. +// +// Fun fact: this is Kyle's favorite comment syntax! + + +There's block comment styles: + +/* This comment block is a block-style comment syntax. + +There's only two identifier across multiple lines. */ + +/* This is another common multi-line comment style. + * + * It has stars at the begining of every line. + */ + + +Some people do crazy things like mix comment styles: + +// This comment has a /* comment */ identifier inside of it! + +/* Look at my //cool// comment art! */ + + +Indented comments: + + // Indented single-line comment. + + /* Indented block comment. */
\ No newline at end of file diff --git a/tests/fixtures/css/buttons.css b/tests/fixtures/css/buttons.css new file mode 100644 index 0000000..575f934 --- /dev/null +++ b/tests/fixtures/css/buttons.css @@ -0,0 +1,38 @@ +/* +Your standard form button. + +:hover - Highlights when hovering. +:disabled - Dims the button when disabled. +.primary - Indicates button is the primary action. +.smaller - A little bit smaller now. + +Styleguide 2.1.1. +*/ +button { + padding: 5px 15px; } + button.primary, button.primary:hover { + color: #fff; } + button.smaller { + font-size: 11px; } + button:hover { + color: #337797; } + button:disabled { + opacity: 0.5; } + + +/* +A button suitable for giving stars to someone. + +.star-given - A highlight indicating you've already given a star. +.disabled - Dims the button to indicate it cannot be used. + +Styleguide 2.2.1. +*/ +a.button.star { + display: inline-block; } + a.button.star .star { + font-size: 10px; } + a.button.star.star-given { + color: #ae7e00; } + a.button.star.disabled { + opacity: 0.5; }
\ No newline at end of file diff --git a/tests/fixtures/less/_label.less b/tests/fixtures/less/_label.less new file mode 100644 index 0000000..43c13a4 --- /dev/null +++ b/tests/fixtures/less/_label.less @@ -0,0 +1,10 @@ +/* +A default form label + +Styleguide 5.0.0 +*/ +label { + display: block; + float: left; + width: 150px; +}
\ No newline at end of file diff --git a/tests/fixtures/less/buttons.less b/tests/fixtures/less/buttons.less new file mode 100644 index 0000000..afc58ac --- /dev/null +++ b/tests/fixtures/less/buttons.less @@ -0,0 +1,51 @@ +/* +Your standard form button. + +:hover - Highlights when hovering. +:disabled - Dims the button when disabled. +.primary - Indicates button is the primary action. +.smaller - A little bit smaller now. + +Styleguide 2.1.1. +*/ +button, .button { + padding:5px 15px; + + &.primary, &.primary:hover{ + color:#fff; + } + + &.smaller{ + font-size:9px; + } + + &:hover{ + color:#337797; + } + + &:disabled{ + opacity:0.5; + } +} + +/* +A button suitable for giving stars to someone. + +.star-given - A highlight indicating you've already given a star. +.disabled - Dims the button to indicate it cannot be used. + +Styleguide 2.2.1. +*/ +a.button.star{ + display:inline-block; + + .star{ font-size:10px; } + + &.star-given{ + color:#ae7e00; + } + + &.disabled{ + opacity:0.5; + } +}
\ No newline at end of file diff --git a/tests/fixtures/less/mixins.less b/tests/fixtures/less/mixins.less new file mode 100644 index 0000000..87b5272 --- /dev/null +++ b/tests/fixtures/less/mixins.less @@ -0,0 +1,8 @@ +/* +Your standard grid helper. + +Styleguide 4.0.0. +*/ +.grid(@columns, @max: 10) { + width: (@columns / @max) * 960px; +}
\ No newline at end of file diff --git a/tests/fixtures/less/nested.less b/tests/fixtures/less/nested.less new file mode 100644 index 0000000..3eea176 --- /dev/null +++ b/tests/fixtures/less/nested.less @@ -0,0 +1,17 @@ +@import "_label"; +/* +Your standard form element. + +Styleguide 3.0.0 +*/ +form { + + /* + Your standard text input box. + + Styleguide 3.0.1 + */ + input[type="text"] { + border: 1px solid #ccc; + } +}
\ No newline at end of file diff --git a/tests/fixtures/sass/buttons.sass b/tests/fixtures/sass/buttons.sass new file mode 100644 index 0000000..2a8bcdf --- /dev/null +++ b/tests/fixtures/sass/buttons.sass @@ -0,0 +1,40 @@ +/* Your standard form button. + * + * :hover - Highlights when hovering. + * :disabled - Dims the button when disabled. + * .primary - Indicates button is the primary action. + * .smaller - A little bit smaller now. + * + * Styleguide 2.1.1. */ +button + padding: 5px 15px + + &.primary, &.primary:hover + color: #fff + + &.smaller + font-size: 11px + + &:hover + color: #337797 + + &:disabled + opacity: 0.5 + +// A button suitable for giving stars to someone. +// +// .star-given - A highlight indicating you've already given a star. +// .disabled - Dims the button to indicate it cannot be used. +// +// Styleguide 2.2.1. +a.button.star + display: inline-block + + .star + font-size: 10px + + &.star-given + color: #ae7e00 + + &.disabled + opacity: 0.5
\ No newline at end of file diff --git a/tests/fixtures/sass/nested.sass b/tests/fixtures/sass/nested.sass new file mode 100644 index 0000000..ae0309e --- /dev/null +++ b/tests/fixtures/sass/nested.sass @@ -0,0 +1,10 @@ +/* Your standard form element. + * + * Styleguide 3.0.0 */ +form + + /* Your standard text input box. + * + * Styleguide 3.0.1 */ + input[type="text"] + border: 1px solid #ccc
\ No newline at end of file diff --git a/tests/fixtures/scss/buttons.scss b/tests/fixtures/scss/buttons.scss new file mode 100644 index 0000000..efa3bb1 --- /dev/null +++ b/tests/fixtures/scss/buttons.scss @@ -0,0 +1,47 @@ +// Your standard form button. +// +// :hover - Highlights when hovering. +// :disabled - Dims the button when disabled. +// .primary - Indicates button is the primary action. +// .smaller - A little bit smaller now. +// +// Styleguide 2.1.1. +button{ + padding:5px 15px; + + &.primary, &.primary:hover{ + color:#fff; + } + + &.smaller{ + font-size:11px; + } + + &:hover{ + color:#337797; + } + + &:disabled{ + opacity:0.5; + } +} + +// A button suitable for giving stars to someone. +// +// .star-given - A highlight indicating you've already given a star. +// .disabled - Dims the button to indicate it cannot be used. +// +// Styleguide 2.2.1. +a.button.star{ + display:inline-block; + + .star{ font-size:10px; } + + &.star-given{ + color:#ae7e00; + } + + &.disabled{ + opacity:0.5; + } +}
\ No newline at end of file diff --git a/tests/fixtures/scss/nested.scss b/tests/fixtures/scss/nested.scss new file mode 100644 index 0000000..2e51c2b --- /dev/null +++ b/tests/fixtures/scss/nested.scss @@ -0,0 +1,12 @@ +// Your standard form element. +// +// Styleguide 3.0.0 +form { + + // Your standard text input box. + // + // Styleguide 3.0.1 + input[type="text"] { + border: 1px solid #ccc; + } +}
\ No newline at end of file diff --git a/tests/test_comment.py b/tests/test_comment.py new file mode 100644 index 0000000..ea47156 --- /dev/null +++ b/tests/test_comment.py @@ -0,0 +1,65 @@ +import os +import unittest + +from pykss import comment + + +class CommentMethodTestCase(unittest.TestCase): + + def test_detects_single_line_comment_syntax(self): + self.assertTrue(comment.is_single_line_comment('// yuuuuup')) + self.assertFalse(comment.is_single_line_comment('nooooope')) + + def test_detects_start_of_multi_line_comment_syntax(self): + self.assertTrue(comment.is_multi_line_comment_start('/* yuuuuup')) + self.assertFalse(comment.is_multi_line_comment_start('nooooope')) + + def test_detects_end_of_multi_line_comment_syntax(self): + self.assertTrue(comment.is_multi_line_comment_end(" yuuuuup */")) + self.assertFalse(comment.is_multi_line_comment_end("nooooope")) + + def test_parses_the_single_line_comment_syntax(self): + self.assertEqual(comment.parse_single_line("// yuuuuup"), 'yuuuuup') + + def test_parses_the_multi_line_comment_syntax(self): + self.assertEqual(comment.parse_multi_line('/* yuuuup */'), 'yuuuup') + + +class CommentParserTestCase(unittest.TestCase): + + def setUp(self): + text = os.path.join(os.path.dirname(__file__), 'fixtures', 'comments.txt') + self.comments = comment.CommentParser(text).blocks + + def test_finds_single_line_comment_styles(self): + expected = """ +This comment block has comment identifiers on every line. + +Fun fact: this is Kyle's favorite comment syntax!""" + self.assertTrue(expected.strip() in self.comments) + + def test_finds_block_style_comment_styles(self): + expected = """ +This comment block is a block-style comment syntax. + +There's only two identifier across multiple lines. + """ + self.assertTrue(expected.strip() in self.comments) + + expected = """ +This is another common multi-line comment style. + +It has stars at the begining of every line. + """ + self.assertTrue(expected.strip() in self.comments) + + def test_handles_mixed_styles(self): + expected = "This comment has a /* comment */ identifier inside of it!" + self.assertTrue(expected.strip() in self.comments) + + expected = 'Look at my //cool// comment art!' + self.assertTrue(expected.strip() in self.comments) + + def test_handles_indented_comments(self): + self.assertTrue('Indented single-line comment.' in self.comments) + self.assertTrue('Indented block comment.' in self.comments) diff --git a/tests/test_modifier.py b/tests/test_modifier.py new file mode 100644 index 0000000..1e109d8 --- /dev/null +++ b/tests/test_modifier.py @@ -0,0 +1,15 @@ +import unittest + +from pykss.modifier import Modifier + + +class ModiferTestCase(unittest.TestCase): + + def setUp(self): + self.modifier = Modifier('.callout.extreme:hover', 'calls things out') + + def test_handles_pseudo(self): + self.assertTrue('pseudo-class-hover' in self.modifier.class_name) + + def test_handles_multiple_classes(self): + self.assertTrue('callout extreme' in self.modifier.class_name) diff --git a/tests/test_parser.py b/tests/test_parser.py new file mode 100644 index 0000000..1471160 --- /dev/null +++ b/tests/test_parser.py @@ -0,0 +1,48 @@ +import os +import unittest + +import pykss + + +class ParseTestCase(unittest.TestCase): + + def setUp(self): + fixtures = os.path.join(os.path.dirname(__file__), 'fixtures') + self.scss = pykss.Parser(os.path.join(fixtures, 'scss')) + self.less = pykss.Parser(os.path.join(fixtures, 'less')) + self.sass = pykss.Parser(os.path.join(fixtures, 'sass')) + self.css = pykss.Parser(os.path.join(fixtures, 'css')) + self.multiple = pykss.Parser(os.path.join(fixtures, 'scss'), os.path.join(fixtures, 'less')) + + def test_parses_kss_comments_in_scss(self): + self.assertEqual(self.scss.section('2.1.1').description, 'Your standard form button.') + + def test_parses_kss_comments_in_less(self): + self.assertEqual(self.less.section('2.1.1').description, 'Your standard form button.') + + def test_parses_kss_multi_line_comments_in_sass(self): + self.assertEqual(self.sass.section('2.1.1').description, 'Your standard form button.') + + def test_parses_kss_single_line_comments_in_sass(self): + self.assertEqual(self.sass.section('2.2.1').description, 'A button suitable for giving stars to someone.') + + def test_parses_kss_comments_in_css(self): + self.assertEqual(self.css.section('2.1.1').description, 'Your standard form button.') + + def test_parses_nested_scss_documents(self): + self.assertEqual(self.scss.section('3.0.0').description, 'Your standard form element.') + self.assertEqual(self.scss.section('3.0.1').description, 'Your standard text input box.') + + def test_parses_nested_less_documents(self): + self.assertEqual(self.less.section('3.0.0').description, 'Your standard form element.') + self.assertEqual(self.less.section('3.0.1').description, 'Your standard text input box.') + + def test_parses_nested_sass_documents(self): + self.assertEqual(self.sass.section('3.0.0').description, 'Your standard form element.') + self.assertEqual(self.sass.section('3.0.1').description, 'Your standard text input box.') + + def test_parse_returns_dictionary_of_sections(self): + self.assertEqual(len(self.css.sections), 2) + + def test_parse_multiple_paths(self): + self.assertEqual(len(self.multiple.sections), 6) diff --git a/tests/test_section.py b/tests/test_section.py new file mode 100644 index 0000000..7ba8496 --- /dev/null +++ b/tests/test_section.py @@ -0,0 +1,36 @@ +import unittest + +from pykss.section import Section + + +class SectionTestCase(unittest.TestCase): + + def setUp(self): + comment = """ +# Form Button + +Your standard form button. + +:hover - Highlights when hovering. +:disabled - Dims the button when disabled. +.primary - Indicates button is the primary action. +.smaller - A smaller button + +Styleguide 2.1.1. + """ + self.section = Section(comment.strip(), 'example.css') + + def test_parses_the_description(self): + self.assertEqual(self.section.description, '# Form Button\n\nYour standard form button.') + + def test_parses_the_modifiers(self): + self.assertEqual(len(self.section.modifiers), 4) + + def test_parses_modifier_names(self): + self.assertEqual(self.section.modifiers[0].name, ':hover') + + def test_parses_modifier_descriptions(self): + self.assertEqual(self.section.modifiers[0].description, 'Highlights when hovering.') + + def test_parses_the_styleguide_reference(self): + self.assertEqual(self.section.section, '2.1.1') |
