1- package main
1+ package builder
22
33import (
44 "encoding/json"
55 "os"
66 "path/filepath"
77 "testing"
8+
9+ "github.com/rose-pine/rose-pine-bloom/color"
10+ "github.com/rose-pine/rose-pine-bloom/config"
811)
912
1013func setupTest (t * testing.T ) (string , func ()) {
@@ -15,7 +18,7 @@ func setupTest(t *testing.T) (string, func()) {
1518 return tmpDir , func () { os .RemoveAll (tmpDir ) }
1619}
1720
18- func buildFromTemplate (t * testing.T , template string , cfg * Config ) {
21+ func buildFromTemplate (t * testing.T , template string , cfg * config. Config ) {
1922 templatePath := filepath .Join (cfg .Output , "template.json" )
2023 if err := os .WriteFile (templatePath , []byte (template ), 0644 ); err != nil {
2124 t .Fatal (err )
@@ -49,7 +52,7 @@ func assertJSONField(t *testing.T, result map[string]any, field, want string) {
4952}
5053
5154// testConfig provides standard config
52- var testConfig = Config {
55+ var testConfig = config. Config {
5356 Template : "" ,
5457 Output : "" ,
5558 Prefix : "$" ,
@@ -60,9 +63,9 @@ var testConfig = Config{
6063}
6164
6265// testColor provides a standard color
63- var testColor = & Color {
64- HSL : hsl ( 2 , 55 , 83 ) ,
65- RGB : rgb ( 235 , 188 , 186 ) ,
66+ var testColor = & color. Color {
67+ HSL : color. HSL { 2 , 55 , 83 } ,
68+ RGB : color. RGB { 235 , 188 , 186 } ,
6669}
6770
6871// testTemplate provides a standard template
@@ -118,51 +121,51 @@ func TestColorFormatting(t *testing.T) {
118121
119122 tests := []struct {
120123 name string
121- format ColorFormat
124+ format color. ColorFormat
122125 plain bool
123126 commas bool
124127 spaces bool
125128 want string
126129 }{
127- {"hex" , FormatHex , false , true , true , "#ebbcba" },
128- {"hex plain" , FormatHex , true , true , true , "ebbcba" },
129-
130- {"hsl" , FormatHSL , false , true , true , "hsl(2, 55%, 83%)" },
131- {"hsl no-commas" , FormatHSL , false , false , true , "hsl(2 55% 83%)" },
132- {"hsl no-spaces" , FormatHSL , false , true , false , "hsl(2,55%,83%)" },
133- {"hsl plain" , FormatHSL , true , true , true , "2, 55%, 83%" },
134- {"hsl plain no-commas" , FormatHSL , true , false , true , "2 55% 83%" },
135- {"hsl plain no-spaces" , FormatHSL , true , true , false , "2,55%,83%" },
136-
137- {"hsl-array" , FormatHSLArray , false , true , true , "[2, 0.55, 0.83]" },
138- {"hsl-array plain" , FormatHSLArray , true , true , true , "2, 0.55, 0.83" },
139- {"hsl-array no-commas" , FormatHSLArray , false , false , true , "[2 0.55 0.83]" },
140- {"hsl-array no-spaces" , FormatHSLArray , false , true , false , "[2,0.55,0.83]" },
141-
142- {"hsl-css" , FormatHSLCSS , false , true , true , "hsl(2deg 55% 83%)" },
143- {"hsl-css plain" , FormatHSLCSS , true , true , true , "2deg 55% 83%" },
144-
145- {"rgb" , FormatRGB , false , true , true , "rgb(235, 188, 186)" },
146- {"rgb no-commas" , FormatRGB , false , false , true , "rgb(235 188 186)" },
147- {"rgb no-spaces" , FormatRGB , false , true , false , "rgb(235,188,186)" },
148- {"rgb plain" , FormatRGB , true , true , true , "235, 188, 186" },
149- {"rgb plain no-commas" , FormatRGB , true , false , true , "235 188 186" },
150- {"rgb plain no-spaces" , FormatRGB , true , true , false , "235,188,186" },
151-
152- {"rgb-array" , FormatRGBArray , false , true , true , "[235, 188, 186]" },
153- {"rgb-array plain" , FormatRGBArray , true , true , true , "235, 188, 186" },
154- {"rgb-array no-commas" , FormatRGBArray , false , false , true , "[235 188 186]" },
155- {"rgb-array no-spaces" , FormatRGBArray , false , true , false , "[235,188,186]" },
156-
157- {"rgb-css" , FormatRGBCSS , false , true , true , "rgb(235 188 186)" },
158- {"rgb-css plain" , FormatRGBCSS , true , true , true , "235 188 186" },
159-
160- {"ansi" , FormatAnsi , false , true , true , "235;188;186" },
130+ {"hex" , color . FormatHex , false , true , true , "#ebbcba" },
131+ {"hex plain" , color . FormatHex , true , true , true , "ebbcba" },
132+
133+ {"hsl" , color . FormatHSL , false , true , true , "hsl(2, 55%, 83%)" },
134+ {"hsl no-commas" , color . FormatHSL , false , false , true , "hsl(2 55% 83%)" },
135+ {"hsl no-spaces" , color . FormatHSL , false , true , false , "hsl(2,55%,83%)" },
136+ {"hsl plain" , color . FormatHSL , true , true , true , "2, 55%, 83%" },
137+ {"hsl plain no-commas" , color . FormatHSL , true , false , true , "2 55% 83%" },
138+ {"hsl plain no-spaces" , color . FormatHSL , true , true , false , "2,55%,83%" },
139+
140+ {"hsl-array" , color . FormatHSLArray , false , true , true , "[2, 0.55, 0.83]" },
141+ {"hsl-array plain" , color . FormatHSLArray , true , true , true , "2, 0.55, 0.83" },
142+ {"hsl-array no-commas" , color . FormatHSLArray , false , false , true , "[2 0.55 0.83]" },
143+ {"hsl-array no-spaces" , color . FormatHSLArray , false , true , false , "[2,0.55,0.83]" },
144+
145+ {"hsl-css" , color . FormatHSLCSS , false , true , true , "hsl(2deg 55% 83%)" },
146+ {"hsl-css plain" , color . FormatHSLCSS , true , true , true , "2deg 55% 83%" },
147+
148+ {"rgb" , color . FormatRGB , false , true , true , "rgb(235, 188, 186)" },
149+ {"rgb no-commas" , color . FormatRGB , false , false , true , "rgb(235 188 186)" },
150+ {"rgb no-spaces" , color . FormatRGB , false , true , false , "rgb(235,188,186)" },
151+ {"rgb plain" , color . FormatRGB , true , true , true , "235, 188, 186" },
152+ {"rgb plain no-commas" , color . FormatRGB , true , false , true , "235 188 186" },
153+ {"rgb plain no-spaces" , color . FormatRGB , true , true , false , "235,188,186" },
154+
155+ {"rgb-array" , color . FormatRGBArray , false , true , true , "[235, 188, 186]" },
156+ {"rgb-array plain" , color . FormatRGBArray , true , true , true , "235, 188, 186" },
157+ {"rgb-array no-commas" , color . FormatRGBArray , false , false , true , "[235 188 186]" },
158+ {"rgb-array no-spaces" , color . FormatRGBArray , false , true , false , "[235,188,186]" },
159+
160+ {"rgb-css" , color . FormatRGBCSS , false , true , true , "rgb(235 188 186)" },
161+ {"rgb-css plain" , color . FormatRGBCSS , true , true , true , "235 188 186" },
162+
163+ {"ansi" , color . FormatAnsi , false , true , true , "235;188;186" },
161164 }
162165
163166 for _ , tt := range tests {
164167 t .Run (tt .name , func (t * testing.T ) {
165- got := formatColor (testColor , tt .format , tt .plain , tt .commas , tt .spaces )
168+ got := color . FormatColor (testColor , tt .format , tt .plain , tt .commas , tt .spaces )
166169 if got != tt .want {
167170 t .Errorf ("formatColor() = %v, want %v" , got , tt .want )
168171 }
@@ -172,45 +175,45 @@ func TestColorFormatting(t *testing.T) {
172175
173176func TestAlphaFormatting (t * testing.T ) {
174177 alpha := 0.5
175- color := & Color {
178+ c := & color. Color {
176179 HSL : testColor .HSL ,
177180 RGB : testColor .RGB ,
178181 Alpha : & alpha ,
179182 }
180183
181184 tests := []struct {
182185 name string
183- format ColorFormat
186+ format color. ColorFormat
184187 plain bool
185188 want string
186189 }{
187- {"hex" , FormatHex , false , "#ebbcba80" },
188- {"hex plain" , FormatHex , true , "ebbcba80" },
190+ {"hex" , color . FormatHex , false , "#ebbcba80" },
191+ {"hex plain" , color . FormatHex , true , "ebbcba80" },
189192
190- {"hsl" , FormatHSL , false , "hsla(2, 55%, 83%, 0.5)" },
191- {"hsl plain" , FormatHSL , true , "2, 55%, 83%, 0.5" },
193+ {"hsl" , color . FormatHSL , false , "hsla(2, 55%, 83%, 0.5)" },
194+ {"hsl plain" , color . FormatHSL , true , "2, 55%, 83%, 0.5" },
192195
193- {"hsl-css" , FormatHSLCSS , false , "hsl(2deg 55% 83% / 0.5)" },
194- {"hsl-css plain" , FormatHSLCSS , true , "2deg 55% 83% / 0.5" },
196+ {"hsl-css" , color . FormatHSLCSS , false , "hsl(2deg 55% 83% / 0.5)" },
197+ {"hsl-css plain" , color . FormatHSLCSS , true , "2deg 55% 83% / 0.5" },
195198
196- {"hsl-array" , FormatHSLArray , false , "[2, 0.55, 0.83, 0.5]" },
197- {"hsl-array plain" , FormatHSLArray , true , "2, 0.55, 0.83, 0.5" },
199+ {"hsl-array" , color . FormatHSLArray , false , "[2, 0.55, 0.83, 0.5]" },
200+ {"hsl-array plain" , color . FormatHSLArray , true , "2, 0.55, 0.83, 0.5" },
198201
199- {"rgb" , FormatRGB , false , "rgba(235, 188, 186, 0.5)" },
200- {"rgb plain" , FormatRGB , true , "235, 188, 186, 0.5" },
202+ {"rgb" , color . FormatRGB , false , "rgba(235, 188, 186, 0.5)" },
203+ {"rgb plain" , color . FormatRGB , true , "235, 188, 186, 0.5" },
201204
202- {"rgb-css" , FormatRGBCSS , false , "rgb(235 188 186 / 0.5)" },
203- {"rgb-css plain" , FormatRGBCSS , true , "235 188 186 / 0.5" },
205+ {"rgb-css" , color . FormatRGBCSS , false , "rgb(235 188 186 / 0.5)" },
206+ {"rgb-css plain" , color . FormatRGBCSS , true , "235 188 186 / 0.5" },
204207
205- {"rgb-array" , FormatRGBArray , false , "[235, 188, 186, 0.5]" },
206- {"rgb-array plain" , FormatRGBArray , true , "235, 188, 186, 0.5" },
208+ {"rgb-array" , color . FormatRGBArray , false , "[235, 188, 186, 0.5]" },
209+ {"rgb-array plain" , color . FormatRGBArray , true , "235, 188, 186, 0.5" },
207210
208- {"ansi" , FormatAnsi , false , "235;188;186;0.5" },
211+ {"ansi" , color . FormatAnsi , false , "235;188;186;0.5" },
209212 }
210213
211214 for _ , tt := range tests {
212215 t .Run (tt .name , func (t * testing.T ) {
213- got := formatColor ( color , tt .format , tt .plain , true , true )
216+ got := color . FormatColor ( c , tt .format , tt .plain , true , true )
214217 if got != tt .want {
215218 t .Errorf ("formatColor() = %v, want %v" , got , tt .want )
216219 }
0 commit comments