'use strict' ; import * as assert from 'assert' ; import { Hover , TextDocument , getCSSLanguageService , getLESSLanguageService , getSCSSLanguageService } from '../../cssLanguageService' ; import { HoverSettings } from '../../cssLanguageTypes' ; function assertHover ( value , expected , languageId = 'css' , hoverSettings ? ) { let offset = value . indexOf ( '|' ) ; value = value . substr ( 0 , offset ) + value . substr ( offset + 1 ) ; const ls = languageId === 'css' ? getCSSLanguageService ( ) : languageId === 'less' ? getLESSLanguageService ( ) : getSCSSLanguageService ( ) ; const document = TextDocument . create ( `test://foo/bar.${ languageId }` , languageId , 1 , value ) ; const hoverResult = ls . doHover ( document , document . positionAt ( offset ) , ls . parseStylesheet ( document ) , hoverSettings ) ; assert ( hoverResult ) ; if ( hoverResult ! . range && expected . range ) { assert . equal ( hoverResult ! . range , expected . range ) ; } assert . deepEqual ( hoverResult ! . contents , expected . contents ) ; } suite ( 'CSS Hover' , ( ) => { test ( 'basic' , ( ) => { assertHover ( '.test { |color: blue; }' , { contents : { kind : 'markdown' , value : "Sets the color of an element's text\n\nSyntax: &lt;color&gt;\n\n[MDN Reference](https://developer.mozilla.org/docs/Web/CSS/color)" } } ) ; assertHover ( '.test { |color: blue; }' , { contents : { kind : 'markdown' , value : "[MDN Reference](https://developer.mozilla.org/docs/Web/CSS/color)" } } , undefined , { documentation : false } ) ; assertHover ( '.test { |color: blue; }' , { contents : { kind : 'markdown' , value : "Sets the color of an element's text\n\nSyntax: &lt;color&gt;" } } , undefined , { references : false } ) ; } ) ; test ( 'specificity' , ( ) => { assertHover ( '.|foo {}' , { contents : [ { language : 'html' , value : '<element class="foo">' } , '[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 1, 0)' ] } ) ; } ) ; } ) ; suite ( 'SCSS Hover' , ( ) => { test ( 'nested' , ( ) => { assertHover ( 'div { d|iv {} }' , { contents : [ { language : 'html' , value : '<div>\n  …\n    <div>' } , '[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 0, 1)' ] } , 'scss' ) ; } ) ; test ( '@at-root' , ( ) => { assertHover ( '.test { @|at-root { }' , { contents : [ ] } , 'scss' ) ; } ) ; } ) ;