1+ import { BorderStyle , Range } from "@cursorless/common" ;
12import * as assert from "assert" ;
2- import { generateDecorations } from "./calculateHighlights " ;
3- import type { Fixture , Scope } from "./types" ;
3+ import { flattenHighlights } from "./combineHighlightStyles " ;
4+ import type { Highlight , Scope } from "./types" ;
45
56interface Test {
67 name : string ;
@@ -16,7 +17,7 @@ const tests: Test[] = [
1617 targets : [ { content : "0:3-0:5" } , { content : "0:7-0:9" } ] ,
1718 } ,
1819 ] ,
19- expected : [ "0:3-0:5" , "0:7-0:9" ] ,
20+ expected : [ "0:3-0:5" , "0:5-0:7" , "0: 7-0:9"] ,
2021 } ,
2122 {
2223 name : "Adjacent targets" ,
@@ -34,7 +35,7 @@ const tests: Test[] = [
3435 targets : [ { content : "0:3-0:5" } , { content : "0:4-0:9" } ] ,
3536 } ,
3637 ] ,
37- expected : [ "0:3-0:5 " , "0:4-0:5" , "0:5-0:9" ] ,
38+ expected : [ "0:3-0:4 " , "0:4-0:5" , "0:5-0:9" ] ,
3839 } ,
3940 {
4041 name : "Domain == target" ,
@@ -54,7 +55,7 @@ const tests: Test[] = [
5455 targets : [ { content : "0:3-0:5" } ] ,
5556 } ,
5657 ] ,
57- expected : [ "0:3-0:5" , "0:3 -0:6" ] ,
58+ expected : [ "0:3-0:5" , "0:5 -0:6" ] ,
5859 } ,
5960 {
6061 name : "Target contains domain" ,
@@ -64,7 +65,7 @@ const tests: Test[] = [
6465 targets : [ { content : "0:3-0:6" } ] ,
6566 } ,
6667 ] ,
67- expected : [ "0:3-0:6 " , "0:3 -0:5 " ] ,
68+ expected : [ "0:3-0:5 " , "0:5 -0:6 " ] ,
6869 } ,
6970 {
7071 name : "Domain overlaps target" ,
@@ -74,26 +75,49 @@ const tests: Test[] = [
7475 targets : [ { content : "0:4-0:6" } ] ,
7576 } ,
7677 ] ,
77- expected : [ "0:4 -0:6" ] ,
78+ expected : [ "0:3-0:4" , "0:4-0:5" , "0:5 -0:6"] ,
7879 } ,
7980] ;
8081
81- suite ( "calculate highlights" , ( ) => {
82+ suite ( "flatten highlights" , ( ) => {
8283 tests . forEach ( ( t ) => {
83- const fixture : Fixture = {
84- name : t . name ,
85- scopes : t . scopes ,
86- facet : "line" ,
87- languageId : "plaintext" ,
88- code : "" ,
89- } ;
90- test ( fixture . name , ( ) => {
91- const decorations = generateDecorations ( fixture , "content" ) ?? [ ] ;
92- assert . equal ( decorations . length , t . expected . length ) ;
93- // TODO: decorations test
94- // for (let i = 0; i < decorations .length; i++) {
95- // assert.equal(decorations [i].range.concise(), t.expected[i]);
96- // }
84+ const highlights = t . scopes . flatMap ( ( s ) => {
85+ const result : Highlight [ ] = [ ] ;
86+ if ( s . domain ) {
87+ result . push ( createHighlight ( s . domain ) ) ;
88+ }
89+ result . push ( ... s . targets . map ( ( t ) => createHighlight ( t . content ) ) ) ;
90+ return result ;
91+ } ) ;
92+ test ( t . name , ( ) => {
93+ const actual = flattenHighlights ( highlights ) ;
94+ assert . equal ( actual . length , t . expected . length ) ;
95+ for ( let i = 0 ; i < actual . length ; i ++ ) {
96+ assert . equal ( actual [ i ] . range . concise ( ) , t . expected [ i ] ) ;
97+ }
9798 } ) ;
9899 } ) ;
99100} ) ;
101+
102+ function createHighlight ( range : string ) : Highlight {
103+ return {
104+ range : Range . fromConcise ( range ) ,
105+ style : {
106+ backgroundColor : "black" ,
107+ borderColorSolid : "red" ,
108+ borderColorPorous : "pink" ,
109+ borderRadius : {
110+ topLeft : false ,
111+ topRight : false ,
112+ bottomLeft : false ,
113+ bottomRight : false ,
114+ } ,
115+ borderStyle : {
116+ top : BorderStyle . none ,
117+ bottom : BorderStyle . none ,
118+ left : BorderStyle . none ,
119+ right : BorderStyle . none ,
120+ } ,
121+ } ,
122+ } ;
123+ }
0 commit comments