def test_min_score(self): self.assertEqual(expand('auto', Config({ 'type': 'stylesheet', 'options': { 'stylesheet.fuzzySearchMinScore': 0 } })), 'align-self: unset;') self.assertEqual(expand('auto', Config({ 'type': 'stylesheet', 'options': { 'stylesheet.fuzzySearchMinScore': 0.3 } })), 'auto: ;')
def test_resolve_context_value(self): config = Config({ 'type': 'stylesheet', 'context': { 'name': 'align-content' } }) self.assertEqual(expand('s', config), 'start') self.assertEqual(expand('a', config), 'auto')
def test_css_in_js(self): config = Config({ 'type': 'stylesheet', 'options': { 'stylesheet.json': True, 'stylesheet.between': ': ' } }) self.assertEqual(expand('p10+mt10-20', config), 'padding: 10,\nmarginTop: \'10px 20px\',')
def test_limit_snippets_by_scope(self): section_scope = Config({ 'type': 'stylesheet', 'context': { 'name': CSSAbbreviationScope.Section }, 'snippets': { 'mten': 'margin: 10px;', 'fsz': 'font-size', 'myCenterAwesome': 'body {\n\tdisplay: grid;\n}' } }) property_scope = Config({ 'type': 'stylesheet', 'context': { 'name': CSSAbbreviationScope.Property }, 'snippets': { 'mten': 'margin: 10px;', 'fsz': 'font-size', 'myCenterAwesome': 'body {\n\tdisplay: grid;\n}' } }) self.assertEqual(expand('m', section_scope), 'body {\n\tdisplay: grid;\n}') self.assertEqual(expand('b', section_scope), '') self.assertEqual(expand('m', property_scope), 'margin: ;')
def test_numeric_with_format(self): config = Config({ 'type': 'stylesheet', 'options': { 'stylesheet.intUnit': 'pt', 'stylesheet.floatUnit': 'vh', 'stylesheet.unitAliases': { 'e': 'em', 'p': '%', 'x': 'ex', 'r': ' / @rem' } } }) self.assertEqual(expand('p0', config), 'padding: 0;', 'No unit for 0') self.assertEqual(expand('p10', config), 'padding: 10pt;', '`pt` unit for integers') self.assertEqual(expand('p.4', config), 'padding: 0.4vh;', '`vh` for floats') self.assertEqual(expand('p10p', config), 'padding: 10%;', 'unit alias') self.assertEqual(expand('z10', config), 'z-index: 10;', 'Unitless property') self.assertEqual(expand('p10r', config), 'padding: 10 / @rem;', 'unit alias')
sys.path.append('../') from emmet import expand_stylesheet, parse_stylesheet_snippets, Config from emmet.stylesheet.score import calculate_score as score def field(index: int, placeholder: str, **kwargs): if placeholder: return '${%d:%s}' % (index, placeholder) return '${%d}' % index default_config = Config({ 'type': 'stylesheet', 'options': { 'output.field': field }, 'snippets': { 'mten': 'margin: 10px;', 'fsz': 'font-size' }, 'cache': {} }) def expand(abbr: str, config=default_config): return expand_stylesheet(abbr, config) def pick(abbr: str, items: list): items = map(lambda item: { 'item': item, 'score': score(abbr, item) }, items) items = list(filter(lambda item: item['score'] > 0, items)) items.sort(key=lambda item: item['score'], reverse=True)